aboutsummaryrefslogtreecommitdiff
path: root/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'platforms')
-rw-r--r--platforms/avr/drivers/analog.c23
-rw-r--r--platforms/avr/drivers/analog.h1
-rw-r--r--platforms/chibios/boards/QMK_PROTON_C/configs/config.h9
-rw-r--r--platforms/chibios/boards/common/ld/STM32F401xC.ld85
-rw-r--r--platforms/chibios/boards/common/ld/STM32F411xE.ld85
-rw-r--r--platforms/chibios/drivers/i2c_master.c12
-rw-r--r--platforms/chibios/drivers/i2c_master.h25
-rw-r--r--platforms/chibios/drivers/serial.c2
-rw-r--r--platforms/chibios/drivers/serial_usart.c10
-rw-r--r--platforms/chibios/drivers/spi_master.c6
-rw-r--r--platforms/chibios/drivers/spi_master.h6
-rw-r--r--platforms/chibios/drivers/uart.c8
-rw-r--r--platforms/chibios/drivers/ws2812.c2
-rw-r--r--platforms/chibios/drivers/ws2812_pwm.c48
-rw-r--r--platforms/chibios/drivers/ws2812_spi.c27
15 files changed, 263 insertions, 86 deletions
diff --git a/platforms/avr/drivers/analog.c b/platforms/avr/drivers/analog.c
index 8d299ffdb..628835cce 100644
--- a/platforms/avr/drivers/analog.c
+++ b/platforms/avr/drivers/analog.c
@@ -23,29 +23,6 @@ static uint8_t aref = ADC_REF_POWER;
23 23
24void analogReference(uint8_t mode) { aref = mode & (_BV(REFS1) | _BV(REFS0)); } 24void analogReference(uint8_t mode) { aref = mode & (_BV(REFS1) | _BV(REFS0)); }
25 25
26// Arduino compatible pin input
27int16_t analogRead(uint8_t pin) {
28#if defined(__AVR_ATmega32U4__)
29 // clang-format off
30 static const uint8_t PROGMEM pin_to_mux[] = {
31 //A0 A1 A2 A3 A4 A5
32 //F7 F6 F5 F4 F1 F0
33 0x07, 0x06, 0x05, 0x04, 0x01, 0x00,
34 //A6 A7 A8 A9 A10 A11
35 //D4 D7 B4 B5 B6 D6
36 0x20, 0x22, 0x23, 0x24, 0x25, 0x21
37 };
38 // clang-format on
39 if (pin >= 12) return 0;
40 return adc_read(pgm_read_byte(pin_to_mux + pin));
41#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
42 if (pin >= 8) return 0;
43 return adc_read(pin);
44#else
45 return 0;
46#endif
47}
48
49int16_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); } 26int16_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); }
50 27
51uint8_t pinToMux(pin_t pin) { 28uint8_t pinToMux(pin_t pin) {
diff --git a/platforms/avr/drivers/analog.h b/platforms/avr/drivers/analog.h
index 058882450..b3c05e197 100644
--- a/platforms/avr/drivers/analog.h
+++ b/platforms/avr/drivers/analog.h
@@ -23,7 +23,6 @@
23extern "C" { 23extern "C" {
24#endif 24#endif
25void analogReference(uint8_t mode); 25void analogReference(uint8_t mode);
26int16_t analogRead(uint8_t pin);
27 26
28int16_t analogReadPin(pin_t pin); 27int16_t analogReadPin(pin_t pin);
29uint8_t pinToMux(pin_t pin); 28uint8_t pinToMux(pin_t pin);
diff --git a/platforms/chibios/boards/QMK_PROTON_C/configs/config.h b/platforms/chibios/boards/QMK_PROTON_C/configs/config.h
index a73f0c0b4..fa1a73c35 100644
--- a/platforms/chibios/boards/QMK_PROTON_C/configs/config.h
+++ b/platforms/chibios/boards/QMK_PROTON_C/configs/config.h
@@ -18,3 +18,12 @@
18#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP 18#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
19# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE 19# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE
20#endif 20#endif
21
22#ifdef CONVERT_TO_PROTON_C
23# ifndef I2C1_SDA_PIN
24# define I2C1_SDA_PIN D1
25# endif
26# ifndef I2C1_SCL_PIN
27# define I2C1_SCL_PIN D0
28# endif
29#endif
diff --git a/platforms/chibios/boards/common/ld/STM32F401xC.ld b/platforms/chibios/boards/common/ld/STM32F401xC.ld
new file mode 100644
index 000000000..8fae66cec
--- /dev/null
+++ b/platforms/chibios/boards/common/ld/STM32F401xC.ld
@@ -0,0 +1,85 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/*
18 * STM32F401xC memory setup.
19 */
20MEMORY
21{
22 flash0 (rx) : org = 0x08000000, len = 16k /* Sector 0 - Init code as ROM bootloader assumes application starts here */
23 flash1 (rx) : org = 0x08004000, len = 16k /* Sector 1 - Emulated eeprom */
24 flash2 (rx) : org = 0x08008000, len = 256k - 32k /* Sector 2..6 - Rest of firmware */
25 flash3 (rx) : org = 0x00000000, len = 0
26 flash4 (rx) : org = 0x00000000, len = 0
27 flash5 (rx) : org = 0x00000000, len = 0
28 flash6 (rx) : org = 0x00000000, len = 0
29 flash7 (rx) : org = 0x00000000, len = 0
30 ram0 (wx) : org = 0x20000000, len = 64k
31 ram1 (wx) : org = 0x00000000, len = 0
32 ram2 (wx) : org = 0x00000000, len = 0
33 ram3 (wx) : org = 0x00000000, len = 0
34 ram4 (wx) : org = 0x00000000, len = 0
35 ram5 (wx) : org = 0x00000000, len = 0
36 ram6 (wx) : org = 0x00000000, len = 0
37 ram7 (wx) : org = 0x00000000, len = 0
38}
39
40/* For each data/text section two region are defined, a virtual region
41 and a load region (_LMA suffix).*/
42
43/* Flash region to be used for exception vectors.*/
44REGION_ALIAS("VECTORS_FLASH", flash0);
45REGION_ALIAS("VECTORS_FLASH_LMA", flash0);
46
47/* Flash region to be used for constructors and destructors.*/
48REGION_ALIAS("XTORS_FLASH", flash2);
49REGION_ALIAS("XTORS_FLASH_LMA", flash2);
50
51/* Flash region to be used for code text.*/
52REGION_ALIAS("TEXT_FLASH", flash2);
53REGION_ALIAS("TEXT_FLASH_LMA", flash2);
54
55/* Flash region to be used for read only data.*/
56REGION_ALIAS("RODATA_FLASH", flash2);
57REGION_ALIAS("RODATA_FLASH_LMA", flash2);
58
59/* Flash region to be used for various.*/
60REGION_ALIAS("VARIOUS_FLASH", flash2);
61REGION_ALIAS("VARIOUS_FLASH_LMA", flash2);
62
63/* Flash region to be used for RAM(n) initialization data.*/
64REGION_ALIAS("RAM_INIT_FLASH_LMA", flash2);
65
66/* RAM region to be used for Main stack. This stack accommodates the processing
67 of all exceptions and interrupts.*/
68REGION_ALIAS("MAIN_STACK_RAM", ram0);
69
70/* RAM region to be used for the process stack. This is the stack used by
71 the main() function.*/
72REGION_ALIAS("PROCESS_STACK_RAM", ram0);
73
74/* RAM region to be used for data segment.*/
75REGION_ALIAS("DATA_RAM", ram0);
76REGION_ALIAS("DATA_RAM_LMA", flash2);
77
78/* RAM region to be used for BSS segment.*/
79REGION_ALIAS("BSS_RAM", ram0);
80
81/* RAM region to be used for the default heap.*/
82REGION_ALIAS("HEAP_RAM", ram0);
83
84/* Generic rules inclusion.*/
85INCLUDE rules.ld
diff --git a/platforms/chibios/boards/common/ld/STM32F411xE.ld b/platforms/chibios/boards/common/ld/STM32F411xE.ld
new file mode 100644
index 000000000..aea8084b5
--- /dev/null
+++ b/platforms/chibios/boards/common/ld/STM32F411xE.ld
@@ -0,0 +1,85 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/*
18 * STM32F411xE memory setup.
19 */
20MEMORY
21{
22 flash0 (rx) : org = 0x08000000, len = 16k /* Sector 0 - Init code as ROM bootloader assumes application starts here */
23 flash1 (rx) : org = 0x08004000, len = 16k /* Sector 1 - Emulated eeprom */
24 flash2 (rx) : org = 0x08008000, len = 512k - 32k /* Sector 2..7 - Rest of firmware */
25 flash3 (rx) : org = 0x00000000, len = 0
26 flash4 (rx) : org = 0x00000000, len = 0
27 flash5 (rx) : org = 0x00000000, len = 0
28 flash6 (rx) : org = 0x00000000, len = 0
29 flash7 (rx) : org = 0x00000000, len = 0
30 ram0 (wx) : org = 0x20000000, len = 128k
31 ram1 (wx) : org = 0x00000000, len = 0
32 ram2 (wx) : org = 0x00000000, len = 0
33 ram3 (wx) : org = 0x00000000, len = 0
34 ram4 (wx) : org = 0x00000000, len = 0
35 ram5 (wx) : org = 0x00000000, len = 0
36 ram6 (wx) : org = 0x00000000, len = 0
37 ram7 (wx) : org = 0x00000000, len = 0
38}
39
40/* For each data/text section two region are defined, a virtual region
41 and a load region (_LMA suffix).*/
42
43/* Flash region to be used for exception vectors.*/
44REGION_ALIAS("VECTORS_FLASH", flash0);
45REGION_ALIAS("VECTORS_FLASH_LMA", flash0);
46
47/* Flash region to be used for constructors and destructors.*/
48REGION_ALIAS("XTORS_FLASH", flash2);
49REGION_ALIAS("XTORS_FLASH_LMA", flash2);
50
51/* Flash region to be used for code text.*/
52REGION_ALIAS("TEXT_FLASH", flash2);
53REGION_ALIAS("TEXT_FLASH_LMA", flash2);
54
55/* Flash region to be used for read only data.*/
56REGION_ALIAS("RODATA_FLASH", flash2);
57REGION_ALIAS("RODATA_FLASH_LMA", flash2);
58
59/* Flash region to be used for various.*/
60REGION_ALIAS("VARIOUS_FLASH", flash2);
61REGION_ALIAS("VARIOUS_FLASH_LMA", flash2);
62
63/* Flash region to be used for RAM(n) initialization data.*/
64REGION_ALIAS("RAM_INIT_FLASH_LMA", flash2);
65
66/* RAM region to be used for Main stack. This stack accommodates the processing
67 of all exceptions and interrupts.*/
68REGION_ALIAS("MAIN_STACK_RAM", ram0);
69
70/* RAM region to be used for the process stack. This is the stack used by
71 the main() function.*/
72REGION_ALIAS("PROCESS_STACK_RAM", ram0);
73
74/* RAM region to be used for data segment.*/
75REGION_ALIAS("DATA_RAM", ram0);
76REGION_ALIAS("DATA_RAM_LMA", flash2);
77
78/* RAM region to be used for BSS segment.*/
79REGION_ALIAS("BSS_RAM", ram0);
80
81/* RAM region to be used for the default heap.*/
82REGION_ALIAS("HEAP_RAM", ram0);
83
84/* Generic rules inclusion.*/
85INCLUDE rules.ld
diff --git a/platforms/chibios/drivers/i2c_master.c b/platforms/chibios/drivers/i2c_master.c
index fc4bb2ab3..981f6fa06 100644
--- a/platforms/chibios/drivers/i2c_master.c
+++ b/platforms/chibios/drivers/i2c_master.c
@@ -63,16 +63,16 @@ __attribute__((weak)) void i2c_init(void) {
63 is_initialised = true; 63 is_initialised = true;
64 64
65 // Try releasing special pins for a short time 65 // Try releasing special pins for a short time
66 palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT); 66 palSetLineMode(I2C1_SCL_PIN, PAL_MODE_INPUT);
67 palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT); 67 palSetLineMode(I2C1_SDA_PIN, PAL_MODE_INPUT);
68 68
69 chThdSleepMilliseconds(10); 69 chThdSleepMilliseconds(10);
70#if defined(USE_GPIOV1) 70#if defined(USE_GPIOV1)
71 palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, I2C1_SCL_PAL_MODE); 71 palSetLineMode(I2C1_SCL_PIN, I2C1_SCL_PAL_MODE);
72 palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, I2C1_SDA_PAL_MODE); 72 palSetLineMode(I2C1_SDA_PIN, I2C1_SDA_PAL_MODE);
73#else 73#else
74 palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); 74 palSetLineMode(I2C1_SCL_PIN, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_OUTPUT_TYPE_OPENDRAIN);
75 palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); 75 palSetLineMode(I2C1_SDA_PIN, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_OUTPUT_TYPE_OPENDRAIN);
76#endif 76#endif
77 } 77 }
78} 78}
diff --git a/platforms/chibios/drivers/i2c_master.h b/platforms/chibios/drivers/i2c_master.h
index c68109acb..ce32fd245 100644
--- a/platforms/chibios/drivers/i2c_master.h
+++ b/platforms/chibios/drivers/i2c_master.h
@@ -27,24 +27,11 @@
27#include <ch.h> 27#include <ch.h>
28#include <hal.h> 28#include <hal.h>
29 29
30#ifdef I2C1_BANK 30#ifndef I2C1_SCL_PIN
31# define I2C1_SCL_BANK I2C1_BANK 31# define I2C1_SCL_PIN B6
32# define I2C1_SDA_BANK I2C1_BANK
33#endif 32#endif
34 33#ifndef I2C1_SDA_PIN
35#ifndef I2C1_SCL_BANK 34# define I2C1_SDA_PIN B7
36# define I2C1_SCL_BANK GPIOB
37#endif
38
39#ifndef I2C1_SDA_BANK
40# define I2C1_SDA_BANK GPIOB
41#endif
42
43#ifndef I2C1_SCL
44# define I2C1_SCL 6
45#endif
46#ifndef I2C1_SDA
47# define I2C1_SDA 7
48#endif 35#endif
49 36
50#ifdef USE_I2CV1 37#ifdef USE_I2CV1
@@ -83,10 +70,10 @@
83 70
84#ifdef USE_GPIOV1 71#ifdef USE_GPIOV1
85# ifndef I2C1_SCL_PAL_MODE 72# ifndef I2C1_SCL_PAL_MODE
86# define I2C1_SCL_PAL_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN 73# define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATE_OPENDRAIN
87# endif 74# endif
88# ifndef I2C1_SDA_PAL_MODE 75# ifndef I2C1_SDA_PAL_MODE
89# define I2C1_SDA_PAL_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN 76# define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATE_OPENDRAIN
90# endif 77# endif
91#else 78#else
92// The default PAL alternate modes are used to signal that the pins are used for I2C 79// The default PAL alternate modes are used to signal that the pins are used for I2C
diff --git a/platforms/chibios/drivers/serial.c b/platforms/chibios/drivers/serial.c
index f54fbcee4..ef6f0aa8d 100644
--- a/platforms/chibios/drivers/serial.c
+++ b/platforms/chibios/drivers/serial.c
@@ -19,7 +19,7 @@
19# error "chSysPolledDelayX method not supported on this platform" 19# error "chSysPolledDelayX method not supported on this platform"
20#else 20#else
21# undef wait_us 21# undef wait_us
22# define wait_us(x) chSysPolledDelayX(US2RTC(STM32_SYSCLK, x)) 22# define wait_us(x) chSysPolledDelayX(US2RTC(CPU_CLOCK, x))
23#endif 23#endif
24 24
25#ifndef SELECT_SOFT_SERIAL_SPEED 25#ifndef SELECT_SOFT_SERIAL_SPEED
diff --git a/platforms/chibios/drivers/serial_usart.c b/platforms/chibios/drivers/serial_usart.c
index ea4473791..124e4be68 100644
--- a/platforms/chibios/drivers/serial_usart.c
+++ b/platforms/chibios/drivers/serial_usart.c
@@ -104,9 +104,9 @@ static inline bool receive(uint8_t* destination, const size_t size) {
104__attribute__((weak)) void usart_init(void) { 104__attribute__((weak)) void usart_init(void) {
105# if defined(MCU_STM32) 105# if defined(MCU_STM32)
106# if defined(USE_GPIOV1) 106# if defined(USE_GPIOV1)
107 palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); 107 palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE_OPENDRAIN);
108# else 108# else
109 palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); 109 palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_OUTPUT_TYPE_OPENDRAIN);
110# endif 110# endif
111 111
112# if defined(USART_REMAP) 112# if defined(USART_REMAP)
@@ -125,11 +125,11 @@ __attribute__((weak)) void usart_init(void) {
125__attribute__((weak)) void usart_init(void) { 125__attribute__((weak)) void usart_init(void) {
126# if defined(MCU_STM32) 126# if defined(MCU_STM32)
127# if defined(USE_GPIOV1) 127# if defined(USE_GPIOV1)
128 palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL); 128 palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE_PUSHPULL);
129 palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT); 129 palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);
130# else 130# else
131 palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); 131 palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST);
132 palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_RX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); 132 palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_RX_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST);
133# endif 133# endif
134 134
135# if defined(USART_REMAP) 135# if defined(USART_REMAP)
diff --git a/platforms/chibios/drivers/spi_master.c b/platforms/chibios/drivers/spi_master.c
index 28ddcbb2b..f98db6db9 100644
--- a/platforms/chibios/drivers/spi_master.c
+++ b/platforms/chibios/drivers/spi_master.c
@@ -42,9 +42,9 @@ __attribute__((weak)) void spi_init(void) {
42 palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_PAL_MODE); 42 palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_PAL_MODE);
43 palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_PAL_MODE); 43 palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_PAL_MODE);
44#else 44#else
45 palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); 45 palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST);
46 palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); 46 palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST);
47 palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_ALTERNATE(SPI_MISO_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); 47 palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_ALTERNATE(SPI_MISO_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST);
48#endif 48#endif
49 } 49 }
50} 50}
diff --git a/platforms/chibios/drivers/spi_master.h b/platforms/chibios/drivers/spi_master.h
index b5a6ef143..6a3ce481f 100644
--- a/platforms/chibios/drivers/spi_master.h
+++ b/platforms/chibios/drivers/spi_master.h
@@ -33,7 +33,7 @@
33 33
34#ifndef SPI_SCK_PAL_MODE 34#ifndef SPI_SCK_PAL_MODE
35# if defined(USE_GPIOV1) 35# if defined(USE_GPIOV1)
36# define SPI_SCK_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL 36# define SPI_SCK_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
37# else 37# else
38# define SPI_SCK_PAL_MODE 5 38# define SPI_SCK_PAL_MODE 5
39# endif 39# endif
@@ -45,7 +45,7 @@
45 45
46#ifndef SPI_MOSI_PAL_MODE 46#ifndef SPI_MOSI_PAL_MODE
47# if defined(USE_GPIOV1) 47# if defined(USE_GPIOV1)
48# define SPI_MOSI_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL 48# define SPI_MOSI_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
49# else 49# else
50# define SPI_MOSI_PAL_MODE 5 50# define SPI_MOSI_PAL_MODE 5
51# endif 51# endif
@@ -57,7 +57,7 @@
57 57
58#ifndef SPI_MISO_PAL_MODE 58#ifndef SPI_MISO_PAL_MODE
59# if defined(USE_GPIOV1) 59# if defined(USE_GPIOV1)
60# define SPI_MISO_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL 60# define SPI_MISO_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
61# else 61# else
62# define SPI_MISO_PAL_MODE 5 62# define SPI_MISO_PAL_MODE 5
63# endif 63# endif
diff --git a/platforms/chibios/drivers/uart.c b/platforms/chibios/drivers/uart.c
index 030335b34..0e8e0515a 100644
--- a/platforms/chibios/drivers/uart.c
+++ b/platforms/chibios/drivers/uart.c
@@ -29,11 +29,11 @@ void uart_init(uint32_t baud) {
29 serialConfig.speed = baud; 29 serialConfig.speed = baud;
30 30
31#if defined(USE_GPIOV1) 31#if defined(USE_GPIOV1)
32 palSetLineMode(SD1_TX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); 32 palSetLineMode(SD1_TX_PIN, PAL_MODE_ALTERNATE_OPENDRAIN);
33 palSetLineMode(SD1_RX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); 33 palSetLineMode(SD1_RX_PIN, PAL_MODE_ALTERNATE_OPENDRAIN);
34#else 34#else
35 palSetLineMode(SD1_TX_PIN, PAL_MODE_ALTERNATE(SD1_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); 35 palSetLineMode(SD1_TX_PIN, PAL_MODE_ALTERNATE(SD1_TX_PAL_MODE) | PAL_OUTPUT_TYPE_OPENDRAIN);
36 palSetLineMode(SD1_RX_PIN, PAL_MODE_ALTERNATE(SD1_RX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); 36 palSetLineMode(SD1_RX_PIN, PAL_MODE_ALTERNATE(SD1_RX_PAL_MODE) | PAL_OUTPUT_TYPE_OPENDRAIN);
37#endif 37#endif
38 sdStart(&SERIAL_DRIVER, &serialConfig); 38 sdStart(&SERIAL_DRIVER, &serialConfig);
39 } 39 }
diff --git a/platforms/chibios/drivers/ws2812.c b/platforms/chibios/drivers/ws2812.c
index 0d12e2fb7..ffcdcff24 100644
--- a/platforms/chibios/drivers/ws2812.c
+++ b/platforms/chibios/drivers/ws2812.c
@@ -23,7 +23,7 @@
23#endif 23#endif
24 24
25#define NUMBER_NOPS 6 25#define NUMBER_NOPS 6
26#define CYCLES_PER_SEC (STM32_SYSCLK / NUMBER_NOPS * NOP_FUDGE) 26#define CYCLES_PER_SEC (CPU_CLOCK / NUMBER_NOPS * NOP_FUDGE)
27#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives 27#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives
28#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC) 28#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC)
29#define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE) 29#define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE)
diff --git a/platforms/chibios/drivers/ws2812_pwm.c b/platforms/chibios/drivers/ws2812_pwm.c
index e6af55b6b..c17b9cd4e 100644
--- a/platforms/chibios/drivers/ws2812_pwm.c
+++ b/platforms/chibios/drivers/ws2812_pwm.c
@@ -5,7 +5,9 @@
5/* Adapted from https://github.com/joewa/WS2812-LED-Driver_ChibiOS/ */ 5/* Adapted from https://github.com/joewa/WS2812-LED-Driver_ChibiOS/ */
6 6
7#ifdef RGBW 7#ifdef RGBW
8# error "RGBW not supported" 8# define WS2812_CHANNELS 4
9#else
10# define WS2812_CHANNELS 3
9#endif 11#endif
10 12
11#ifndef WS2812_PWM_DRIVER 13#ifndef WS2812_PWM_DRIVER
@@ -40,15 +42,15 @@
40// Default Push Pull 42// Default Push Pull
41#ifndef WS2812_EXTERNAL_PULLUP 43#ifndef WS2812_EXTERNAL_PULLUP
42# if defined(USE_GPIOV1) 44# if defined(USE_GPIOV1)
43# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL 45# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE_PUSHPULL
44# else 46# else
45# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING 47# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING
46# endif 48# endif
47#else 49#else
48# if defined(USE_GPIOV1) 50# if defined(USE_GPIOV1)
49# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN 51# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE_OPENDRAIN
50# else 52# else
51# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING 53# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_OUTPUT_TYPE_OPENDRAIN | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING
52# endif 54# endif
53#endif 55#endif
54 56
@@ -59,7 +61,7 @@
59 61
60/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ 62/* --- PRIVATE CONSTANTS ---------------------------------------------------- */
61 63
62#define WS2812_PWM_FREQUENCY (STM32_SYSCLK / 2) /**< Clock frequency of PWM, must be valid with respect to system clock! */ 64#define WS2812_PWM_FREQUENCY (CPU_CLOCK / 2) /**< Clock frequency of PWM, must be valid with respect to system clock! */
63#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY / WS2812_PWM_TARGET_PERIOD) /**< Clock period in ticks. 1 / 800kHz = 1.25 uS (as per datasheet) */ 65#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY / WS2812_PWM_TARGET_PERIOD) /**< Clock period in ticks. 1 / 800kHz = 1.25 uS (as per datasheet) */
64 66
65/** 67/**
@@ -68,8 +70,9 @@
68 * The reset period for each frame is defined in WS2812_TRST_US. 70 * The reset period for each frame is defined in WS2812_TRST_US.
69 * Calculate the number of zeroes to add at the end assuming 1.25 uS/bit: 71 * Calculate the number of zeroes to add at the end assuming 1.25 uS/bit:
70 */ 72 */
73#define WS2812_COLOR_BITS (WS2812_CHANNELS * 8)
71#define WS2812_RESET_BIT_N (1000 * WS2812_TRST_US / 1250) 74#define WS2812_RESET_BIT_N (1000 * WS2812_TRST_US / 1250)
72#define WS2812_COLOR_BIT_N (RGBLED_NUM * 24) /**< Number of data bits */ 75#define WS2812_COLOR_BIT_N (RGBLED_NUM * WS2812_COLOR_BITS) /**< Number of data bits */
73#define WS2812_BIT_N (WS2812_COLOR_BIT_N + WS2812_RESET_BIT_N) /**< Total number of bits in a frame */ 76#define WS2812_BIT_N (WS2812_COLOR_BIT_N + WS2812_RESET_BIT_N) /**< Total number of bits in a frame */
74 77
75/** 78/**
@@ -114,7 +117,7 @@
114 * 117 *
115 * @return The bit index 118 * @return The bit index
116 */ 119 */
117#define WS2812_BIT(led, byte, bit) (24 * (led) + 8 * (byte) + (7 - (bit))) 120#define WS2812_BIT(led, byte, bit) (WS2812_COLOR_BITS * (led) + 8 * (byte) + (7 - (bit)))
118 121
119#if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB) 122#if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
120/** 123/**
@@ -228,6 +231,20 @@
228# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 0, (bit)) 231# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 0, (bit))
229#endif 232#endif
230 233
234#ifdef RGBW
235/**
236 * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given white bit
237 *
238 * @note The white byte is the last byte in the color packet
239 *
240 * @param[in] led: The led index [0, @ref WS2812_LED_N)
241 * @param[in] bit: The bit index [0, 7]
242 *
243 * @return The bit index
244 */
245# define WS2812_WHITE_BIT(led, bit) WS2812_BIT((led), 3, (bit))
246#endif
247
231/* --- PRIVATE VARIABLES ---------------------------------------------------- */ 248/* --- PRIVATE VARIABLES ---------------------------------------------------- */
232 249
233static uint32_t ws2812_frame_buffer[WS2812_BIT_N + 1]; /**< Buffer for a frame */ 250static uint32_t ws2812_frame_buffer[WS2812_BIT_N + 1]; /**< Buffer for a frame */
@@ -296,6 +313,17 @@ void ws2812_write_led(uint16_t led_number, uint8_t r, uint8_t g, uint8_t b) {
296 ws2812_frame_buffer[WS2812_BLUE_BIT(led_number, bit)] = ((b >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0; 313 ws2812_frame_buffer[WS2812_BLUE_BIT(led_number, bit)] = ((b >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
297 } 314 }
298} 315}
316void ws2812_write_led_rgbw(uint16_t led_number, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
317 // Write color to frame buffer
318 for (uint8_t bit = 0; bit < 8; bit++) {
319 ws2812_frame_buffer[WS2812_RED_BIT(led_number, bit)] = ((r >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
320 ws2812_frame_buffer[WS2812_GREEN_BIT(led_number, bit)] = ((g >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
321 ws2812_frame_buffer[WS2812_BLUE_BIT(led_number, bit)] = ((b >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
322#ifdef RGBW
323 ws2812_frame_buffer[WS2812_WHITE_BIT(led_number, bit)] = ((w >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
324#endif
325 }
326}
299 327
300// Setleds for standard RGB 328// Setleds for standard RGB
301void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) { 329void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
@@ -306,6 +334,10 @@ void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
306 } 334 }
307 335
308 for (uint16_t i = 0; i < leds; i++) { 336 for (uint16_t i = 0; i < leds; i++) {
337#ifdef RGBW
338 ws2812_write_led_rgbw(i, ledarray[i].r, ledarray[i].g, ledarray[i].b, ledarray[i].w);
339#else
309 ws2812_write_led(i, ledarray[i].r, ledarray[i].g, ledarray[i].b); 340 ws2812_write_led(i, ledarray[i].r, ledarray[i].g, ledarray[i].b);
341#endif
310 } 342 }
311} 343}
diff --git a/platforms/chibios/drivers/ws2812_spi.c b/platforms/chibios/drivers/ws2812_spi.c
index fe14b478a..62722f466 100644
--- a/platforms/chibios/drivers/ws2812_spi.c
+++ b/platforms/chibios/drivers/ws2812_spi.c
@@ -3,10 +3,6 @@
3 3
4/* Adapted from https://github.com/gamazeps/ws2812b-chibios-SPIDMA/ */ 4/* Adapted from https://github.com/gamazeps/ws2812b-chibios-SPIDMA/ */
5 5
6#ifdef RGBW
7# error "RGBW not supported"
8#endif
9
10// Define the spi your LEDs are plugged to here 6// Define the spi your LEDs are plugged to here
11#ifndef WS2812_SPI 7#ifndef WS2812_SPI
12# define WS2812_SPI SPID1 8# define WS2812_SPI SPID1
@@ -24,15 +20,15 @@
24// Default Push Pull 20// Default Push Pull
25#ifndef WS2812_EXTERNAL_PULLUP 21#ifndef WS2812_EXTERNAL_PULLUP
26# if defined(USE_GPIOV1) 22# if defined(USE_GPIOV1)
27# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL 23# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE_PUSHPULL
28# else 24# else
29# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL 25# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL
30# endif 26# endif
31#else 27#else
32# if defined(USE_GPIOV1) 28# if defined(USE_GPIOV1)
33# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN 29# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE_OPENDRAIN
34# else 30# else
35# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN 31# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_OUTPUT_TYPE_OPENDRAIN
36# endif 32# endif
37#endif 33#endif
38 34
@@ -68,14 +64,18 @@
68#endif 64#endif
69 65
70#if defined(USE_GPIOV1) 66#if defined(USE_GPIOV1)
71# define WS2812_SCK_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL 67# define WS2812_SCK_OUTPUT_MODE PAL_MODE_ALTERNATE_PUSHPULL
72#else 68#else
73# define WS2812_SCK_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL 69# define WS2812_SCK_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL
74#endif 70#endif
75 71
76#define BYTES_FOR_LED_BYTE 4 72#define BYTES_FOR_LED_BYTE 4
77#define NB_COLORS 3 73#ifdef RGBW
78#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS) 74# define WS2812_CHANNELS 4
75#else
76# define WS2812_CHANNELS 3
77#endif
78#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * WS2812_CHANNELS)
79#define DATA_SIZE (BYTES_FOR_LED * RGBLED_NUM) 79#define DATA_SIZE (BYTES_FOR_LED * RGBLED_NUM)
80#define RESET_SIZE (1000 * WS2812_TRST_US / (2 * 1250)) 80#define RESET_SIZE (1000 * WS2812_TRST_US / (2 * 1250))
81#define PREAMBLE_SIZE 4 81#define PREAMBLE_SIZE 4
@@ -116,6 +116,9 @@ static void set_led_color_rgb(LED_TYPE color, int pos) {
116 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.g, j); 116 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.g, j);
117 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.r, j); 117 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.r, j);
118#endif 118#endif
119#ifdef RGBW
120 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 4 + j] = get_protocol_eq(color.w, j);
121#endif
119} 122}
120 123
121void ws2812_init(void) { 124void ws2812_init(void) {