По просьбам трудящихся, кусок кода для CyberLib.h
PHP код:
#if defined(__STM32F1XX__)
//+++++++++Token-Pasting++++++++++++++++
#define _digitalRead(x) _D_READ(x)
#define _D_READ(x) dREAD_D##x
#define _digitalWrite(x,hl) _D_WRITE(x,hl)
#define _D_WRITE(x,hl) dWRITE_D##x##_##hl
//---------Token-Parsing----------------
// Fast bit read
#define dREAD_D32 gpio_read_bit(GPIOB,8)>>8 //(GPIOB->regs->IDR&(1U<<8)>>8)
#define dREAD_D31 gpio_read_bit(GPIOB,12)>>12
#define dREAD_D30 gpio_read_bit(GPIOB,13)>>13
#define dREAD_D29 gpio_read_bit(GPIOB,14)>>14
#define dREAD_D28 gpio_read_bit(GPIOB,15)>>15
#define dREAD_D27 gpio_read_bit(GPIOA,8)>>8
#define dREAD_D26 gpio_read_bit(GPIOA,9)>>9
#define dREAD_D25 gpio_read_bit(GPIOA,10)>>10
#define dREAD_D24 gpio_read_bit(GPIOA,11)>>11
#define dREAD_D23 gpio_read_bit(GPIOA,12)>>12
#define dREAD_D22 gpio_read_bit(GPIOA,13)>>13
#define dREAD_D21 gpio_read_bit(GPIOA,14)>>14
#define dREAD_D20 gpio_read_bit(GPIOA,15)>>15
#define dREAD_D19 gpio_read_bit(GPIOB,03)>>03
#define dREAD_D18 gpio_read_bit(GPIOB,04)>>04
#define dREAD_D17 gpio_read_bit(GPIOB,05)>>05
#define dREAD_D16 gpio_read_bit(GPIOB,06)>>06
#define dREAD_D15 gpio_read_bit(GPIOB,07)>>07
#define dREAD_D14 gpio_read_bit(GPIOC,13)>>13
#define dREAD_D13 gpio_read_bit(GPIOC,14)>>14
#define dREAD_D12 gpio_read_bit(GPIOC,15)>>15
#define dREAD_D11 gpio_read_bit(GPIOA,00)>>00
#define dREAD_D10 gpio_read_bit(GPIOA,01)>>01
#define dREAD_D9 gpio_read_bit(GPIOA,02)>>02
#define dREAD_D8 gpio_read_bit(GPIOA,03)>>03
#define dREAD_D7 gpio_read_bit(GPIOA,04)>>04
#define dREAD_D6 gpio_read_bit(GPIOA,05)>>05
#define dREAD_D5 gpio_read_bit(GPIOA,06)>>06
#define dREAD_D4 gpio_read_bit(GPIOA,07)>>07
#define dREAD_D3 gpio_read_bit(GPIOB,00)>>00
#define dREAD_D2 gpio_read_bit(GPIOB,02)>>02
#define dREAD_D1 gpio_read_bit(GPIOB,10)>>10
#define dREAD_D0 gpio_read_bit(GPIOB,11)>>11
// Fast bit write
#define dWRITE_D33_1 GPIOB->regs->BSRR = 0x0002
#define dWRITE_D33_0 GPIOB->regs->BRR = 0x0002
#define dWRITE_D32_1 GPIOB->regs->BSRR = 0x0100
#define dWRITE_D32_0 GPIOB->regs->BRR = 0x0100
#define dWRITE_D31_1 GPIOB->regs->BSRR = 0x1000
#define dWRITE_D31_0 GPIOB->regs->BRR = 0x1000
#define dWRITE_D30_1 GPIOB->regs->BSRR = 0x2000
#define dWRITE_D30_0 GPIOB->regs->BRR = 0x2000
#define dWRITE_D29_1 GPIOB->regs->BSRR = 0x4000
#define dWRITE_D29_0 GPIOB->regs->BRR = 0x4000
#define dWRITE_D28_1 GPIOB->regs->BSRR = 0x8000
#define dWRITE_D28_0 GPIOB->regs->BRR = 0x8000
#define dWRITE_D27_1 GPIOA->regs->BSRR = 0x0100
#define dWRITE_D27_0 GPIOA->regs->BRR = 0x0100
#define dWRITE_D26_1 GPIOA->regs->BSRR = 0x0200
#define dWRITE_D26_0 GPIOA->regs->BRR = 0x0200
#define dWRITE_D25_1 GPIOA->regs->BSRR = 0x0400
#define dWRITE_D25_0 GPIOA->regs->BRR = 0x0400
#define dWRITE_D24_1 GPIOA->regs->BSRR = 0x0800
#define dWRITE_D24_0 GPIOA->regs->BRR = 0x0800
#define dWRITE_D23_1 GPIOA->regs->BSRR = 0x1000
#define dWRITE_D23_0 GPIOA->regs->BRR = 0x1000
#define dWRITE_D22_1 GPIOA->regs->BSRR = 0x2000
#define dWRITE_D22_0 GPIOA->regs->BRR = 0x2000
#define dWRITE_D21_1 GPIOA->regs->BSRR = 0x4000
#define dWRITE_D21_0 GPIOA->regs->BRR = 0x4000
#define dWRITE_D20_1 GPIOA->regs->BSRR = 0x8000
#define dWRITE_D20_0 GPIOA->regs->BRR = 0x8000
#define dWRITE_D19_1 GPIOB->regs->BSRR = 0x0008
#define dWRITE_D19_0 GPIOB->regs->BRR = 0x0008
#define dWRITE_D18_1 GPIOB->regs->BSRR = 0x0010
#define dWRITE_D18_0 GPIOB->regs->BRR = 0x0010
#define dWRITE_D17_1 GPIOB->regs->BSRR = 0x0020
#define dWRITE_D17_0 GPIOB->regs->BRR = 0x0020
#define dWRITE_D16_1 GPIOB->regs->BSRR = 0x0040
#define dWRITE_D16_0 GPIOB->regs->BRR = 0x0040
#define dWRITE_D15_1 GPIOB->regs->BSRR = 0x0080
#define dWRITE_D15_0 GPIOB->regs->BRR = 0x0080
#define dWRITE_D14_1 GPIOC->regs->BSRR = 0x2000
#define dWRITE_D14_0 GPIOC->regs->BRR = 0x2000
#define dWRITE_D13_1 GPIOC->regs->BSRR = 0x4000
#define dWRITE_D13_0 GPIOC->regs->BRR = 0x4000
#define dWRITE_D12_1 GPIOC->regs->BSRR = 0x8000
#define dWRITE_D12_0 GPIOC->regs->BRR = 0x8000
#define dWRITE_D11_1 GPIOA->regs->BSRR = 0x0001
#define dWRITE_D11_0 GPIOA->regs->BRR = 0x0001
#define dWRITE_D10_1 GPIOA->regs->BSRR = 0x0002
#define dWRITE_D10_0 GPIOA->regs->BRR = 0x0002
#define dWRITE_D9_1 GPIOA->regs->BSRR = 0x0004
#define dWRITE_D9_0 GPIOA->regs->BRR = 0x0004
#define dWRITE_D8_1 GPIOA->regs->BSRR = 0x0008
#define dWRITE_D8_0 GPIOA->regs->BRR = 0x0008
#define dWRITE_D7_1 GPIOA->regs->BSRR = 0x0010
#define dWRITE_D7_0 GPIOA->regs->BRR = 0x0010
#define dWRITE_D6_1 GPIOA->regs->BSRR = 0x0020
#define dWRITE_D6_0 GPIOA->regs->BRR = 0x0020
#define dWRITE_D5_1 GPIOA->regs->BSRR = 0x0040
#define dWRITE_D5_0 GPIOA->regs->BRR = 0x0040
#define dWRITE_D4_1 GPIOA->regs->BSRR = 0x0080
#define dWRITE_D4_0 GPIOA->regs->BRR = 0x0080
#define dWRITE_D3_1 GPIOB->regs->BSRR = 0x0001
#define dWRITE_D3_0 GPIOB->regs->BRR = 0x0001
#define dWRITE_D2_1 GPIOB->regs->BSRR = 0x0004
#define dWRITE_D2_0 GPIOB->regs->BRR = 0x0004
#define dWRITE_D1_1 GPIOB->regs->BSRR = 0x0400
#define dWRITE_D1_0 GPIOB->regs->BRR = 0x0400
#define dWRITE_D0_1 GPIOB->regs->BSRR = 0x0800
#define dWRITE_D0_0 GPIOB->regs->BRR = 0x0800
#endif// defined(__STM32F1XX__)
Это код для проверки
PHP код:
void loop() {
static uint32 startT;
uint32 i,j,k;
uint32 dur;
j=0; startT = micros();
for (k=0; k<CYCLES; k++){
i=0;
do{
_digitalWrite(CLK_PIN,1);
i++;
j<<=1;
j += _digitalRead(DATA_PIN);
_digitalWrite(CLK_PIN,0);
} while (i<32);//32-bit read
}
dur = micros()-startT;
// delay(100);
Serial.print("F:");Serial.print(uint64(k*i)*1000/dur);Serial.print("kHz / ");
Serial.print(72*dur/(k*i));Serial.print(" cycles / ");
Serial.print("dur: "); Serial.print(dur);Serial.print(" mcs / ");
Serial.print("j="); Serial.print(j,16);
Serial.print(" / i*k="); Serial.println(i*k);
// delay(100);
}
В итоге может дрыгать ногами со скоростью 8.000+ кГц
Со считыванием данных с кнопки 4,2МГц.
Проверялось на Arduino IDE 1.5.8 +
Arduino_STM32