diff options
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/chibios/analog.c | 59 | ||||
| -rw-r--r-- | drivers/chibios/serial_usart.c | 69 | ||||
| -rw-r--r-- | drivers/chibios/serial_usart.h | 90 | ||||
| -rw-r--r-- | drivers/chibios/serial_usart_duplex.c | 261 | ||||
| -rw-r--r-- | drivers/chibios/ws2812_pwm.c | 11 | ||||
| -rw-r--r-- | drivers/chibios/ws2812_spi.c | 45 | ||||
| -rw-r--r-- | drivers/issi/is31fl3733.c | 2 | ||||
| -rw-r--r-- | drivers/oled/oled_driver.c | 29 | ||||
| -rw-r--r-- | drivers/oled/oled_driver.h | 12 |
9 files changed, 512 insertions, 66 deletions
diff --git a/drivers/chibios/analog.c b/drivers/chibios/analog.c index 2b3872afb..8c476fcac 100644 --- a/drivers/chibios/analog.c +++ b/drivers/chibios/analog.c | |||
| @@ -101,7 +101,11 @@ | |||
| 101 | 101 | ||
| 102 | // Options are 12, 10, 8, and 6 bit. | 102 | // Options are 12, 10, 8, and 6 bit. |
| 103 | #ifndef ADC_RESOLUTION | 103 | #ifndef ADC_RESOLUTION |
| 104 | # define ADC_RESOLUTION ADC_CFGR1_RES_10BIT | 104 | # ifdef ADC_CFGR_RES_10BITS // ADCv3, ADCv4 |
| 105 | # define ADC_RESOLUTION ADC_CFGR_RES_10BITS | ||
| 106 | # else // ADCv1, ADCv5, or the bodge for ADCv2 above | ||
| 107 | # define ADC_RESOLUTION ADC_CFGR1_RES_10BIT | ||
| 108 | # endif | ||
| 105 | #endif | 109 | #endif |
| 106 | 110 | ||
| 107 | static ADCConfig adcCfg = {}; | 111 | static ADCConfig adcCfg = {}; |
| @@ -119,7 +123,7 @@ static ADCConversionGroup adcConversionGroup = { | |||
| 119 | .smpr = ADC_SAMPLING_RATE, | 123 | .smpr = ADC_SAMPLING_RATE, |
| 120 | #elif defined(USE_ADCV2) | 124 | #elif defined(USE_ADCV2) |
| 121 | # if !defined(STM32F1XX) | 125 | # if !defined(STM32F1XX) |
| 122 | .cr2 = ADC_CR2_SWSTART, // F103 seem very unhappy with, F401 seems very unhappy without... | 126 | .cr2 = ADC_CR2_SWSTART, // F103 seem very unhappy with, F401 seems very unhappy without... |
| 123 | # endif | 127 | # endif |
| 124 | .smpr2 = ADC_SMPR2_SMP_AN0(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN1(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN2(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN3(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN4(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN5(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN6(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN7(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN8(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN9(ADC_SAMPLING_RATE), | 128 | .smpr2 = ADC_SMPR2_SMP_AN0(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN1(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN2(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN3(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN4(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN5(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN6(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN7(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN8(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN9(ADC_SAMPLING_RATE), |
| 125 | .smpr1 = ADC_SMPR1_SMP_AN10(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN11(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN12(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN13(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN14(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN15(ADC_SAMPLING_RATE), | 129 | .smpr1 = ADC_SMPR1_SMP_AN10(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN11(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN12(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN13(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN14(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN15(ADC_SAMPLING_RATE), |
| @@ -161,8 +165,8 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) { | |||
| 161 | case B0: return TO_MUX( ADC_CHANNEL_IN12, 2 ); | 165 | case B0: return TO_MUX( ADC_CHANNEL_IN12, 2 ); |
| 162 | case B1: return TO_MUX( ADC_CHANNEL_IN1, 2 ); | 166 | case B1: return TO_MUX( ADC_CHANNEL_IN1, 2 ); |
| 163 | case B2: return TO_MUX( ADC_CHANNEL_IN12, 1 ); | 167 | case B2: return TO_MUX( ADC_CHANNEL_IN12, 1 ); |
| 164 | case B12: return TO_MUX( ADC_CHANNEL_IN2, 3 ); | 168 | case B12: return TO_MUX( ADC_CHANNEL_IN3, 3 ); |
| 165 | case B13: return TO_MUX( ADC_CHANNEL_IN3, 3 ); | 169 | case B13: return TO_MUX( ADC_CHANNEL_IN5, 2 ); |
| 166 | case B14: return TO_MUX( ADC_CHANNEL_IN4, 3 ); | 170 | case B14: return TO_MUX( ADC_CHANNEL_IN4, 3 ); |
| 167 | case B15: return TO_MUX( ADC_CHANNEL_IN5, 3 ); | 171 | case B15: return TO_MUX( ADC_CHANNEL_IN5, 3 ); |
| 168 | case C0: return TO_MUX( ADC_CHANNEL_IN6, 0 ); // Can also be ADC2 | 172 | case C0: return TO_MUX( ADC_CHANNEL_IN6, 0 ); // Can also be ADC2 |
| @@ -189,11 +193,52 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) { | |||
| 189 | case E15: return TO_MUX( ADC_CHANNEL_IN2, 3 ); | 193 | case E15: return TO_MUX( ADC_CHANNEL_IN2, 3 ); |
| 190 | case F2: return TO_MUX( ADC_CHANNEL_IN10, 0 ); // Can also be ADC2 | 194 | case F2: return TO_MUX( ADC_CHANNEL_IN10, 0 ); // Can also be ADC2 |
| 191 | case F4: return TO_MUX( ADC_CHANNEL_IN5, 0 ); | 195 | case F4: return TO_MUX( ADC_CHANNEL_IN5, 0 ); |
| 192 | #elif defined(STM32F4XX) // TODO: add all pins | 196 | #elif defined(STM32F4XX) |
| 193 | case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 ); | 197 | case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 ); |
| 194 | //case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 ); | 198 | case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 ); |
| 195 | #elif defined(STM32F1XX) // TODO: add all pins | 199 | case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 ); |
| 200 | case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 ); | ||
| 201 | case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 ); | ||
| 202 | case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 ); | ||
| 203 | case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 ); | ||
| 204 | case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 ); | ||
| 205 | case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 ); | ||
| 206 | case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 ); | ||
| 207 | case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 ); | ||
| 208 | case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 ); | ||
| 209 | case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 ); | ||
| 210 | case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 ); | ||
| 211 | case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 ); | ||
| 212 | case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 ); | ||
| 213 | # if STM32_ADC_USE_ADC3 | ||
| 214 | case F3: return TO_MUX( ADC_CHANNEL_IN9, 2 ); | ||
| 215 | case F4: return TO_MUX( ADC_CHANNEL_IN14, 2 ); | ||
| 216 | case F5: return TO_MUX( ADC_CHANNEL_IN15, 2 ); | ||
| 217 | case F6: return TO_MUX( ADC_CHANNEL_IN4, 2 ); | ||
| 218 | case F7: return TO_MUX( ADC_CHANNEL_IN5, 2 ); | ||
| 219 | case F8: return TO_MUX( ADC_CHANNEL_IN6, 2 ); | ||
| 220 | case F9: return TO_MUX( ADC_CHANNEL_IN7, 2 ); | ||
| 221 | case F10: return TO_MUX( ADC_CHANNEL_IN8, 2 ); | ||
| 222 | # endif | ||
| 223 | #elif defined(STM32F1XX) | ||
| 196 | case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 ); | 224 | case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 ); |
| 225 | case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 ); | ||
| 226 | case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 ); | ||
| 227 | case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 ); | ||
| 228 | case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 ); | ||
| 229 | case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 ); | ||
| 230 | case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 ); | ||
| 231 | case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 ); | ||
| 232 | case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 ); | ||
| 233 | case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 ); | ||
| 234 | case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 ); | ||
| 235 | case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 ); | ||
| 236 | case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 ); | ||
| 237 | case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 ); | ||
| 238 | case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 ); | ||
| 239 | case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 ); | ||
| 240 | // STM32F103x[C-G] in 144-pin packages also have analog inputs on F6...F10, but they are on ADC3, and the | ||
| 241 | // ChibiOS ADC driver for STM32F1xx currently supports only ADC1, therefore these pins are not usable. | ||
| 197 | #endif | 242 | #endif |
| 198 | } | 243 | } |
| 199 | 244 | ||
diff --git a/drivers/chibios/serial_usart.c b/drivers/chibios/serial_usart.c index 7c81b1646..cae29388c 100644 --- a/drivers/chibios/serial_usart.c +++ b/drivers/chibios/serial_usart.c | |||
| @@ -1,13 +1,20 @@ | |||
| 1 | #include "quantum.h" | 1 | /* Copyright 2021 QMK |
| 2 | #include "serial.h" | 2 | * |
| 3 | #include "print.h" | 3 | * This program is free software: you can redistribute it and/or modify |
| 4 | 4 | * it under the terms of the GNU General Public License as published by | |
| 5 | #include <ch.h> | 5 | * the Free Software Foundation, either version 3 of the License, or |
| 6 | #include <hal.h> | 6 | * (at your option) any later version. |
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 7 | 16 | ||
| 8 | #ifndef USART_CR1_M0 | 17 | #include "serial_usart.h" |
| 9 | # define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so | ||
| 10 | #endif | ||
| 11 | 18 | ||
| 12 | #ifndef USE_GPIOV1 | 19 | #ifndef USE_GPIOV1 |
| 13 | // The default PAL alternate modes are used to signal that the pins are used for USART | 20 | // The default PAL alternate modes are used to signal that the pins are used for USART |
| @@ -20,50 +27,10 @@ | |||
| 20 | # define SERIAL_USART_DRIVER SD1 | 27 | # define SERIAL_USART_DRIVER SD1 |
| 21 | #endif | 28 | #endif |
| 22 | 29 | ||
| 23 | #ifndef SERIAL_USART_CR1 | ||
| 24 | # define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #ifndef SERIAL_USART_CR2 | ||
| 28 | # define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #ifndef SERIAL_USART_CR3 | ||
| 32 | # define SERIAL_USART_CR3 0 | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #ifdef SOFT_SERIAL_PIN | 30 | #ifdef SOFT_SERIAL_PIN |
| 36 | # define SERIAL_USART_TX_PIN SOFT_SERIAL_PIN | 31 | # define SERIAL_USART_TX_PIN SOFT_SERIAL_PIN |
| 37 | #endif | 32 | #endif |
| 38 | 33 | ||
| 39 | #ifndef SELECT_SOFT_SERIAL_SPEED | ||
| 40 | # define SELECT_SOFT_SERIAL_SPEED 1 | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifdef SERIAL_USART_SPEED | ||
| 44 | // Allow advanced users to directly set SERIAL_USART_SPEED | ||
| 45 | #elif SELECT_SOFT_SERIAL_SPEED == 0 | ||
| 46 | # define SERIAL_USART_SPEED 460800 | ||
| 47 | #elif SELECT_SOFT_SERIAL_SPEED == 1 | ||
| 48 | # define SERIAL_USART_SPEED 230400 | ||
| 49 | #elif SELECT_SOFT_SERIAL_SPEED == 2 | ||
| 50 | # define SERIAL_USART_SPEED 115200 | ||
| 51 | #elif SELECT_SOFT_SERIAL_SPEED == 3 | ||
| 52 | # define SERIAL_USART_SPEED 57600 | ||
| 53 | #elif SELECT_SOFT_SERIAL_SPEED == 4 | ||
| 54 | # define SERIAL_USART_SPEED 38400 | ||
| 55 | #elif SELECT_SOFT_SERIAL_SPEED == 5 | ||
| 56 | # define SERIAL_USART_SPEED 19200 | ||
| 57 | #else | ||
| 58 | # error invalid SELECT_SOFT_SERIAL_SPEED value | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #ifndef SERIAL_USART_TIMEOUT | ||
| 62 | # define SERIAL_USART_TIMEOUT 100 | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #define HANDSHAKE_MAGIC 7 | ||
| 66 | |||
| 67 | static inline msg_t sdWriteHalfDuplex(SerialDriver* driver, uint8_t* data, uint8_t size) { | 34 | static inline msg_t sdWriteHalfDuplex(SerialDriver* driver, uint8_t* data, uint8_t size) { |
| 68 | msg_t ret = sdWrite(driver, data, size); | 35 | msg_t ret = sdWrite(driver, data, size); |
| 69 | 36 | ||
| @@ -123,6 +90,10 @@ __attribute__((weak)) void usart_init(void) { | |||
| 123 | #else | 90 | #else |
| 124 | palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | 91 | palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); |
| 125 | #endif | 92 | #endif |
| 93 | |||
| 94 | #if defined(USART_REMAP) | ||
| 95 | USART_REMAP; | ||
| 96 | #endif | ||
| 126 | } | 97 | } |
| 127 | 98 | ||
| 128 | void usart_master_init(void) { | 99 | void usart_master_init(void) { |
diff --git a/drivers/chibios/serial_usart.h b/drivers/chibios/serial_usart.h new file mode 100644 index 000000000..fee7b4d15 --- /dev/null +++ b/drivers/chibios/serial_usart.h | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #pragma once | ||
| 18 | |||
| 19 | #include "quantum.h" | ||
| 20 | #include "serial.h" | ||
| 21 | #include "printf.h" | ||
| 22 | |||
| 23 | #include <ch.h> | ||
| 24 | #include <hal.h> | ||
| 25 | |||
| 26 | #ifndef USART_CR1_M0 | ||
| 27 | # define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #ifndef SERIAL_USART_CR1 | ||
| 31 | # define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #ifndef SERIAL_USART_CR2 | ||
| 35 | # define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifndef SERIAL_USART_CR3 | ||
| 39 | # define SERIAL_USART_CR3 0 | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #if defined(USART1_REMAP) | ||
| 43 | # define USART_REMAP \ | ||
| 44 | do { \ | ||
| 45 | (AFIO->MAPR |= AFIO_MAPR_USART1_REMAP); \ | ||
| 46 | } while (0) | ||
| 47 | #elif defined(USART2_REMAP) | ||
| 48 | # define USART_REMAP \ | ||
| 49 | do { \ | ||
| 50 | (AFIO->MAPR |= AFIO_MAPR_USART2_REMAP); \ | ||
| 51 | } while (0) | ||
| 52 | #elif defined(USART3_PARTIALREMAP) | ||
| 53 | # define USART_REMAP \ | ||
| 54 | do { \ | ||
| 55 | (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP); \ | ||
| 56 | } while (0) | ||
| 57 | #elif defined(USART3_FULLREMAP) | ||
| 58 | # define USART_REMAP \ | ||
| 59 | do { \ | ||
| 60 | (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); \ | ||
| 61 | } while (0) | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #ifndef SELECT_SOFT_SERIAL_SPEED | ||
| 65 | # define SELECT_SOFT_SERIAL_SPEED 1 | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #ifdef SERIAL_USART_SPEED | ||
| 69 | // Allow advanced users to directly set SERIAL_USART_SPEED | ||
| 70 | #elif SELECT_SOFT_SERIAL_SPEED == 0 | ||
| 71 | # define SERIAL_USART_SPEED 460800 | ||
| 72 | #elif SELECT_SOFT_SERIAL_SPEED == 1 | ||
| 73 | # define SERIAL_USART_SPEED 230400 | ||
| 74 | #elif SELECT_SOFT_SERIAL_SPEED == 2 | ||
| 75 | # define SERIAL_USART_SPEED 115200 | ||
| 76 | #elif SELECT_SOFT_SERIAL_SPEED == 3 | ||
| 77 | # define SERIAL_USART_SPEED 57600 | ||
| 78 | #elif SELECT_SOFT_SERIAL_SPEED == 4 | ||
| 79 | # define SERIAL_USART_SPEED 38400 | ||
| 80 | #elif SELECT_SOFT_SERIAL_SPEED == 5 | ||
| 81 | # define SERIAL_USART_SPEED 19200 | ||
| 82 | #else | ||
| 83 | # error invalid SELECT_SOFT_SERIAL_SPEED value | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #ifndef SERIAL_USART_TIMEOUT | ||
| 87 | # define SERIAL_USART_TIMEOUT 100 | ||
| 88 | #endif | ||
| 89 | |||
| 90 | #define HANDSHAKE_MAGIC 7 | ||
diff --git a/drivers/chibios/serial_usart_duplex.c b/drivers/chibios/serial_usart_duplex.c new file mode 100644 index 000000000..cc9b889ac --- /dev/null +++ b/drivers/chibios/serial_usart_duplex.c | |||
| @@ -0,0 +1,261 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "serial_usart.h" | ||
| 18 | |||
| 19 | #include <stdatomic.h> | ||
| 20 | |||
| 21 | #if !defined(USE_GPIOV1) | ||
| 22 | // The default PAL alternate modes are used to signal that the pins are used for USART | ||
| 23 | # if !defined(SERIAL_USART_TX_PAL_MODE) | ||
| 24 | # define SERIAL_USART_TX_PAL_MODE 7 | ||
| 25 | # endif | ||
| 26 | # if !defined(SERIAL_USART_RX_PAL_MODE) | ||
| 27 | # define SERIAL_USART_RX_PAL_MODE 7 | ||
| 28 | # endif | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #if !defined(SERIAL_USART_DRIVER) | ||
| 32 | # define SERIAL_USART_DRIVER UARTD1 | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #if !defined(SERIAL_USART_TX_PIN) | ||
| 36 | # define SERIAL_USART_TX_PIN A9 | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #if !defined(SERIAL_USART_RX_PIN) | ||
| 40 | # define SERIAL_USART_RX_PIN A10 | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #define SIGNAL_HANDSHAKE_RECEIVED 0x1 | ||
| 44 | |||
| 45 | void handle_transactions_slave(uint8_t sstd_index); | ||
| 46 | static void receive_transaction_handshake(UARTDriver* uartp, uint16_t received_handshake); | ||
| 47 | |||
| 48 | /* | ||
| 49 | * UART driver configuration structure. We use the blocking DMA enabled API and | ||
| 50 | * the rxchar callback to receive handshake tokens but only on the slave halve. | ||
| 51 | */ | ||
| 52 | // clang-format off | ||
| 53 | static UARTConfig uart_config = { | ||
| 54 | .txend1_cb = NULL, | ||
| 55 | .txend2_cb = NULL, | ||
| 56 | .rxend_cb = NULL, | ||
| 57 | .rxchar_cb = NULL, | ||
| 58 | .rxerr_cb = NULL, | ||
| 59 | .timeout_cb = NULL, | ||
| 60 | .speed = (SERIAL_USART_SPEED), | ||
| 61 | .cr1 = (SERIAL_USART_CR1), | ||
| 62 | .cr2 = (SERIAL_USART_CR2), | ||
| 63 | .cr3 = (SERIAL_USART_CR3) | ||
| 64 | }; | ||
| 65 | // clang-format on | ||
| 66 | |||
| 67 | static SSTD_t* Transaction_table = NULL; | ||
| 68 | static uint8_t Transaction_table_size = 0; | ||
| 69 | static atomic_uint_least8_t handshake = 0xFF; | ||
| 70 | static thread_reference_t tp_target = NULL; | ||
| 71 | |||
| 72 | /* | ||
| 73 | * This callback is invoked when a character is received but the application | ||
| 74 | * was not ready to receive it, the character is passed as parameter. | ||
| 75 | * Receive transaction table index from initiator, which doubles as basic handshake token. */ | ||
| 76 | static void receive_transaction_handshake(UARTDriver* uartp, uint16_t received_handshake) { | ||
| 77 | /* Check if received handshake is not a valid transaction id. | ||
| 78 | * Please note that we can still catch a seemingly valid handshake | ||
| 79 | * i.e. a byte from a ongoing transfer which is in the allowed range. | ||
| 80 | * So this check mainly prevents any obviously wrong handshakes and | ||
| 81 | * subsequent wakeups of the receiving thread, which is a costly operation. */ | ||
| 82 | if (received_handshake > Transaction_table_size) { | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | |||
| 86 | handshake = (uint8_t)received_handshake; | ||
| 87 | chSysLockFromISR(); | ||
| 88 | /* Wakeup receiving thread to start a transaction. */ | ||
| 89 | chEvtSignalI(tp_target, (eventmask_t)SIGNAL_HANDSHAKE_RECEIVED); | ||
| 90 | chSysUnlockFromISR(); | ||
| 91 | } | ||
| 92 | |||
| 93 | __attribute__((weak)) void usart_init(void) { | ||
| 94 | #if defined(USE_GPIOV1) | ||
| 95 | palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL); | ||
| 96 | palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT); | ||
| 97 | #else | ||
| 98 | palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); | ||
| 99 | palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_RX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); | ||
| 100 | #endif | ||
| 101 | } | ||
| 102 | |||
| 103 | /* | ||
| 104 | * This thread runs on the slave half and reacts to transactions initiated from the master. | ||
| 105 | */ | ||
| 106 | static THD_WORKING_AREA(waSlaveThread, 1024); | ||
| 107 | static THD_FUNCTION(SlaveThread, arg) { | ||
| 108 | (void)arg; | ||
| 109 | chRegSetThreadName("slave_usart_tx_rx"); | ||
| 110 | |||
| 111 | while (true) { | ||
| 112 | /* We sleep as long as there is no handshake waiting for us. */ | ||
| 113 | chEvtWaitAny((eventmask_t)SIGNAL_HANDSHAKE_RECEIVED); | ||
| 114 | handle_transactions_slave(handshake); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | void soft_serial_target_init(SSTD_t* const sstd_table, int sstd_table_size) { | ||
| 119 | Transaction_table = sstd_table; | ||
| 120 | Transaction_table_size = (uint8_t)sstd_table_size; | ||
| 121 | usart_init(); | ||
| 122 | |||
| 123 | #if defined(USART_REMAP) | ||
| 124 | USART_REMAP; | ||
| 125 | #endif | ||
| 126 | |||
| 127 | tp_target = chThdCreateStatic(waSlaveThread, sizeof(waSlaveThread), HIGHPRIO, SlaveThread, NULL); | ||
| 128 | |||
| 129 | // Start receiving handshake tokens on slave halve | ||
| 130 | uart_config.rxchar_cb = receive_transaction_handshake; | ||
| 131 | uartStart(&SERIAL_USART_DRIVER, &uart_config); | ||
| 132 | } | ||
| 133 | |||
| 134 | /** | ||
| 135 | * @brief React to transactions started by the master. | ||
| 136 | * This version uses duplex send and receive usart pheriphals and DMA backed transfers. | ||
| 137 | */ | ||
| 138 | void inline handle_transactions_slave(uint8_t sstd_index) { | ||
| 139 | size_t buffer_size = 0; | ||
| 140 | msg_t msg = 0; | ||
| 141 | SSTD_t* trans = &Transaction_table[sstd_index]; | ||
| 142 | |||
| 143 | /* Send back the handshake which is XORed as a simple checksum, | ||
| 144 | to signal that the slave is ready to receive possible transaction buffers */ | ||
| 145 | sstd_index ^= HANDSHAKE_MAGIC; | ||
| 146 | buffer_size = (size_t)sizeof(sstd_index); | ||
| 147 | msg = uartSendTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index, TIME_MS2I(SERIAL_USART_TIMEOUT)); | ||
| 148 | |||
| 149 | if (msg != MSG_OK) { | ||
| 150 | if (trans->status) { | ||
| 151 | *trans->status = TRANSACTION_NO_RESPONSE; | ||
| 152 | } | ||
| 153 | return; | ||
| 154 | } | ||
| 155 | |||
| 156 | /* Receive transaction buffer from the master. If this transaction requires it.*/ | ||
| 157 | buffer_size = (size_t)trans->initiator2target_buffer_size; | ||
| 158 | if (buffer_size) { | ||
| 159 | msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->initiator2target_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT)); | ||
| 160 | if (msg != MSG_OK) { | ||
| 161 | if (trans->status) { | ||
| 162 | *trans->status = TRANSACTION_NO_RESPONSE; | ||
| 163 | } | ||
| 164 | return; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | /* Send transaction buffer to the master. If this transaction requires it. */ | ||
| 169 | buffer_size = (size_t)trans->target2initiator_buffer_size; | ||
| 170 | if (buffer_size) { | ||
| 171 | msg = uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->target2initiator_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT)); | ||
| 172 | if (msg != MSG_OK) { | ||
| 173 | if (trans->status) { | ||
| 174 | *trans->status = TRANSACTION_NO_RESPONSE; | ||
| 175 | } | ||
| 176 | return; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | if (trans->status) { | ||
| 181 | *trans->status = TRANSACTION_ACCEPTED; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | void soft_serial_initiator_init(SSTD_t* const sstd_table, int sstd_table_size) { | ||
| 186 | Transaction_table = sstd_table; | ||
| 187 | Transaction_table_size = (uint8_t)sstd_table_size; | ||
| 188 | usart_init(); | ||
| 189 | |||
| 190 | #if defined(SERIAL_USART_PIN_SWAP) | ||
| 191 | uart_config.cr2 |= USART_CR2_SWAP; // master has swapped TX/RX pins | ||
| 192 | #endif | ||
| 193 | |||
| 194 | #if defined(USART_REMAP) | ||
| 195 | USART_REMAP; | ||
| 196 | #endif | ||
| 197 | |||
| 198 | uartStart(&SERIAL_USART_DRIVER, &uart_config); | ||
| 199 | } | ||
| 200 | |||
| 201 | /** | ||
| 202 | * @brief Start transaction from the master to the slave. | ||
| 203 | * This version uses duplex send and receive usart pheriphals and DMA backed transfers. | ||
| 204 | * | ||
| 205 | * @param index Transaction Table index of the transaction to start. | ||
| 206 | * @return int TRANSACTION_NO_RESPONSE in case of Timeout. | ||
| 207 | * TRANSACTION_TYPE_ERROR in case of invalid transaction index. | ||
| 208 | * TRANSACTION_END in case of success. | ||
| 209 | */ | ||
| 210 | #if !defined(SERIAL_USE_MULTI_TRANSACTION) | ||
| 211 | int soft_serial_transaction(void) { | ||
| 212 | uint8_t sstd_index = 0; | ||
| 213 | #else | ||
| 214 | int soft_serial_transaction(int index) { | ||
| 215 | uint8_t sstd_index = index; | ||
| 216 | #endif | ||
| 217 | |||
| 218 | if (sstd_index > Transaction_table_size) { | ||
| 219 | return TRANSACTION_TYPE_ERROR; | ||
| 220 | } | ||
| 221 | |||
| 222 | SSTD_t* const trans = &Transaction_table[sstd_index]; | ||
| 223 | msg_t msg = 0; | ||
| 224 | size_t buffer_size = (size_t)sizeof(sstd_index); | ||
| 225 | |||
| 226 | /* Send transaction table index to the slave, which doubles as basic handshake token. */ | ||
| 227 | uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index, TIME_MS2I(SERIAL_USART_TIMEOUT)); | ||
| 228 | |||
| 229 | uint8_t sstd_index_shake = 0xFF; | ||
| 230 | buffer_size = (size_t)sizeof(sstd_index_shake); | ||
| 231 | |||
| 232 | /* Receive the handshake token from the slave. The token was XORed by the slave as a simple checksum. | ||
| 233 | If the tokens match, the master will start to send and receive possible transaction buffers. */ | ||
| 234 | msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index_shake, TIME_MS2I(SERIAL_USART_TIMEOUT)); | ||
| 235 | if (msg != MSG_OK || (sstd_index_shake != (sstd_index ^ HANDSHAKE_MAGIC))) { | ||
| 236 | dprintln("USART: Handshake Failed"); | ||
| 237 | return TRANSACTION_NO_RESPONSE; | ||
| 238 | } | ||
| 239 | |||
| 240 | /* Send transaction buffer to the slave. If this transaction requires it. */ | ||
| 241 | buffer_size = (size_t)trans->initiator2target_buffer_size; | ||
| 242 | if (buffer_size) { | ||
| 243 | msg = uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->initiator2target_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT)); | ||
| 244 | if (msg != MSG_OK) { | ||
| 245 | dprintln("USART: Send Failed"); | ||
| 246 | return TRANSACTION_NO_RESPONSE; | ||
| 247 | } | ||
| 248 | } | ||
| 249 | |||
| 250 | /* Receive transaction buffer from the slave. If this transaction requires it. */ | ||
| 251 | buffer_size = (size_t)trans->target2initiator_buffer_size; | ||
| 252 | if (buffer_size) { | ||
| 253 | msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->target2initiator_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT)); | ||
| 254 | if (msg != MSG_OK) { | ||
| 255 | dprintln("USART: Receive Failed"); | ||
| 256 | return TRANSACTION_NO_RESPONSE; | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | return TRANSACTION_END; | ||
| 261 | } | ||
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c index 140120d48..e6af55b6b 100644 --- a/drivers/chibios/ws2812_pwm.c +++ b/drivers/chibios/ws2812_pwm.c | |||
| @@ -27,6 +27,15 @@ | |||
| 27 | # error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" | 27 | # error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" |
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| 30 | #ifndef WS2812_PWM_COMPLEMENTARY_OUTPUT | ||
| 31 | # define WS2812_PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH | ||
| 32 | #else | ||
| 33 | # if !STM32_PWM_USE_ADVANCED | ||
| 34 | # error "WS2812_PWM_COMPLEMENTARY_OUTPUT requires STM32_PWM_USE_ADVANCED == TRUE" | ||
| 35 | # endif | ||
| 36 | # define WS2812_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH | ||
| 37 | #endif | ||
| 38 | |||
| 30 | // Push Pull or Open Drain Configuration | 39 | // Push Pull or Open Drain Configuration |
| 31 | // Default Push Pull | 40 | // Default Push Pull |
| 32 | #ifndef WS2812_EXTERNAL_PULLUP | 41 | #ifndef WS2812_EXTERNAL_PULLUP |
| @@ -247,7 +256,7 @@ void ws2812_init(void) { | |||
| 247 | .channels = | 256 | .channels = |
| 248 | { | 257 | { |
| 249 | [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled | 258 | [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled |
| 250 | [WS2812_PWM_CHANNEL - 1] = {.mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // Turn on the channel we care about | 259 | [WS2812_PWM_CHANNEL - 1] = {.mode = WS2812_PWM_OUTPUT_MODE, .callback = NULL}, // Turn on the channel we care about |
| 251 | }, | 260 | }, |
| 252 | .cr2 = 0, | 261 | .cr2 = 0, |
| 253 | .dier = TIM_DIER_UDE, // DMA on update event for next period | 262 | .dier = TIM_DIER_UDE, // DMA on update event for next period |
diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c index 89df2987b..e02cbabc0 100644 --- a/drivers/chibios/ws2812_spi.c +++ b/drivers/chibios/ws2812_spi.c | |||
| @@ -32,6 +32,37 @@ | |||
| 32 | # endif | 32 | # endif |
| 33 | #endif | 33 | #endif |
| 34 | 34 | ||
| 35 | // Define SPI config speed | ||
| 36 | // baudrate should target 3.2MHz | ||
| 37 | // F072 fpclk = 48MHz | ||
| 38 | // 48/16 = 3Mhz | ||
| 39 | #if WS2812_SPI_DIVISOR == 2 | ||
| 40 | # define WS2812_SPI_DIVISOR (0) | ||
| 41 | #elif WS2812_SPI_DIVISOR == 4 | ||
| 42 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_0) | ||
| 43 | #elif WS2812_SPI_DIVISOR == 8 | ||
| 44 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1) | ||
| 45 | #elif WS2812_SPI_DIVISOR == 16 // same as default | ||
| 46 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) | ||
| 47 | #elif WS2812_SPI_DIVISOR == 32 | ||
| 48 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_2) | ||
| 49 | #elif WS2812_SPI_DIVISOR == 64 | ||
| 50 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_0) | ||
| 51 | #elif WS2812_SPI_DIVISOR == 128 | ||
| 52 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1) | ||
| 53 | #elif WS2812_SPI_DIVISOR == 256 | ||
| 54 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) | ||
| 55 | #else | ||
| 56 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) // default | ||
| 57 | #endif | ||
| 58 | |||
| 59 | // Use SPI circular buffer | ||
| 60 | #ifdef WS2812_SPI_USE_CIRCULAR_BUFFER | ||
| 61 | # define WS2812_SPI_BUFFER_MODE 1 // circular buffer | ||
| 62 | #else | ||
| 63 | # define WS2812_SPI_BUFFER_MODE 0 // normal buffer | ||
| 64 | #endif | ||
| 65 | |||
| 35 | #define BYTES_FOR_LED_BYTE 4 | 66 | #define BYTES_FOR_LED_BYTE 4 |
| 36 | #define NB_COLORS 3 | 67 | #define NB_COLORS 3 |
| 37 | #define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS) | 68 | #define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS) |
| @@ -81,14 +112,14 @@ void ws2812_init(void) { | |||
| 81 | palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); | 112 | palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); |
| 82 | 113 | ||
| 83 | // TODO: more dynamic baudrate | 114 | // TODO: more dynamic baudrate |
| 84 | static const SPIConfig spicfg = { | 115 | static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR}; |
| 85 | 0, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), | ||
| 86 | SPI_CR1_BR_1 | SPI_CR1_BR_0 // baudrate : fpclk / 8 => 1tick is 0.32us (2.25 MHz) | ||
| 87 | }; | ||
| 88 | 116 | ||
| 89 | spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */ | 117 | spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */ |
| 90 | spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */ | 118 | spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */ |
| 91 | spiSelect(&WS2812_SPI); /* Slave Select assertion. */ | 119 | spiSelect(&WS2812_SPI); /* Slave Select assertion. */ |
| 120 | #ifdef WS2812_SPI_USE_CIRCULAR_BUFFER | ||
| 121 | spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf); | ||
| 122 | #endif | ||
| 92 | } | 123 | } |
| 93 | 124 | ||
| 94 | void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) { | 125 | void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) { |
| @@ -104,9 +135,11 @@ void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) { | |||
| 104 | 135 | ||
| 105 | // Send async - each led takes ~0.03ms, 50 leds ~1.5ms, animations flushing faster than send will cause issues. | 136 | // Send async - each led takes ~0.03ms, 50 leds ~1.5ms, animations flushing faster than send will cause issues. |
| 106 | // Instead spiSend can be used to send synchronously (or the thread logic can be added back). | 137 | // Instead spiSend can be used to send synchronously (or the thread logic can be added back). |
| 107 | #ifdef WS2812_SPI_SYNC | 138 | #ifndef WS2812_SPI_USE_CIRCULAR_BUFFER |
| 139 | # ifdef WS2812_SPI_SYNC | ||
| 108 | spiSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf); | 140 | spiSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf); |
| 109 | #else | 141 | # else |
| 110 | spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf); | 142 | spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf); |
| 143 | # endif | ||
| 111 | #endif | 144 | #endif |
| 112 | } | 145 | } |
diff --git a/drivers/issi/is31fl3733.c b/drivers/issi/is31fl3733.c index dddf0cb73..d99e5339c 100644 --- a/drivers/issi/is31fl3733.c +++ b/drivers/issi/is31fl3733.c | |||
| @@ -68,7 +68,7 @@ uint8_t g_twi_transfer_buffer[20]; | |||
| 68 | uint8_t g_pwm_buffer[DRIVER_COUNT][192]; | 68 | uint8_t g_pwm_buffer[DRIVER_COUNT][192]; |
| 69 | bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; | 69 | bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; |
| 70 | 70 | ||
| 71 | uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}}; | 71 | uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0}; |
| 72 | bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; | 72 | bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; |
| 73 | 73 | ||
| 74 | bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { | 74 | bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { |
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c index 92c64399e..082115d53 100644 --- a/drivers/oled/oled_driver.c +++ b/drivers/oled/oled_driver.c | |||
| @@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 24 | 24 | ||
| 25 | #include "progmem.h" | 25 | #include "progmem.h" |
| 26 | 26 | ||
| 27 | #include "keyboard.h" | ||
| 28 | |||
| 27 | // Used commands from spec sheet: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf | 29 | // Used commands from spec sheet: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf |
| 28 | // for SH1106: https://www.velleman.eu/downloads/29/infosheets/sh1106_datasheet.pdf | 30 | // for SH1106: https://www.velleman.eu/downloads/29/infosheets/sh1106_datasheet.pdf |
| 29 | 31 | ||
| @@ -71,6 +73,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 71 | #define PRE_CHARGE_PERIOD 0xD9 | 73 | #define PRE_CHARGE_PERIOD 0xD9 |
| 72 | #define VCOM_DETECT 0xDB | 74 | #define VCOM_DETECT 0xDB |
| 73 | 75 | ||
| 76 | // Advance Graphic Commands | ||
| 77 | #define FADE_BLINK 0x23 | ||
| 78 | #define ENABLE_FADE 0x20 | ||
| 79 | #define ENABLE_BLINK 0x30 | ||
| 80 | |||
| 74 | // Charge Pump Commands | 81 | // Charge Pump Commands |
| 75 | #define CHARGE_PUMP 0x8D | 82 | #define CHARGE_PUMP 0x8D |
| 76 | 83 | ||
| @@ -152,6 +159,12 @@ static void InvertCharacter(uint8_t *cursor) { | |||
| 152 | } | 159 | } |
| 153 | 160 | ||
| 154 | bool oled_init(uint8_t rotation) { | 161 | bool oled_init(uint8_t rotation) { |
| 162 | #if defined(USE_I2C) && defined(SPLIT_KEYBOARD) | ||
| 163 | if (!is_keyboard_master()) { | ||
| 164 | return true; | ||
| 165 | } | ||
| 166 | #endif | ||
| 167 | |||
| 155 | oled_rotation = oled_init_user(rotation); | 168 | oled_rotation = oled_init_user(rotation); |
| 156 | if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { | 169 | if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { |
| 157 | oled_rotation_width = OLED_DISPLAY_WIDTH; | 170 | oled_rotation_width = OLED_DISPLAY_WIDTH; |
| @@ -539,7 +552,13 @@ bool oled_on(void) { | |||
| 539 | oled_timeout = timer_read32() + OLED_TIMEOUT; | 552 | oled_timeout = timer_read32() + OLED_TIMEOUT; |
| 540 | #endif | 553 | #endif |
| 541 | 554 | ||
| 542 | static const uint8_t PROGMEM display_on[] = {I2C_CMD, DISPLAY_ON}; | 555 | static const uint8_t PROGMEM display_on[] = |
| 556 | #ifdef OLED_FADE_OUT | ||
| 557 | {I2C_CMD, FADE_BLINK, 0x00}; | ||
| 558 | #else | ||
| 559 | {I2C_CMD, DISPLAY_ON}; | ||
| 560 | #endif | ||
| 561 | |||
| 543 | if (!oled_active) { | 562 | if (!oled_active) { |
| 544 | if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) { | 563 | if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) { |
| 545 | print("oled_on cmd failed\n"); | 564 | print("oled_on cmd failed\n"); |
| @@ -555,7 +574,13 @@ bool oled_off(void) { | |||
| 555 | return !oled_active; | 574 | return !oled_active; |
| 556 | } | 575 | } |
| 557 | 576 | ||
| 558 | static const uint8_t PROGMEM display_off[] = {I2C_CMD, DISPLAY_OFF}; | 577 | static const uint8_t PROGMEM display_off[] = |
| 578 | #ifdef OLED_FADE_OUT | ||
| 579 | {I2C_CMD, FADE_BLINK, ENABLE_FADE | OLED_FADE_OUT_INTERVAL}; | ||
| 580 | #else | ||
| 581 | {I2C_CMD, DISPLAY_OFF}; | ||
| 582 | #endif | ||
| 583 | |||
| 559 | if (oled_active) { | 584 | if (oled_active) { |
| 560 | if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) { | 585 | if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) { |
| 561 | print("oled_off cmd failed\n"); | 586 | print("oled_off cmd failed\n"); |
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h index 72ab21247..cbf5380ee 100644 --- a/drivers/oled/oled_driver.h +++ b/drivers/oled/oled_driver.h | |||
| @@ -154,10 +154,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 154 | # endif | 154 | # endif |
| 155 | #endif | 155 | #endif |
| 156 | 156 | ||
| 157 | #if !defined(OLED_FADE_OUT_INTERVAL) | ||
| 158 | # define OLED_FADE_OUT_INTERVAL 0x00 | ||
| 159 | #endif | ||
| 160 | |||
| 161 | #if OLED_FADE_OUT_INTERVAL > 0x0F || OLED_FADE_OUT_INTERVAL < 0x00 | ||
| 162 | # error OLED_FADE_OUT_INTERVAL must be between 0x00 and 0x0F | ||
| 163 | #endif | ||
| 164 | |||
| 157 | #if !defined(OLED_I2C_TIMEOUT) | 165 | #if !defined(OLED_I2C_TIMEOUT) |
| 158 | # define OLED_I2C_TIMEOUT 100 | 166 | # define OLED_I2C_TIMEOUT 100 |
| 159 | #endif | 167 | #endif |
| 160 | 168 | ||
| 169 | #if !defined(OLED_UPDATE_INTERVAL) && defined(SPLIT_KEYBOARD) | ||
| 170 | # define OLED_UPDATE_INTERVAL 50 | ||
| 171 | #endif | ||
| 172 | |||
| 161 | typedef struct __attribute__((__packed__)) { | 173 | typedef struct __attribute__((__packed__)) { |
| 162 | uint8_t *current_element; | 174 | uint8_t *current_element; |
| 163 | uint16_t remaining_element_count; | 175 | uint16_t remaining_element_count; |
