diff options
Diffstat (limited to 'platforms')
29 files changed, 449 insertions, 342 deletions
| diff --git a/platforms/avr/drivers/ws2812_bitbang.c b/platforms/avr/drivers/ws2812_bitbang.c index aad10d86b0..116053591f 100644 --- a/platforms/avr/drivers/ws2812_bitbang.c +++ b/platforms/avr/drivers/ws2812_bitbang.c @@ -37,13 +37,13 @@  static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi); -void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds) { +void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds) {      DDRx_ADDRESS(WS2812_DI_PIN) |= pinmask(WS2812_DI_PIN);      uint8_t masklo = ~(pinmask(WS2812_DI_PIN)) & PORTx_ADDRESS(WS2812_DI_PIN);      uint8_t maskhi = pinmask(WS2812_DI_PIN) | PORTx_ADDRESS(WS2812_DI_PIN); -    ws2812_sendarray_mask((uint8_t *)ledarray, number_of_leds * sizeof(LED_TYPE), masklo, maskhi); +    ws2812_sendarray_mask((uint8_t *)ledarray, number_of_leds * sizeof(rgb_led_t), masklo, maskhi);      _delay_us(WS2812_TRST_US);  } diff --git a/platforms/avr/drivers/ws2812_i2c.c b/platforms/avr/drivers/ws2812_i2c.c index f4a2fbe0b3..f52a037b8e 100644 --- a/platforms/avr/drivers/ws2812_i2c.c +++ b/platforms/avr/drivers/ws2812_i2c.c @@ -18,12 +18,12 @@ void ws2812_init(void) {  }  // Setleds for standard RGB -void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { +void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {      static bool s_init = false;      if (!s_init) {          ws2812_init();          s_init = true;      } -    i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_I2C_TIMEOUT); +    i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(rgb_led_t) * leds, WS2812_I2C_TIMEOUT);  } diff --git a/platforms/avr/flash.mk b/platforms/avr/flash.mk index 9c2ab72410..51731f0aa8 100644 --- a/platforms/avr/flash.mk +++ b/platforms/avr/flash.mk @@ -130,10 +130,10 @@ avrdude-split-right: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware  	$(call EXEC_AVRDUDE,eeprom-righthand.eep)  define EXEC_USBASP -	if $(AVRDUDE_PROGRAMMER) -p $(AVRDUDE_MCU) -c usbasp 2>&1 | grep -q "could not find USB device with"; then \ +	if $(AVRDUDE_PROGRAMMER) -p $(AVRDUDE_MCU) -c usbasp 2>&1 | grep -q "\(could not\|cannot\) find USB device with"; then \  		printf "$(MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY)" ;\  		sleep $(BOOTLOADER_RETRY_TIME) ;\ -		until $(AVRDUDE_PROGRAMMER) -p $(AVRDUDE_MCU) -c usbasp 2>&1 | (! grep -q "could not find USB device with"); do\ +		until $(AVRDUDE_PROGRAMMER) -p $(AVRDUDE_MCU) -c usbasp 2>&1 | (! grep -q "\(could not\|cannot\) find USB device with"); do\  			printf "." ;\  			sleep $(BOOTLOADER_RETRY_TIME) ;\  		done ;\ diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk index 09028d80af..aef449cadf 100644 --- a/platforms/avr/platform.mk +++ b/platforms/avr/platform.mk @@ -109,6 +109,29 @@ DEBUG_HOST = localhost  #============================================================================ +SIZE_MARGIN = 1024 + +check-size: +	$(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) platforms/avr/bootloader_size.c 2> /dev/null | $(SED) -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) +	$(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi)) +	$(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE))) +	$(eval OVER_SIZE=$(shell expr $(CURRENT_SIZE) - $(MAX_SIZE))) +	$(eval PERCENT_SIZE=$(shell expr $(CURRENT_SIZE) \* 100 / $(MAX_SIZE))) +	if [ $(MAX_SIZE) -gt 0 ] && [ $(CURRENT_SIZE) -gt 0 ]; then \ +		$(SILENT) || printf "$(MSG_CHECK_FILESIZE)" | $(AWK_CMD); \ +		if [ $(CURRENT_SIZE) -gt $(MAX_SIZE) ]; then \ +			$(REMOVE) $(TARGET).$(FIRMWARE_FORMAT); \ +			$(REMOVE) $(BUILD_DIR)/$(TARGET).{hex,bin,uf2}; \ +		    printf "\n * $(MSG_FILE_TOO_BIG)"; $(PRINT_ERROR_PLAIN); \ +		else \ +		    if [ $(FREE_SIZE) -lt $(SIZE_MARGIN) ]; then \ +			$(PRINT_WARNING_PLAIN); printf " * $(MSG_FILE_NEAR_LIMIT)"; \ +		    else \ +			$(PRINT_OK); $(SILENT) || printf " * $(MSG_FILE_JUST_RIGHT)"; \ +		    fi ; \ +		fi ; \ +	fi +  # Convert hex to bin.  bin: $(BUILD_DIR)/$(TARGET).hex  ifeq ($(BOOTLOADER),lufa-ms) diff --git a/platforms/chibios/_pin_defs.h b/platforms/chibios/_pin_defs.h index 414c9e3d11..e144ef9b0a 100644 --- a/platforms/chibios/_pin_defs.h +++ b/platforms/chibios/_pin_defs.h @@ -24,271 +24,272 @@  /* Include the vendor specific pin defs */  #if __has_include_next("_pin_defs.h")  #    include_next "_pin_defs.h" -#endif +#else +#    define A0 PAL_LINE(GPIOA, 0) +#    define A1 PAL_LINE(GPIOA, 1) +#    define A2 PAL_LINE(GPIOA, 2) +#    define A3 PAL_LINE(GPIOA, 3) +#    define A4 PAL_LINE(GPIOA, 4) +#    define A5 PAL_LINE(GPIOA, 5) +#    define A6 PAL_LINE(GPIOA, 6) +#    define A7 PAL_LINE(GPIOA, 7) +#    define A8 PAL_LINE(GPIOA, 8) +#    define A9 PAL_LINE(GPIOA, 9) +#    define A10 PAL_LINE(GPIOA, 10) +#    define A11 PAL_LINE(GPIOA, 11) +#    define A12 PAL_LINE(GPIOA, 12) +#    define A13 PAL_LINE(GPIOA, 13) +#    define A14 PAL_LINE(GPIOA, 14) +#    define A15 PAL_LINE(GPIOA, 15) +#    define A16 PAL_LINE(GPIOA, 16) +#    define A17 PAL_LINE(GPIOA, 17) +#    define A18 PAL_LINE(GPIOA, 18) +#    define A19 PAL_LINE(GPIOA, 19) +#    define A20 PAL_LINE(GPIOA, 20) +#    define A21 PAL_LINE(GPIOA, 21) +#    define A22 PAL_LINE(GPIOA, 22) +#    define A23 PAL_LINE(GPIOA, 23) +#    define A24 PAL_LINE(GPIOA, 24) +#    define A25 PAL_LINE(GPIOA, 25) +#    define A26 PAL_LINE(GPIOA, 26) +#    define A27 PAL_LINE(GPIOA, 27) +#    define A28 PAL_LINE(GPIOA, 28) +#    define A29 PAL_LINE(GPIOA, 29) +#    define A30 PAL_LINE(GPIOA, 30) +#    define A31 PAL_LINE(GPIOA, 31) +#    define A32 PAL_LINE(GPIOA, 32) +#    define B0 PAL_LINE(GPIOB, 0) +#    define B1 PAL_LINE(GPIOB, 1) +#    define B2 PAL_LINE(GPIOB, 2) +#    define B3 PAL_LINE(GPIOB, 3) +#    define B4 PAL_LINE(GPIOB, 4) +#    define B5 PAL_LINE(GPIOB, 5) +#    define B6 PAL_LINE(GPIOB, 6) +#    define B7 PAL_LINE(GPIOB, 7) +#    define B8 PAL_LINE(GPIOB, 8) +#    define B9 PAL_LINE(GPIOB, 9) +#    define B10 PAL_LINE(GPIOB, 10) +#    define B11 PAL_LINE(GPIOB, 11) +#    define B12 PAL_LINE(GPIOB, 12) +#    define B13 PAL_LINE(GPIOB, 13) +#    define B14 PAL_LINE(GPIOB, 14) +#    define B15 PAL_LINE(GPIOB, 15) +#    define B16 PAL_LINE(GPIOB, 16) +#    define B17 PAL_LINE(GPIOB, 17) +#    define B18 PAL_LINE(GPIOB, 18) +#    define B19 PAL_LINE(GPIOB, 19) +#    define B20 PAL_LINE(GPIOB, 20) +#    define B21 PAL_LINE(GPIOB, 21) +#    define B22 PAL_LINE(GPIOB, 22) +#    define B23 PAL_LINE(GPIOB, 23) +#    define B24 PAL_LINE(GPIOB, 24) +#    define B25 PAL_LINE(GPIOB, 25) +#    define B26 PAL_LINE(GPIOB, 26) +#    define B27 PAL_LINE(GPIOB, 27) +#    define B28 PAL_LINE(GPIOB, 28) +#    define B29 PAL_LINE(GPIOB, 29) +#    define B30 PAL_LINE(GPIOB, 30) +#    define B31 PAL_LINE(GPIOB, 31) +#    define B32 PAL_LINE(GPIOB, 32) +#    define C0 PAL_LINE(GPIOC, 0) +#    define C1 PAL_LINE(GPIOC, 1) +#    define C2 PAL_LINE(GPIOC, 2) +#    define C3 PAL_LINE(GPIOC, 3) +#    define C4 PAL_LINE(GPIOC, 4) +#    define C5 PAL_LINE(GPIOC, 5) +#    define C6 PAL_LINE(GPIOC, 6) +#    define C7 PAL_LINE(GPIOC, 7) +#    define C8 PAL_LINE(GPIOC, 8) +#    define C9 PAL_LINE(GPIOC, 9) +#    define C10 PAL_LINE(GPIOC, 10) +#    define C11 PAL_LINE(GPIOC, 11) +#    define C12 PAL_LINE(GPIOC, 12) +#    define C13 PAL_LINE(GPIOC, 13) +#    define C14 PAL_LINE(GPIOC, 14) +#    define C15 PAL_LINE(GPIOC, 15) +#    define C16 PAL_LINE(GPIOC, 16) +#    define C17 PAL_LINE(GPIOC, 17) +#    define C18 PAL_LINE(GPIOC, 18) +#    define C19 PAL_LINE(GPIOC, 19) +#    define C20 PAL_LINE(GPIOC, 20) +#    define C21 PAL_LINE(GPIOC, 21) +#    define C22 PAL_LINE(GPIOC, 22) +#    define C23 PAL_LINE(GPIOC, 23) +#    define C24 PAL_LINE(GPIOC, 24) +#    define C25 PAL_LINE(GPIOC, 25) +#    define C26 PAL_LINE(GPIOC, 26) +#    define C27 PAL_LINE(GPIOC, 27) +#    define C28 PAL_LINE(GPIOC, 28) +#    define C29 PAL_LINE(GPIOC, 29) +#    define C30 PAL_LINE(GPIOC, 30) +#    define C31 PAL_LINE(GPIOC, 31) +#    define C32 PAL_LINE(GPIOC, 32) +#    define D0 PAL_LINE(GPIOD, 0) +#    define D1 PAL_LINE(GPIOD, 1) +#    define D2 PAL_LINE(GPIOD, 2) +#    define D3 PAL_LINE(GPIOD, 3) +#    define D4 PAL_LINE(GPIOD, 4) +#    define D5 PAL_LINE(GPIOD, 5) +#    define D6 PAL_LINE(GPIOD, 6) +#    define D7 PAL_LINE(GPIOD, 7) +#    define D8 PAL_LINE(GPIOD, 8) +#    define D9 PAL_LINE(GPIOD, 9) +#    define D10 PAL_LINE(GPIOD, 10) +#    define D11 PAL_LINE(GPIOD, 11) +#    define D12 PAL_LINE(GPIOD, 12) +#    define D13 PAL_LINE(GPIOD, 13) +#    define D14 PAL_LINE(GPIOD, 14) +#    define D15 PAL_LINE(GPIOD, 15) +#    define D16 PAL_LINE(GPIOD, 16) +#    define D17 PAL_LINE(GPIOD, 17) +#    define D18 PAL_LINE(GPIOD, 18) +#    define D19 PAL_LINE(GPIOD, 19) +#    define D20 PAL_LINE(GPIOD, 20) +#    define D21 PAL_LINE(GPIOD, 21) +#    define D22 PAL_LINE(GPIOD, 22) +#    define D23 PAL_LINE(GPIOD, 23) +#    define D24 PAL_LINE(GPIOD, 24) +#    define D25 PAL_LINE(GPIOD, 25) +#    define D26 PAL_LINE(GPIOD, 26) +#    define D27 PAL_LINE(GPIOD, 27) +#    define D28 PAL_LINE(GPIOD, 28) +#    define D29 PAL_LINE(GPIOD, 29) +#    define D30 PAL_LINE(GPIOD, 30) +#    define D31 PAL_LINE(GPIOD, 31) +#    define D32 PAL_LINE(GPIOD, 32) +#    define E0 PAL_LINE(GPIOE, 0) +#    define E1 PAL_LINE(GPIOE, 1) +#    define E2 PAL_LINE(GPIOE, 2) +#    define E3 PAL_LINE(GPIOE, 3) +#    define E4 PAL_LINE(GPIOE, 4) +#    define E5 PAL_LINE(GPIOE, 5) +#    define E6 PAL_LINE(GPIOE, 6) +#    define E7 PAL_LINE(GPIOE, 7) +#    define E8 PAL_LINE(GPIOE, 8) +#    define E9 PAL_LINE(GPIOE, 9) +#    define E10 PAL_LINE(GPIOE, 10) +#    define E11 PAL_LINE(GPIOE, 11) +#    define E12 PAL_LINE(GPIOE, 12) +#    define E13 PAL_LINE(GPIOE, 13) +#    define E14 PAL_LINE(GPIOE, 14) +#    define E15 PAL_LINE(GPIOE, 15) +#    define E16 PAL_LINE(GPIOE, 16) +#    define E17 PAL_LINE(GPIOE, 17) +#    define E18 PAL_LINE(GPIOE, 18) +#    define E19 PAL_LINE(GPIOE, 19) +#    define E20 PAL_LINE(GPIOE, 20) +#    define E21 PAL_LINE(GPIOE, 21) +#    define E22 PAL_LINE(GPIOE, 22) +#    define E23 PAL_LINE(GPIOE, 23) +#    define E24 PAL_LINE(GPIOE, 24) +#    define E25 PAL_LINE(GPIOE, 25) +#    define E26 PAL_LINE(GPIOE, 26) +#    define E27 PAL_LINE(GPIOE, 27) +#    define E28 PAL_LINE(GPIOE, 28) +#    define E29 PAL_LINE(GPIOE, 29) +#    define E30 PAL_LINE(GPIOE, 30) +#    define E31 PAL_LINE(GPIOE, 31) +#    define E32 PAL_LINE(GPIOE, 32) +#    define F0 PAL_LINE(GPIOF, 0) +#    define F1 PAL_LINE(GPIOF, 1) +#    define F2 PAL_LINE(GPIOF, 2) +#    define F3 PAL_LINE(GPIOF, 3) +#    define F4 PAL_LINE(GPIOF, 4) +#    define F5 PAL_LINE(GPIOF, 5) +#    define F6 PAL_LINE(GPIOF, 6) +#    define F7 PAL_LINE(GPIOF, 7) +#    define F8 PAL_LINE(GPIOF, 8) +#    define F9 PAL_LINE(GPIOF, 9) +#    define F10 PAL_LINE(GPIOF, 10) +#    define F11 PAL_LINE(GPIOF, 11) +#    define F12 PAL_LINE(GPIOF, 12) +#    define F13 PAL_LINE(GPIOF, 13) +#    define F14 PAL_LINE(GPIOF, 14) +#    define F15 PAL_LINE(GPIOF, 15) +#    define G0 PAL_LINE(GPIOG, 0) +#    define G1 PAL_LINE(GPIOG, 1) +#    define G2 PAL_LINE(GPIOG, 2) +#    define G3 PAL_LINE(GPIOG, 3) +#    define G4 PAL_LINE(GPIOG, 4) +#    define G5 PAL_LINE(GPIOG, 5) +#    define G6 PAL_LINE(GPIOG, 6) +#    define G7 PAL_LINE(GPIOG, 7) +#    define G8 PAL_LINE(GPIOG, 8) +#    define G9 PAL_LINE(GPIOG, 9) +#    define G10 PAL_LINE(GPIOG, 10) +#    define G11 PAL_LINE(GPIOG, 11) +#    define G12 PAL_LINE(GPIOG, 12) +#    define G13 PAL_LINE(GPIOG, 13) +#    define G14 PAL_LINE(GPIOG, 14) +#    define G15 PAL_LINE(GPIOG, 15) +#    define H0 PAL_LINE(GPIOH, 0) +#    define H1 PAL_LINE(GPIOH, 1) +#    define H2 PAL_LINE(GPIOH, 2) +#    define H3 PAL_LINE(GPIOH, 3) +#    define H4 PAL_LINE(GPIOH, 4) +#    define H5 PAL_LINE(GPIOH, 5) +#    define H6 PAL_LINE(GPIOH, 6) +#    define H7 PAL_LINE(GPIOH, 7) +#    define H8 PAL_LINE(GPIOH, 8) +#    define H9 PAL_LINE(GPIOH, 9) +#    define H10 PAL_LINE(GPIOH, 10) +#    define H11 PAL_LINE(GPIOH, 11) +#    define H12 PAL_LINE(GPIOH, 12) +#    define H13 PAL_LINE(GPIOH, 13) +#    define H14 PAL_LINE(GPIOH, 14) +#    define H15 PAL_LINE(GPIOH, 15) +#    define I0 PAL_LINE(GPIOI, 0) +#    define I1 PAL_LINE(GPIOI, 1) +#    define I2 PAL_LINE(GPIOI, 2) +#    define I3 PAL_LINE(GPIOI, 3) +#    define I4 PAL_LINE(GPIOI, 4) +#    define I5 PAL_LINE(GPIOI, 5) +#    define I6 PAL_LINE(GPIOI, 6) +#    define I7 PAL_LINE(GPIOI, 7) +#    define I8 PAL_LINE(GPIOI, 8) +#    define I9 PAL_LINE(GPIOI, 9) +#    define I10 PAL_LINE(GPIOI, 10) +#    define I11 PAL_LINE(GPIOI, 11) +#    define I12 PAL_LINE(GPIOI, 12) +#    define I13 PAL_LINE(GPIOI, 13) +#    define I14 PAL_LINE(GPIOI, 14) +#    define I15 PAL_LINE(GPIOI, 15) +#    define J0 PAL_LINE(GPIOJ, 0) +#    define J1 PAL_LINE(GPIOJ, 1) +#    define J2 PAL_LINE(GPIOJ, 2) +#    define J3 PAL_LINE(GPIOJ, 3) +#    define J4 PAL_LINE(GPIOJ, 4) +#    define J5 PAL_LINE(GPIOJ, 5) +#    define J6 PAL_LINE(GPIOJ, 6) +#    define J7 PAL_LINE(GPIOJ, 7) +#    define J8 PAL_LINE(GPIOJ, 8) +#    define J9 PAL_LINE(GPIOJ, 9) +#    define J10 PAL_LINE(GPIOJ, 10) +#    define J11 PAL_LINE(GPIOJ, 11) +#    define J12 PAL_LINE(GPIOJ, 12) +#    define J13 PAL_LINE(GPIOJ, 13) +#    define J14 PAL_LINE(GPIOJ, 14) +#    define J15 PAL_LINE(GPIOJ, 15) -#define A0 PAL_LINE(GPIOA, 0) -#define A1 PAL_LINE(GPIOA, 1) -#define A2 PAL_LINE(GPIOA, 2) -#define A3 PAL_LINE(GPIOA, 3) -#define A4 PAL_LINE(GPIOA, 4) -#define A5 PAL_LINE(GPIOA, 5) -#define A6 PAL_LINE(GPIOA, 6) -#define A7 PAL_LINE(GPIOA, 7) -#define A8 PAL_LINE(GPIOA, 8) -#define A9 PAL_LINE(GPIOA, 9) -#define A10 PAL_LINE(GPIOA, 10) -#define A11 PAL_LINE(GPIOA, 11) -#define A12 PAL_LINE(GPIOA, 12) -#define A13 PAL_LINE(GPIOA, 13) -#define A14 PAL_LINE(GPIOA, 14) -#define A15 PAL_LINE(GPIOA, 15) -#define A16 PAL_LINE(GPIOA, 16) -#define A17 PAL_LINE(GPIOA, 17) -#define A18 PAL_LINE(GPIOA, 18) -#define A19 PAL_LINE(GPIOA, 19) -#define A20 PAL_LINE(GPIOA, 20) -#define A21 PAL_LINE(GPIOA, 21) -#define A22 PAL_LINE(GPIOA, 22) -#define A23 PAL_LINE(GPIOA, 23) -#define A24 PAL_LINE(GPIOA, 24) -#define A25 PAL_LINE(GPIOA, 25) -#define A26 PAL_LINE(GPIOA, 26) -#define A27 PAL_LINE(GPIOA, 27) -#define A28 PAL_LINE(GPIOA, 28) -#define A29 PAL_LINE(GPIOA, 29) -#define A30 PAL_LINE(GPIOA, 30) -#define A31 PAL_LINE(GPIOA, 31) -#define A32 PAL_LINE(GPIOA, 32) -#define B0 PAL_LINE(GPIOB, 0) -#define B1 PAL_LINE(GPIOB, 1) -#define B2 PAL_LINE(GPIOB, 2) -#define B3 PAL_LINE(GPIOB, 3) -#define B4 PAL_LINE(GPIOB, 4) -#define B5 PAL_LINE(GPIOB, 5) -#define B6 PAL_LINE(GPIOB, 6) -#define B7 PAL_LINE(GPIOB, 7) -#define B8 PAL_LINE(GPIOB, 8) -#define B9 PAL_LINE(GPIOB, 9) -#define B10 PAL_LINE(GPIOB, 10) -#define B11 PAL_LINE(GPIOB, 11) -#define B12 PAL_LINE(GPIOB, 12) -#define B13 PAL_LINE(GPIOB, 13) -#define B14 PAL_LINE(GPIOB, 14) -#define B15 PAL_LINE(GPIOB, 15) -#define B16 PAL_LINE(GPIOB, 16) -#define B17 PAL_LINE(GPIOB, 17) -#define B18 PAL_LINE(GPIOB, 18) -#define B19 PAL_LINE(GPIOB, 19) -#define B20 PAL_LINE(GPIOB, 20) -#define B21 PAL_LINE(GPIOB, 21) -#define B22 PAL_LINE(GPIOB, 22) -#define B23 PAL_LINE(GPIOB, 23) -#define B24 PAL_LINE(GPIOB, 24) -#define B25 PAL_LINE(GPIOB, 25) -#define B26 PAL_LINE(GPIOB, 26) -#define B27 PAL_LINE(GPIOB, 27) -#define B28 PAL_LINE(GPIOB, 28) -#define B29 PAL_LINE(GPIOB, 29) -#define B30 PAL_LINE(GPIOB, 30) -#define B31 PAL_LINE(GPIOB, 31) -#define B32 PAL_LINE(GPIOB, 32) -#define C0 PAL_LINE(GPIOC, 0) -#define C1 PAL_LINE(GPIOC, 1) -#define C2 PAL_LINE(GPIOC, 2) -#define C3 PAL_LINE(GPIOC, 3) -#define C4 PAL_LINE(GPIOC, 4) -#define C5 PAL_LINE(GPIOC, 5) -#define C6 PAL_LINE(GPIOC, 6) -#define C7 PAL_LINE(GPIOC, 7) -#define C8 PAL_LINE(GPIOC, 8) -#define C9 PAL_LINE(GPIOC, 9) -#define C10 PAL_LINE(GPIOC, 10) -#define C11 PAL_LINE(GPIOC, 11) -#define C12 PAL_LINE(GPIOC, 12) -#define C13 PAL_LINE(GPIOC, 13) -#define C14 PAL_LINE(GPIOC, 14) -#define C15 PAL_LINE(GPIOC, 15) -#define C16 PAL_LINE(GPIOC, 16) -#define C17 PAL_LINE(GPIOC, 17) -#define C18 PAL_LINE(GPIOC, 18) -#define C19 PAL_LINE(GPIOC, 19) -#define C20 PAL_LINE(GPIOC, 20) -#define C21 PAL_LINE(GPIOC, 21) -#define C22 PAL_LINE(GPIOC, 22) -#define C23 PAL_LINE(GPIOC, 23) -#define C24 PAL_LINE(GPIOC, 24) -#define C25 PAL_LINE(GPIOC, 25) -#define C26 PAL_LINE(GPIOC, 26) -#define C27 PAL_LINE(GPIOC, 27) -#define C28 PAL_LINE(GPIOC, 28) -#define C29 PAL_LINE(GPIOC, 29) -#define C30 PAL_LINE(GPIOC, 30) -#define C31 PAL_LINE(GPIOC, 31) -#define C32 PAL_LINE(GPIOC, 32) -#define D0 PAL_LINE(GPIOD, 0) -#define D1 PAL_LINE(GPIOD, 1) -#define D2 PAL_LINE(GPIOD, 2) -#define D3 PAL_LINE(GPIOD, 3) -#define D4 PAL_LINE(GPIOD, 4) -#define D5 PAL_LINE(GPIOD, 5) -#define D6 PAL_LINE(GPIOD, 6) -#define D7 PAL_LINE(GPIOD, 7) -#define D8 PAL_LINE(GPIOD, 8) -#define D9 PAL_LINE(GPIOD, 9) -#define D10 PAL_LINE(GPIOD, 10) -#define D11 PAL_LINE(GPIOD, 11) -#define D12 PAL_LINE(GPIOD, 12) -#define D13 PAL_LINE(GPIOD, 13) -#define D14 PAL_LINE(GPIOD, 14) -#define D15 PAL_LINE(GPIOD, 15) -#define D16 PAL_LINE(GPIOD, 16) -#define D17 PAL_LINE(GPIOD, 17) -#define D18 PAL_LINE(GPIOD, 18) -#define D19 PAL_LINE(GPIOD, 19) -#define D20 PAL_LINE(GPIOD, 20) -#define D21 PAL_LINE(GPIOD, 21) -#define D22 PAL_LINE(GPIOD, 22) -#define D23 PAL_LINE(GPIOD, 23) -#define D24 PAL_LINE(GPIOD, 24) -#define D25 PAL_LINE(GPIOD, 25) -#define D26 PAL_LINE(GPIOD, 26) -#define D27 PAL_LINE(GPIOD, 27) -#define D28 PAL_LINE(GPIOD, 28) -#define D29 PAL_LINE(GPIOD, 29) -#define D30 PAL_LINE(GPIOD, 30) -#define D31 PAL_LINE(GPIOD, 31) -#define D32 PAL_LINE(GPIOD, 32) -#define E0 PAL_LINE(GPIOE, 0) -#define E1 PAL_LINE(GPIOE, 1) -#define E2 PAL_LINE(GPIOE, 2) -#define E3 PAL_LINE(GPIOE, 3) -#define E4 PAL_LINE(GPIOE, 4) -#define E5 PAL_LINE(GPIOE, 5) -#define E6 PAL_LINE(GPIOE, 6) -#define E7 PAL_LINE(GPIOE, 7) -#define E8 PAL_LINE(GPIOE, 8) -#define E9 PAL_LINE(GPIOE, 9) -#define E10 PAL_LINE(GPIOE, 10) -#define E11 PAL_LINE(GPIOE, 11) -#define E12 PAL_LINE(GPIOE, 12) -#define E13 PAL_LINE(GPIOE, 13) -#define E14 PAL_LINE(GPIOE, 14) -#define E15 PAL_LINE(GPIOE, 15) -#define E16 PAL_LINE(GPIOE, 16) -#define E17 PAL_LINE(GPIOE, 17) -#define E18 PAL_LINE(GPIOE, 18) -#define E19 PAL_LINE(GPIOE, 19) -#define E20 PAL_LINE(GPIOE, 20) -#define E21 PAL_LINE(GPIOE, 21) -#define E22 PAL_LINE(GPIOE, 22) -#define E23 PAL_LINE(GPIOE, 23) -#define E24 PAL_LINE(GPIOE, 24) -#define E25 PAL_LINE(GPIOE, 25) -#define E26 PAL_LINE(GPIOE, 26) -#define E27 PAL_LINE(GPIOE, 27) -#define E28 PAL_LINE(GPIOE, 28) -#define E29 PAL_LINE(GPIOE, 29) -#define E30 PAL_LINE(GPIOE, 30) -#define E31 PAL_LINE(GPIOE, 31) -#define E32 PAL_LINE(GPIOE, 32) -#define F0 PAL_LINE(GPIOF, 0) -#define F1 PAL_LINE(GPIOF, 1) -#define F2 PAL_LINE(GPIOF, 2) -#define F3 PAL_LINE(GPIOF, 3) -#define F4 PAL_LINE(GPIOF, 4) -#define F5 PAL_LINE(GPIOF, 5) -#define F6 PAL_LINE(GPIOF, 6) -#define F7 PAL_LINE(GPIOF, 7) -#define F8 PAL_LINE(GPIOF, 8) -#define F9 PAL_LINE(GPIOF, 9) -#define F10 PAL_LINE(GPIOF, 10) -#define F11 PAL_LINE(GPIOF, 11) -#define F12 PAL_LINE(GPIOF, 12) -#define F13 PAL_LINE(GPIOF, 13) -#define F14 PAL_LINE(GPIOF, 14) -#define F15 PAL_LINE(GPIOF, 15) -#define G0 PAL_LINE(GPIOG, 0) -#define G1 PAL_LINE(GPIOG, 1) -#define G2 PAL_LINE(GPIOG, 2) -#define G3 PAL_LINE(GPIOG, 3) -#define G4 PAL_LINE(GPIOG, 4) -#define G5 PAL_LINE(GPIOG, 5) -#define G6 PAL_LINE(GPIOG, 6) -#define G7 PAL_LINE(GPIOG, 7) -#define G8 PAL_LINE(GPIOG, 8) -#define G9 PAL_LINE(GPIOG, 9) -#define G10 PAL_LINE(GPIOG, 10) -#define G11 PAL_LINE(GPIOG, 11) -#define G12 PAL_LINE(GPIOG, 12) -#define G13 PAL_LINE(GPIOG, 13) -#define G14 PAL_LINE(GPIOG, 14) -#define G15 PAL_LINE(GPIOG, 15) -#define H0 PAL_LINE(GPIOH, 0) -#define H1 PAL_LINE(GPIOH, 1) -#define H2 PAL_LINE(GPIOH, 2) -#define H3 PAL_LINE(GPIOH, 3) -#define H4 PAL_LINE(GPIOH, 4) -#define H5 PAL_LINE(GPIOH, 5) -#define H6 PAL_LINE(GPIOH, 6) -#define H7 PAL_LINE(GPIOH, 7) -#define H8 PAL_LINE(GPIOH, 8) -#define H9 PAL_LINE(GPIOH, 9) -#define H10 PAL_LINE(GPIOH, 10) -#define H11 PAL_LINE(GPIOH, 11) -#define H12 PAL_LINE(GPIOH, 12) -#define H13 PAL_LINE(GPIOH, 13) -#define H14 PAL_LINE(GPIOH, 14) -#define H15 PAL_LINE(GPIOH, 15) -#define I0 PAL_LINE(GPIOI, 0) -#define I1 PAL_LINE(GPIOI, 1) -#define I2 PAL_LINE(GPIOI, 2) -#define I3 PAL_LINE(GPIOI, 3) -#define I4 PAL_LINE(GPIOI, 4) -#define I5 PAL_LINE(GPIOI, 5) -#define I6 PAL_LINE(GPIOI, 6) -#define I7 PAL_LINE(GPIOI, 7) -#define I8 PAL_LINE(GPIOI, 8) -#define I9 PAL_LINE(GPIOI, 9) -#define I10 PAL_LINE(GPIOI, 10) -#define I11 PAL_LINE(GPIOI, 11) -#define I12 PAL_LINE(GPIOI, 12) -#define I13 PAL_LINE(GPIOI, 13) -#define I14 PAL_LINE(GPIOI, 14) -#define I15 PAL_LINE(GPIOI, 15) -#define J0 PAL_LINE(GPIOJ, 0) -#define J1 PAL_LINE(GPIOJ, 1) -#define J2 PAL_LINE(GPIOJ, 2) -#define J3 PAL_LINE(GPIOJ, 3) -#define J4 PAL_LINE(GPIOJ, 4) -#define J5 PAL_LINE(GPIOJ, 5) -#define J6 PAL_LINE(GPIOJ, 6) -#define J7 PAL_LINE(GPIOJ, 7) -#define J8 PAL_LINE(GPIOJ, 8) -#define J9 PAL_LINE(GPIOJ, 9) -#define J10 PAL_LINE(GPIOJ, 10) -#define J11 PAL_LINE(GPIOJ, 11) -#define J12 PAL_LINE(GPIOJ, 12) -#define J13 PAL_LINE(GPIOJ, 13) -#define J14 PAL_LINE(GPIOJ, 14) -#define J15 PAL_LINE(GPIOJ, 15)  // Keyboards can `#define KEYBOARD_REQUIRES_GPIOK` if they need to access GPIO-K pins. These conflict with a whole  // bunch of layout definitions, so it's intentionally left out unless absolutely required -- in that case, the  // keyboard designer should use a different symbol when defining their layout macros. -#ifdef KEYBOARD_REQUIRES_GPIOK -#    define K0 PAL_LINE(GPIOK, 0) -#    define K1 PAL_LINE(GPIOK, 1) -#    define K2 PAL_LINE(GPIOK, 2) -#    define K3 PAL_LINE(GPIOK, 3) -#    define K4 PAL_LINE(GPIOK, 4) -#    define K5 PAL_LINE(GPIOK, 5) -#    define K6 PAL_LINE(GPIOK, 6) -#    define K7 PAL_LINE(GPIOK, 7) -#    define K8 PAL_LINE(GPIOK, 8) -#    define K9 PAL_LINE(GPIOK, 9) -#    define K10 PAL_LINE(GPIOK, 10) -#    define K11 PAL_LINE(GPIOK, 11) -#    define K12 PAL_LINE(GPIOK, 12) -#    define K13 PAL_LINE(GPIOK, 13) -#    define K14 PAL_LINE(GPIOK, 14) -#    define K15 PAL_LINE(GPIOK, 15) +#    ifdef KEYBOARD_REQUIRES_GPIOK +#        define K0 PAL_LINE(GPIOK, 0) +#        define K1 PAL_LINE(GPIOK, 1) +#        define K2 PAL_LINE(GPIOK, 2) +#        define K3 PAL_LINE(GPIOK, 3) +#        define K4 PAL_LINE(GPIOK, 4) +#        define K5 PAL_LINE(GPIOK, 5) +#        define K6 PAL_LINE(GPIOK, 6) +#        define K7 PAL_LINE(GPIOK, 7) +#        define K8 PAL_LINE(GPIOK, 8) +#        define K9 PAL_LINE(GPIOK, 9) +#        define K10 PAL_LINE(GPIOK, 10) +#        define K11 PAL_LINE(GPIOK, 11) +#        define K12 PAL_LINE(GPIOK, 12) +#        define K13 PAL_LINE(GPIOK, 13) +#        define K14 PAL_LINE(GPIOK, 14) +#        define K15 PAL_LINE(GPIOK, 15) +#    endif  #endif diff --git a/platforms/chibios/boards/BONSAI_C4/configs/config.h b/platforms/chibios/boards/BONSAI_C4/configs/config.h index c5dbb25c45..193b028bde 100644 --- a/platforms/chibios/boards/BONSAI_C4/configs/config.h +++ b/platforms/chibios/boards/BONSAI_C4/configs/config.h @@ -24,11 +24,9 @@  // FRAM configuration  #ifndef EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN +#    define EEPROM_SPI_MB85RS64V  #    define EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN PAL_LINE(GPIOA, 0)  #    define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 8 // 96MHz / 8 = 12MHz; max supported by MB85R64 is 20MHz -#    define EXTERNAL_EEPROM_BYTE_COUNT 8192 -#    define EXTERNAL_EEPROM_PAGE_SIZE 64 // does not matter for FRAM, just sets the RAM buffer size in STM32F chip -#    define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 8191  #endif  // External flash configuration @@ -66,7 +64,7 @@  #endif  // WS2812-style LED control on pin A10 -#ifdef WS2812_DRIVER_PWM +#ifdef WS2812_PWM  #    ifndef WS2812_DI_PIN  #        define WS2812_DI_PIN PAL_LINE(GPIOA, 10)  #    endif diff --git a/platforms/chibios/boards/BONSAI_C4/configs/halconf.h b/platforms/chibios/boards/BONSAI_C4/configs/halconf.h index 7887e7c9ba..6bab6fbcff 100644 --- a/platforms/chibios/boards/BONSAI_C4/configs/halconf.h +++ b/platforms/chibios/boards/BONSAI_C4/configs/halconf.h @@ -32,7 +32,7 @@  #    endif  #endif -#ifdef WS2812_DRIVER_PWM +#ifdef WS2812_PWM  #    ifndef HAL_USE_PWM  #        define HAL_USE_PWM TRUE  #    endif diff --git a/platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/mcuconf.h index 8621807cbb..4f39793264 100644 --- a/platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_PROMICRO_RP2040/configs/mcuconf.h @@ -54,6 +54,7 @@  #define RP_IRQ_USB0_PRIORITY                3  #define RP_IRQ_I2C0_PRIORITY                2  #define RP_IRQ_I2C1_PRIORITY                2 +#define RP_IRQ_RTC_PRIORITY                 3  /*   * ADC driver system settings. diff --git a/platforms/chibios/boards/GENERIC_RP_RP2040/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_RP_RP2040/configs/mcuconf.h index 902f9b5005..3a10f67727 100644 --- a/platforms/chibios/boards/GENERIC_RP_RP2040/configs/mcuconf.h +++ b/platforms/chibios/boards/GENERIC_RP_RP2040/configs/mcuconf.h @@ -54,6 +54,7 @@  #define RP_IRQ_USB0_PRIORITY                3  #define RP_IRQ_I2C0_PRIORITY                2  #define RP_IRQ_I2C1_PRIORITY                2 +#define RP_IRQ_RTC_PRIORITY                 3  /*   * ADC driver system settings. diff --git a/platforms/chibios/boards/GENERIC_WB32_F3G71XX/board/board.c b/platforms/chibios/boards/GENERIC_WB32_F3G71XX/board/board.c index f74c9e8be7..80472b88f7 100644 --- a/platforms/chibios/boards/GENERIC_WB32_F3G71XX/board/board.c +++ b/platforms/chibios/boards/GENERIC_WB32_F3G71XX/board/board.c @@ -73,6 +73,7 @@ void __early_init(void) {    wb32_clock_init();    wb32_gpio_init();  } +  /**   * @brief   Board-specific initialization code.   * @note    You can add your board-specific code here. @@ -80,7 +81,3 @@ void __early_init(void) {  void boardInit(void) {  } - -void restart_usb_driver(USBDriver *usbp) { -  // Do nothing. Restarting the USB driver on these boards breaks it. -} diff --git a/platforms/chibios/boards/GENERIC_WB32_FQ95XX/board/board.c b/platforms/chibios/boards/GENERIC_WB32_FQ95XX/board/board.c index a99537fc27..5701fd2e0d 100644 --- a/platforms/chibios/boards/GENERIC_WB32_FQ95XX/board/board.c +++ b/platforms/chibios/boards/GENERIC_WB32_FQ95XX/board/board.c @@ -73,6 +73,7 @@ void __early_init(void) {    wb32_clock_init();    wb32_gpio_init();  } +  /**   * @brief   Board-specific initialization code.   * @note    You can add your board-specific code here. @@ -80,7 +81,3 @@ void __early_init(void) {  void boardInit(void) {  } - -void restart_usb_driver(USBDriver *usbp) { -  // Do nothing. Restarting the USB driver on these boards breaks it. -} diff --git a/platforms/chibios/boards/QMK_BLOK/configs/mcuconf.h b/platforms/chibios/boards/QMK_BLOK/configs/mcuconf.h index 0c2ef592d6..d5dec0fcd0 100644 --- a/platforms/chibios/boards/QMK_BLOK/configs/mcuconf.h +++ b/platforms/chibios/boards/QMK_BLOK/configs/mcuconf.h @@ -54,6 +54,7 @@  #define RP_IRQ_USB0_PRIORITY                3  #define RP_IRQ_I2C0_PRIORITY                2  #define RP_IRQ_I2C1_PRIORITY                2 +#define RP_IRQ_RTC_PRIORITY                 3  /*   * ADC driver system settings. diff --git a/platforms/chibios/boards/QMK_PM2040/configs/mcuconf.h b/platforms/chibios/boards/QMK_PM2040/configs/mcuconf.h index 493dcf6434..e3351deb3b 100644 --- a/platforms/chibios/boards/QMK_PM2040/configs/mcuconf.h +++ b/platforms/chibios/boards/QMK_PM2040/configs/mcuconf.h @@ -54,6 +54,7 @@  #define RP_IRQ_USB0_PRIORITY                3  #define RP_IRQ_I2C0_PRIORITY                2  #define RP_IRQ_I2C1_PRIORITY                2 +#define RP_IRQ_RTC_PRIORITY                 3  /*   * ADC driver system settings. diff --git a/platforms/chibios/bootloader.mk b/platforms/chibios/bootloader.mk index fc898e7699..5b6edd73ad 100644 --- a/platforms/chibios/bootloader.mk +++ b/platforms/chibios/bootloader.mk @@ -107,6 +107,7 @@ ifeq ($(strip $(BOOTLOADER)), tinyuf2)  endif  ifeq ($(strip $(BOOTLOADER)), uf2boot)      OPT_DEFS += -DBOOTLOADER_UF2BOOT +    BOARD = STM32_F103_STM32DUINO      BOOTLOADER_TYPE = uf2boot      FIRMWARE_FORMAT = uf2  endif diff --git a/platforms/chibios/chibios_config.h b/platforms/chibios/chibios_config.h index 1f8a7842fe..f1636f9da0 100644 --- a/platforms/chibios/chibios_config.h +++ b/platforms/chibios/chibios_config.h @@ -37,7 +37,9 @@  #        define BACKLIGHT_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE)  #    endif  #    define BACKLIGHT_PWM_COUNTER_FREQUENCY 1000000 -#    define BACKLIGHT_PWM_PERIOD BACKLIGHT_PWM_COUNTER_FREQUENCY / 2048 +#    ifndef BACKLIGHT_PWM_PERIOD +#        define BACKLIGHT_PWM_PERIOD BACKLIGHT_PWM_COUNTER_FREQUENCY / 2048 +#    endif  #    ifndef AUDIO_PWM_PAL_MODE  #        define AUDIO_PWM_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE) diff --git a/platforms/chibios/drivers/audio_dac_additive.c b/platforms/chibios/drivers/audio_dac_additive.c index 22e4fa2608..26e044b048 100644 --- a/platforms/chibios/drivers/audio_dac_additive.c +++ b/platforms/chibios/drivers/audio_dac_additive.c @@ -84,7 +84,7 @@ static const dacsample_t dac_buffer_trapezoid[AUDIO_DAC_BUFFER_SIZE] = {0x0,   0                                                                          0xfff, 0xfdf, 0xf7f, 0xf1f, 0xebf, 0xe5f, 0xdff, 0xd9f, 0xd3f, 0xcdf, 0xc7f, 0xc1f, 0xbbf, 0xb5f, 0xaff, 0xa9f, 0xa3f, 0x9df, 0x97f, 0x91f, 0x8bf, 0x85f, 0x7ff, 0x79f, 0x73f, 0x6df, 0x67f, 0x61f, 0x5bf, 0x55f, 0x4ff, 0x49f, 0x43f, 0x3df, 0x37f, 0x31f, 0x2bf, 0x25f, 0x1ff, 0x19f, 0x13f, 0xdf,  0x7f,  0x1f,  0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0};  #endif // AUDIO_DAC_SAMPLE_WAVEFORM_TRAPEZOID -static dacsample_t dac_buffer_empty[AUDIO_DAC_BUFFER_SIZE] = {AUDIO_DAC_OFF_VALUE}; +static dacsample_t dac_buffer[AUDIO_DAC_BUFFER_SIZE];  /* keep track of the sample position for for each frequency */  static float dac_if[AUDIO_MAX_SIMULTANEOUS_TONES] = {0.0}; @@ -121,24 +121,27 @@ __attribute__((weak)) uint16_t dac_value_generate(void) {      /* doing additive wave synthesis over all currently playing tones = adding up       * sine-wave-samples for each frequency, scaled by the number of active tones       */ -    uint16_t value     = 0; -    float    frequency = 0.0f; +    uint_fast16_t value     = 0; +    float         frequency = 0.0f; -    for (uint8_t i = 0; i < active_tones_snapshot_length; i++) { +    for (size_t i = 0; i < active_tones_snapshot_length; i++) {          /* Note: a user implementation does not have to rely on the active_tones_snapshot, but           * could directly query the active frequencies through audio_get_processed_frequency */          frequency = active_tones_snapshot[i]; -        dac_if[i] = dac_if[i] + ((frequency * AUDIO_DAC_BUFFER_SIZE) / AUDIO_DAC_SAMPLE_RATE) * 2 / 3; +        float new_dac_if = dac_if[i]; +        new_dac_if += frequency * ((float)AUDIO_DAC_BUFFER_SIZE / AUDIO_DAC_SAMPLE_RATE * 2.0f / 3.0f);          /*Note: the 2/3 are necessary to get the correct frequencies on the           *      DAC output (as measured with an oscilloscope), since the gpt           *      timer runs with 3*AUDIO_DAC_SAMPLE_RATE; and the DAC callback           *      is called twice per conversion.*/ -        dac_if[i] = fmodf(dac_if[i], AUDIO_DAC_BUFFER_SIZE); +        while (new_dac_if >= AUDIO_DAC_BUFFER_SIZE) +            new_dac_if -= AUDIO_DAC_BUFFER_SIZE; +        dac_if[i] = new_dac_if;          // Wavetable generation/lookup -        uint16_t dac_i = (uint16_t)dac_if[i]; +        size_t dac_i = (size_t)new_dac_if;  #if defined(AUDIO_DAC_SAMPLE_WAVEFORM_SINE)          value += dac_buffer_sine[dac_i] / active_tones_snapshot_length; @@ -308,10 +311,17 @@ void audio_driver_initialize(void) {      DACD1.params->dac->CR &= ~DAC_CR_BOFF1;      DACD2.params->dac->CR &= ~DAC_CR_BOFF2; +    /* Start the DAC output with all off values. This buffer will then get fed +     * with samples from dac_end, which will play notes. +     */ +    for (size_t i = 0; i < AUDIO_DAC_BUFFER_SIZE; i++) { +        dac_buffer[i] = AUDIO_DAC_OFF_VALUE; +    } +      if (AUDIO_PIN == A4) { -        dacStartConversion(&DACD1, &dac_conv_cfg, dac_buffer_empty, AUDIO_DAC_BUFFER_SIZE); +        dacStartConversion(&DACD1, &dac_conv_cfg, dac_buffer, AUDIO_DAC_BUFFER_SIZE);      } else if (AUDIO_PIN == A5) { -        dacStartConversion(&DACD2, &dac_conv_cfg, dac_buffer_empty, AUDIO_DAC_BUFFER_SIZE); +        dacStartConversion(&DACD2, &dac_conv_cfg, dac_buffer, AUDIO_DAC_BUFFER_SIZE);      }      // no inverted/out-of-phase waveform (yet?), only pulling AUDIO_PIN_ALT to AUDIO_DAC_OFF_VALUE diff --git a/platforms/chibios/drivers/eeprom/eeprom_kinetis_flexram.c b/platforms/chibios/drivers/eeprom/eeprom_kinetis_flexram.c index 6468cbf3fa..9cf956b2f7 100644 --- a/platforms/chibios/drivers/eeprom/eeprom_kinetis_flexram.c +++ b/platforms/chibios/drivers/eeprom/eeprom_kinetis_flexram.c @@ -146,7 +146,7 @@ uint32_t eeprom_read_dword(const uint32_t *addr) {   *   * FIXME: needs doc   */ -void eeprom_read_block(void *buf, const void *addr, uint32_t len) { +void eeprom_read_block(void *buf, const void *addr, size_t len) {      uint32_t offset = (uint32_t)addr;      uint8_t *dest   = (uint8_t *)buf;      uint32_t end    = offset + len; @@ -271,7 +271,7 @@ void eeprom_write_dword(uint32_t *addr, uint32_t value) {   *   * FIXME: needs doc   */ -void eeprom_write_block(const void *buf, void *addr, uint32_t len) { +void eeprom_write_block(const void *buf, void *addr, size_t len) {      uint32_t       offset = (uint32_t)addr;      const uint8_t *src    = (const uint8_t *)buf; @@ -480,7 +480,7 @@ uint32_t eeprom_read_dword(const uint32_t *addr) {      return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24);  } -void eeprom_read_block(void *buf, const void *addr, uint32_t len) { +void eeprom_read_block(void *buf, const void *addr, size_t len) {      const uint8_t *p    = (const uint8_t *)addr;      uint8_t *      dest = (uint8_t *)buf;      while (len--) { @@ -506,7 +506,7 @@ void eeprom_write_dword(uint32_t *addr, uint32_t value) {      eeprom_write_byte(p, value >> 24);  } -void eeprom_write_block(const void *buf, void *addr, uint32_t len) { +void eeprom_write_block(const void *buf, void *addr, size_t len) {      uint8_t *      p   = (uint8_t *)addr;      const uint8_t *src = (const uint8_t *)buf;      while (len--) { diff --git a/platforms/chibios/drivers/serial.c b/platforms/chibios/drivers/serial.c index f087d0c2ed..f199716a2b 100644 --- a/platforms/chibios/drivers/serial.c +++ b/platforms/chibios/drivers/serial.c @@ -10,7 +10,7 @@  #include <hal.h>  // TODO: resolve/remove build warnings -#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT) && defined(PROTOCOL_CHIBIOS) && defined(WS2812_DRIVER_BITBANG) +#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT) && defined(PROTOCOL_CHIBIOS) && defined(WS2812_BITBANG)  #    warning "RGBLED_SPLIT not supported with bitbang WS2812 driver"  #endif diff --git a/platforms/chibios/drivers/spi_master.c b/platforms/chibios/drivers/spi_master.c index c3ab0623f0..481a2e422a 100644 --- a/platforms/chibios/drivers/spi_master.c +++ b/platforms/chibios/drivers/spi_master.c @@ -18,14 +18,14 @@  #include "timer.h" -static pin_t currentSlavePin = NO_PIN; +static bool spiStarted = false; -#if defined(K20x) || defined(KL2x) || defined(RP2040) -static SPIConfig spiConfig = {NULL, 0, 0, 0}; -#else -static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0}; +#if SPI_SELECT_MODE == SPI_SELECT_MODE_NONE +static pin_t currentSlavePin;  #endif +static SPIConfig spiConfig; +  __attribute__((weak)) void spi_init(void) {      static bool is_initialised = false;      if (!is_initialised) { @@ -33,28 +33,45 @@ __attribute__((weak)) void spi_init(void) {          // Try releasing special pins for a short time          setPinInput(SPI_SCK_PIN); -        setPinInput(SPI_MOSI_PIN); -        setPinInput(SPI_MISO_PIN); +        if (SPI_MOSI_PIN != NO_PIN) { +            setPinInput(SPI_MOSI_PIN); +        } +        if (SPI_MISO_PIN != NO_PIN) { +            setPinInput(SPI_MISO_PIN); +        }          chThdSleepMilliseconds(10);  #if defined(USE_GPIOV1)          palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), SPI_SCK_PAL_MODE); -        palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_PAL_MODE); -        palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_PAL_MODE); +        if (SPI_MOSI_PIN != NO_PIN) { +            palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_PAL_MODE); +        } +        if (SPI_MISO_PIN != NO_PIN) { +            palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_PAL_MODE); +        }  #else          palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), SPI_SCK_FLAGS); -        palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_FLAGS); -        palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_FLAGS); +        if (SPI_MOSI_PIN != NO_PIN) { +            palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_FLAGS); +        } +        if (SPI_MISO_PIN != NO_PIN) { +            palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_FLAGS); +        }  #endif          spiStop(&SPI_DRIVER); -        currentSlavePin = NO_PIN; +        spiStarted = false;      }  }  bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { -    if (currentSlavePin != NO_PIN || slavePin == NO_PIN) { +    if (spiStarted) { +        return false; +    } +#if SPI_SELECT_MODE != SPI_SELECT_MODE_NONE +    if (slavePin == NO_PIN) {          return false;      } +#endif  #if !(defined(WB32F3G71xx) || defined(WB32FQ95xx))      uint16_t roundedDivisor = 2; @@ -247,13 +264,29 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) {      }  #endif -    currentSlavePin  = slavePin; +    spiStarted = true; +#if SPI_SELECT_MODE == SPI_SELECT_MODE_NONE +    currentSlavePin = slavePin; +#endif +#if SPI_SELECT_MODE == SPI_SELECT_MODE_PAD      spiConfig.ssport = PAL_PORT(slavePin);      spiConfig.sspad  = PAL_PAD(slavePin); -      setPinOutput(slavePin); +#elif SPI_SELECT_MODE == SPI_SELECT_MODE_NONE +    if (slavePin != NO_PIN) { +        setPinOutput(slavePin); +    } +#else +#    error "Unsupported SPI_SELECT_MODE" +#endif +      spiStart(&SPI_DRIVER, &spiConfig);      spiSelect(&SPI_DRIVER); +#if SPI_SELECT_MODE == SPI_SELECT_MODE_NONE +    if (slavePin != NO_PIN) { +        writePinLow(slavePin); +    } +#endif      return true;  } @@ -283,9 +316,14 @@ spi_status_t spi_receive(uint8_t *data, uint16_t length) {  }  void spi_stop(void) { -    if (currentSlavePin != NO_PIN) { +    if (spiStarted) { +#if SPI_SELECT_MODE == SPI_SELECT_MODE_NONE +        if (currentSlavePin != NO_PIN) { +            writePinHigh(currentSlavePin); +        } +#endif          spiUnselect(&SPI_DRIVER);          spiStop(&SPI_DRIVER); -        currentSlavePin = NO_PIN; +        spiStarted = false;      }  } diff --git a/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c b/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c index 8d59e13bb2..de317e269a 100644 --- a/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c +++ b/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c @@ -268,7 +268,7 @@ static inline void sync_ws2812_transfer(void) {      busy_wait_until(LAST_TRANSFER);  } -void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) { +void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {      static bool is_initialized = false;      if (unlikely(!is_initialized)) {          is_initialized = ws2812_init(); diff --git a/platforms/chibios/drivers/wear_leveling/wear_leveling_efl_config.h b/platforms/chibios/drivers/wear_leveling/wear_leveling_efl_config.h index e74cf85efd..0f0fa694e9 100644 --- a/platforms/chibios/drivers/wear_leveling/wear_leveling_efl_config.h +++ b/platforms/chibios/drivers/wear_leveling/wear_leveling_efl_config.h @@ -50,5 +50,5 @@  // 1kB logical EEPROM  #ifndef WEAR_LEVELING_LOGICAL_SIZE -#    define WEAR_LEVELING_LOGICAL_SIZE 1024 +#    define WEAR_LEVELING_LOGICAL_SIZE ((WEAR_LEVELING_BACKING_SIZE) / 2)  #endif // WEAR_LEVELING_LOGICAL_SIZE diff --git a/platforms/chibios/drivers/wear_leveling/wear_leveling_rp2040_flash.c b/platforms/chibios/drivers/wear_leveling/wear_leveling_rp2040_flash.c index 640628e1e9..6624c30b5b 100644 --- a/platforms/chibios/drivers/wear_leveling/wear_leveling_rp2040_flash.c +++ b/platforms/chibios/drivers/wear_leveling/wear_leveling_rp2040_flash.c @@ -25,8 +25,8 @@  #define FLASHCMD_READ_STATUS 0x05  #define FLASHCMD_WRITE_ENABLE 0x06 -extern uint8_t  BOOT2_ROM[256]; -static uint32_t BOOT2_ROM_RAM[64]; +extern const uint8_t BOOT2_ROM[256]; +static uint32_t      BOOT2_ROM_RAM[64];  static ssi_hw_t *const ssi = (ssi_hw_t *)XIP_SSI_BASE; diff --git a/platforms/chibios/drivers/wear_leveling/wear_leveling_rp2040_flash_config.h b/platforms/chibios/drivers/wear_leveling/wear_leveling_rp2040_flash_config.h index 93a9aa0372..e1e2433601 100644 --- a/platforms/chibios/drivers/wear_leveling/wear_leveling_rp2040_flash_config.h +++ b/platforms/chibios/drivers/wear_leveling/wear_leveling_rp2040_flash_config.h @@ -18,7 +18,7 @@  // 32kB logical EEPROM  #ifndef WEAR_LEVELING_LOGICAL_SIZE -#    define WEAR_LEVELING_LOGICAL_SIZE 4096 +#    define WEAR_LEVELING_LOGICAL_SIZE ((WEAR_LEVELING_BACKING_SIZE) / 2)  #endif // WEAR_LEVELING_LOGICAL_SIZE  // Define how much flash space we have (defaults to lib/pico-sdk/src/boards/include/boards/***) diff --git a/platforms/chibios/drivers/ws2812_bitbang.c b/platforms/chibios/drivers/ws2812_bitbang.c index c55e0f654c..e3b735a1a6 100644 --- a/platforms/chibios/drivers/ws2812_bitbang.c +++ b/platforms/chibios/drivers/ws2812_bitbang.c @@ -72,7 +72,7 @@ void ws2812_init(void) {  }  // Setleds for standard RGB -void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { +void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {      static bool s_init = false;      if (!s_init) {          ws2812_init(); diff --git a/platforms/chibios/drivers/ws2812_pwm.c b/platforms/chibios/drivers/ws2812_pwm.c index cfee547a82..440687bd72 100644 --- a/platforms/chibios/drivers/ws2812_pwm.c +++ b/platforms/chibios/drivers/ws2812_pwm.c @@ -379,7 +379,7 @@ void ws2812_write_led_rgbw(uint16_t led_number, uint8_t r, uint8_t g, uint8_t b,  }  // Setleds for standard RGB -void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) { +void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {      static bool s_init = false;      if (!s_init) {          ws2812_init(); diff --git a/platforms/chibios/drivers/ws2812_spi.c b/platforms/chibios/drivers/ws2812_spi.c index f188576e04..01162f07f4 100644 --- a/platforms/chibios/drivers/ws2812_spi.c +++ b/platforms/chibios/drivers/ws2812_spi.c @@ -6,8 +6,8 @@  /* Adapted from https://github.com/gamazeps/ws2812b-chibios-SPIDMA/ */  // Define the spi your LEDs are plugged to here -#ifndef WS2812_SPI -#    define WS2812_SPI SPID1 +#ifndef WS2812_SPI_DRIVER +#    define WS2812_SPI_DRIVER SPID1  #endif  #ifndef WS2812_SPI_MOSI_PAL_MODE @@ -106,7 +106,7 @@ static uint8_t get_protocol_eq(uint8_t data, int pos) {      return eq;  } -static void set_led_color_rgb(LED_TYPE color, int pos) { +static void set_led_color_rgb(rgb_led_t color, int pos) {      uint8_t* tx_start = &txbuf[PREAMBLE_SIZE];  #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB) @@ -179,15 +179,15 @@ void ws2812_init(void) {  #endif      }; -    spiAcquireBus(&WS2812_SPI);     /* Acquire ownership of the bus.    */ -    spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters.       */ -    spiSelect(&WS2812_SPI);         /* Slave Select assertion.          */ +    spiAcquireBus(&WS2812_SPI_DRIVER);     /* Acquire ownership of the bus.    */ +    spiStart(&WS2812_SPI_DRIVER, &spicfg); /* Setup transfer parameters.       */ +    spiSelect(&WS2812_SPI_DRIVER);         /* Slave Select assertion.          */  #ifdef WS2812_SPI_USE_CIRCULAR_BUFFER -    spiStartSend(&WS2812_SPI, ARRAY_SIZE(txbuf), txbuf); +    spiStartSend(&WS2812_SPI_DRIVER, ARRAY_SIZE(txbuf), txbuf);  #endif  } -void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) { +void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {      static bool s_init = false;      if (!s_init) {          ws2812_init(); @@ -202,9 +202,9 @@ void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {      // Instead spiSend can be used to send synchronously (or the thread logic can be added back).  #ifndef WS2812_SPI_USE_CIRCULAR_BUFFER  #    ifdef WS2812_SPI_SYNC -    spiSend(&WS2812_SPI, ARRAY_SIZE(txbuf), txbuf); +    spiSend(&WS2812_SPI_DRIVER, ARRAY_SIZE(txbuf), txbuf);  #    else -    spiStartSend(&WS2812_SPI, ARRAY_SIZE(txbuf), txbuf); +    spiStartSend(&WS2812_SPI_DRIVER, ARRAY_SIZE(txbuf), txbuf);  #    endif  #endif  } diff --git a/platforms/chibios/platform.mk b/platforms/chibios/platform.mk index 081b001e6d..e42ecebdc5 100644 --- a/platforms/chibios/platform.mk +++ b/platforms/chibios/platform.mk @@ -476,6 +476,11 @@ HEX     = $(OBJCOPY) -O $(FORMAT)  EEP     =  BIN     = $(OBJCOPY) -O binary +# disable warning about RWX triggered by ChibiOS linker scripts +ifeq ("$(shell echo "int main(){}" | $(CC) -shared -Wl,--no-warn-rwx-segments -x c - -o /dev/null 2>&1)", "") +	SHARED_LDFLAGS += -Wl,--no-warn-rwx-segments +endif +  ##############################################################################  # Make targets  # diff --git a/platforms/chibios/vendors/RP/stage2_bootloaders.c b/platforms/chibios/vendors/RP/stage2_bootloaders.c index e65b0a5802..131fa0ce9e 100644 --- a/platforms/chibios/vendors/RP/stage2_bootloaders.c +++ b/platforms/chibios/vendors/RP/stage2_bootloaders.c @@ -13,7 +13,7 @@  #if defined(RP2040_FLASH_AT25SF128A) -uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = { +const uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {    0x00, 0xb5, 0x31, 0x4b, 0x21, 0x20, 0x58, 0x60, 0x98, 0x68, 0x02, 0x21,    0x88, 0x43, 0x98, 0x60, 0xd8, 0x60, 0x18, 0x61, 0x58, 0x61, 0x2d, 0x4b,    0x00, 0x21, 0x99, 0x60, 0x04, 0x21, 0x59, 0x61, 0x01, 0x21, 0xf0, 0x22, @@ -40,7 +40,7 @@ uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {  #elif defined(RP2040_FLASH_GD25Q64CS) -uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = { +const uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {    0x00, 0xb5, 0x31, 0x4b, 0x21, 0x20, 0x58, 0x60, 0x98, 0x68, 0x02, 0x21,    0x88, 0x43, 0x98, 0x60, 0xd8, 0x60, 0x18, 0x61, 0x58, 0x61, 0x2d, 0x4b,    0x00, 0x21, 0x99, 0x60, 0x04, 0x21, 0x59, 0x61, 0x01, 0x21, 0xf0, 0x22, @@ -67,7 +67,7 @@ uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {  #elif defined(RP2040_FLASH_W25X10CL) -uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = { +const uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {    0x00, 0xb5, 0x14, 0x4b, 0x00, 0x21, 0x99, 0x60, 0x04, 0x21, 0x59, 0x61,    0x12, 0x49, 0x19, 0x60, 0x00, 0x21, 0x59, 0x60, 0x11, 0x49, 0x12, 0x48,    0x01, 0x60, 0x01, 0x21, 0x99, 0x60, 0xbb, 0x21, 0x19, 0x66, 0x02, 0x21, @@ -94,7 +94,7 @@ uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {  #elif defined(RP2040_FLASH_IS25LP080) -uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = { +const uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {    0x00, 0xb5, 0x2b, 0x4b, 0x00, 0x21, 0x99, 0x60, 0x04, 0x21, 0x59, 0x61,    0x29, 0x49, 0x19, 0x60, 0x01, 0x21, 0x99, 0x60, 0x28, 0x48, 0x00, 0xf0,    0x42, 0xf8, 0x28, 0x4a, 0x90, 0x42, 0x12, 0xd0, 0x06, 0x21, 0x19, 0x66, @@ -121,7 +121,7 @@ uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {  #elif defined(RP2040_FLASH_GENERIC_03H) -uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = { +const uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {    0x00, 0xb5, 0x0c, 0x4b, 0x00, 0x21, 0x99, 0x60, 0x04, 0x21, 0x59, 0x61,    0x0a, 0x49, 0x19, 0x60, 0x0a, 0x49, 0x0b, 0x48, 0x01, 0x60, 0x00, 0x21,    0x59, 0x60, 0x01, 0x21, 0x99, 0x60, 0x01, 0xbc, 0x00, 0x28, 0x00, 0xd0, @@ -148,7 +148,7 @@ uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {  #else -uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = { +const uint8_t BOOTLOADER_SECTION BOOT2_ROM[256] = {    0x00, 0xb5, 0x32, 0x4b, 0x21, 0x20, 0x58, 0x60, 0x98, 0x68, 0x02, 0x21,    0x88, 0x43, 0x98, 0x60, 0xd8, 0x60, 0x18, 0x61, 0x58, 0x61, 0x2e, 0x4b,    0x00, 0x21, 0x99, 0x60, 0x04, 0x21, 0x59, 0x61, 0x01, 0x21, 0xf0, 0x22, diff --git a/platforms/test/timer.c b/platforms/test/timer.c index 320cc57782..eb929d7dac 100644 --- a/platforms/test/timer.c +++ b/platforms/test/timer.c @@ -17,34 +17,65 @@  #include "timer.h"  #include <stdatomic.h> -static atomic_uint_least32_t current_time = 0; +static atomic_uint_least32_t current_time      = 0; +static atomic_uint_least32_t async_tick_amount = 0; +static atomic_uint_least32_t access_counter    = 0; + +void simulate_async_tick(uint32_t t) { +    async_tick_amount = t; +} + +uint32_t timer_read_internal(void) { +    return current_time; +} + +uint32_t current_access_counter(void) { +    return access_counter; +} + +void reset_access_counter(void) { +    access_counter = 0; +}  void timer_init(void) { -    current_time = 0; +    current_time      = 0; +    async_tick_amount = 0; +    access_counter    = 0;  }  void timer_clear(void) { -    current_time = 0; +    current_time      = 0; +    async_tick_amount = 0; +    access_counter    = 0;  }  uint16_t timer_read(void) { -    return current_time & 0xFFFF; +    return (uint16_t)timer_read32();  } +  uint32_t timer_read32(void) { +    if (access_counter++ > 0) { +        current_time += async_tick_amount; +    }      return current_time;  } +  uint16_t timer_elapsed(uint16_t last) {      return TIMER_DIFF_16(timer_read(), last);  } +  uint32_t timer_elapsed32(uint32_t last) {      return TIMER_DIFF_32(timer_read32(), last);  }  void set_time(uint32_t t) { -    current_time = t; +    current_time   = t; +    access_counter = 0;  } +  void advance_time(uint32_t ms) {      current_time += ms; +    access_counter = 0;  }  void wait_ms(uint32_t ms) { | 
