From 18a333ec6bc9051ae7ec63a809d725c5c5f77046 Mon Sep 17 00:00:00 2001
From: Sergey Vlasov
Date: Wed, 3 Mar 2021 07:26:06 +0300
Subject: Add support for complementary outputs to the WS2812 PWM driver
(#11988)
---
drivers/chibios/ws2812_pwm.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'drivers')
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c
index 140120d488..e6af55b6b3 100644
--- a/drivers/chibios/ws2812_pwm.c
+++ b/drivers/chibios/ws2812_pwm.c
@@ -27,6 +27,15 @@
# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP"
#endif
+#ifndef WS2812_PWM_COMPLEMENTARY_OUTPUT
+# define WS2812_PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH
+#else
+# if !STM32_PWM_USE_ADVANCED
+# error "WS2812_PWM_COMPLEMENTARY_OUTPUT requires STM32_PWM_USE_ADVANCED == TRUE"
+# endif
+# define WS2812_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
+#endif
+
// Push Pull or Open Drain Configuration
// Default Push Pull
#ifndef WS2812_EXTERNAL_PULLUP
@@ -247,7 +256,7 @@ void ws2812_init(void) {
.channels =
{
[0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled
- [WS2812_PWM_CHANNEL - 1] = {.mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // Turn on the channel we care about
+ [WS2812_PWM_CHANNEL - 1] = {.mode = WS2812_PWM_OUTPUT_MODE, .callback = NULL}, // Turn on the channel we care about
},
.cr2 = 0,
.dier = TIM_DIER_UDE, // DMA on update event for next period
--
cgit v1.2.3
From b7f2f40ae5bf9ad148e2de58757a14813f37a779 Mon Sep 17 00:00:00 2001
From: Drashna Jaelre
Date: Fri, 5 Mar 2021 16:26:57 -0800
Subject: Set default OLED Update Interval for Split Keyboards (#12107)
Because the matrix scanning is slower for splits, in general,
the frequent updating of the OLEDs can slow down the matrix scanning.
To help prevent that, set the update interval for the OLEDs to not
update as frequently.---
drivers/oled/oled_driver.h | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'drivers')
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h
index 72ab21247d..00896f01c2 100644
--- a/drivers/oled/oled_driver.h
+++ b/drivers/oled/oled_driver.h
@@ -158,6 +158,10 @@ along with this program. If not, see .
# define OLED_I2C_TIMEOUT 100
#endif
+#if !defined(OLED_UPDATE_INTERVAL) && defined(SPLIT_KEYBOARD)
+# define OLED_UPDATE_INTERVAL 50
+#endif
+
typedef struct __attribute__((__packed__)) {
uint8_t *current_element;
uint16_t remaining_element_count;
--
cgit v1.2.3
From 6f7466b6dd72e161b61683e26b7720421d8cc9bd Mon Sep 17 00:00:00 2001
From: Xelus22
Date: Fri, 19 Mar 2021 08:29:18 +0000
Subject: ARM WS2812 SPI config (baudrate and circular buffer) (#12216)
* initial commit
* include circular buffer command
* add endif
* circular buffer mode
* remove untrue comment
* revamp and add documentation
* do not allow WS2812_SPI_SYNC & CIRCULAR_BUFFER---
docs/ws2812_driver.md | 19 +++++++++++++++++++
drivers/chibios/ws2812_spi.c | 44 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 59 insertions(+), 4 deletions(-)
(limited to 'drivers')
diff --git a/docs/ws2812_driver.md b/docs/ws2812_driver.md
index fa14f02fdb..e69400364c 100644
--- a/docs/ws2812_driver.md
+++ b/docs/ws2812_driver.md
@@ -77,6 +77,25 @@ Configure the hardware via your config.h:
You must also turn on the SPI feature in your halconf.h and mcuconf.h
+#### Circular Buffer Mode
+Some boards may flicker while in the normal buffer mode. To fix this issue, circular buffer mode may be used to rectify the issue.
+
+By default, the circular buffer mode is disabled.
+
+To enable this alternative buffer mode, place this into your `config.h` file:
+```c
+#define WS2812_SPI_USE_CIRCULAR_BUFFER
+```
+
+#### Setting baudrate with divisor
+To adjust the baudrate at which the SPI peripheral is configured, users will need to derive the target baudrate from the clock tree provided by STM32CubeMX.
+
+Only divisors of 2, 4, 8, 16, 32, 64, 128 and 256 are supported by hardware.
+
+|Define |Default|Description |
+|--------------------|-------|-------------------------------------|
+|`WS2812_SPI_DIVISOR`|`16` |SPI source clock peripheral divisor |
+
#### Testing Notes
While not an exhaustive list, the following table provides the scenarios that have been partially validated:
diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c
index 89df2987b5..bc0a54acce 100644
--- a/drivers/chibios/ws2812_spi.c
+++ b/drivers/chibios/ws2812_spi.c
@@ -32,6 +32,37 @@
# endif
#endif
+// Define SPI config speed
+// baudrate should target 3.2MHz
+// F072 fpclk = 48MHz
+// 48/16 = 3Mhz
+#if WS2812_SPI_DIVISOR == 2
+# define WS2812_SPI_DIVISOR (0)
+#elif WS2812_SPI_DIVISOR == 4
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_0)
+#elif WS2812_SPI_DIVISOR == 8
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1)
+#elif WS2812_SPI_DIVISOR == 16 //same as default
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0)
+#elif WS2812_SPI_DIVISOR == 32
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2)
+#elif WS2812_SPI_DIVISOR == 64
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_0)
+#elif WS2812_SPI_DIVISOR == 128
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1)
+#elif WS2812_SPI_DIVISOR == 256
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0)
+#else
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) //default
+#endif
+
+// Use SPI circular buffer
+#ifdef WS2812_SPI_USE_CIRCULAR_BUFFER
+# define WS2812_SPI_BUFFER_MODE 1 //circular buffer
+#else
+# define WS2812_SPI_BUFFER_MODE 0 //normal buffer
+#endif
+
#define BYTES_FOR_LED_BYTE 4
#define NB_COLORS 3
#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS)
@@ -82,13 +113,16 @@ void ws2812_init(void) {
// TODO: more dynamic baudrate
static const SPIConfig spicfg = {
- 0, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN),
- SPI_CR1_BR_1 | SPI_CR1_BR_0 // baudrate : fpclk / 8 => 1tick is 0.32us (2.25 MHz)
+ WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN),
+ WS2812_SPI_DIVISOR
};
spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */
spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */
spiSelect(&WS2812_SPI); /* Slave Select assertion. */
+#ifdef WS2812_SPI_USE_CIRCULAR_BUFFER
+ spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
+#endif
}
void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
@@ -104,9 +138,11 @@ void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
// Send async - each led takes ~0.03ms, 50 leds ~1.5ms, animations flushing faster than send will cause issues.
// Instead spiSend can be used to send synchronously (or the thread logic can be added back).
-#ifdef WS2812_SPI_SYNC
+#ifndef WS2812_SPI_USE_CIRCULAR_BUFFER
+# ifdef WS2812_SPI_SYNC
spiSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
-#else
+# else
spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
+# endif
#endif
}
--
cgit v1.2.3
From 32f0567ca5e0d7db78ce316df6b5a18546c525b7 Mon Sep 17 00:00:00 2001
From: github-actions[bot]
Date: Fri, 19 Mar 2021 16:24:36 +0000
Subject: Format code according to conventions (#12292)
Co-authored-by: QMK Bot ---
drivers/chibios/ws2812_spi.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
(limited to 'drivers')
diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c
index bc0a54acce..e02cbabc02 100644
--- a/drivers/chibios/ws2812_spi.c
+++ b/drivers/chibios/ws2812_spi.c
@@ -34,7 +34,7 @@
// Define SPI config speed
// baudrate should target 3.2MHz
-// F072 fpclk = 48MHz
+// F072 fpclk = 48MHz
// 48/16 = 3Mhz
#if WS2812_SPI_DIVISOR == 2
# define WS2812_SPI_DIVISOR (0)
@@ -42,7 +42,7 @@
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_0)
#elif WS2812_SPI_DIVISOR == 8
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1)
-#elif WS2812_SPI_DIVISOR == 16 //same as default
+#elif WS2812_SPI_DIVISOR == 16 // same as default
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0)
#elif WS2812_SPI_DIVISOR == 32
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2)
@@ -53,14 +53,14 @@
#elif WS2812_SPI_DIVISOR == 256
# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0)
#else
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) //default
+# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) // default
#endif
// Use SPI circular buffer
#ifdef WS2812_SPI_USE_CIRCULAR_BUFFER
-# define WS2812_SPI_BUFFER_MODE 1 //circular buffer
+# define WS2812_SPI_BUFFER_MODE 1 // circular buffer
#else
-# define WS2812_SPI_BUFFER_MODE 0 //normal buffer
+# define WS2812_SPI_BUFFER_MODE 0 // normal buffer
#endif
#define BYTES_FOR_LED_BYTE 4
@@ -112,10 +112,7 @@ void ws2812_init(void) {
palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE);
// TODO: more dynamic baudrate
- static const SPIConfig spicfg = {
- WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN),
- WS2812_SPI_DIVISOR
- };
+ static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR};
spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */
spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */
--
cgit v1.2.3
From b05565f368cf0a2901913bd1b279625d6d3866ca Mon Sep 17 00:00:00 2001
From: Oleg Senchenko
Date: Thu, 25 Mar 2021 15:42:25 +0300
Subject: Fix connection issue in split keyboards when slave and OLED display
are connected via I2C, fix #9335 (#11487)
* In split keyboards fix connection issue when slave and OLED are connected via I2C. Fix #9335
* Revert "In split keyboards fix connection issue when slave and OLED are connected via I2C. Fix #9335"
This reverts commit 3ee639e1f35fb0fe257fc3ba1095124e039af7d7.
* In split keyboards fix connection issue when slave and OLED are connected via I2C. Fix #9335
* Update drivers/oled/oled_driver.c
Co-authored-by: Drashna Jaelre
Co-authored-by: osenchenko
Co-authored-by: Drashna Jaelre ---
drivers/oled/oled_driver.c | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'drivers')
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index 92c64399e2..a60f2de6d1 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -24,6 +24,8 @@ along with this program. If not, see .
#include "progmem.h"
+#include "keyboard.h"
+
// Used commands from spec sheet: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
// for SH1106: https://www.velleman.eu/downloads/29/infosheets/sh1106_datasheet.pdf
@@ -152,6 +154,10 @@ static void InvertCharacter(uint8_t *cursor) {
}
bool oled_init(uint8_t rotation) {
+#if defined(USE_I2C) && defined(SPLIT_KEYBOARD)
+ if (!is_keyboard_master()) { return true; }
+#endif
+
oled_rotation = oled_init_user(rotation);
if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
oled_rotation_width = OLED_DISPLAY_WIDTH;
--
cgit v1.2.3
From 67252c246c0298ad253d04281e19add65e34d72b Mon Sep 17 00:00:00 2001
From: github-actions[bot]
Date: Thu, 25 Mar 2021 23:44:37 +1100
Subject: Format code according to conventions (#12381)
Co-authored-by: QMK Bot ---
drivers/oled/oled_driver.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'drivers')
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index a60f2de6d1..6c1238cd6f 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -155,7 +155,9 @@ static void InvertCharacter(uint8_t *cursor) {
bool oled_init(uint8_t rotation) {
#if defined(USE_I2C) && defined(SPLIT_KEYBOARD)
- if (!is_keyboard_master()) { return true; }
+ if (!is_keyboard_master()) {
+ return true;
+ }
#endif
oled_rotation = oled_init_user(rotation);
--
cgit v1.2.3
From 65c97527624d4865d3867371722742c477f71268 Mon Sep 17 00:00:00 2001
From: Sergey Vlasov
Date: Sun, 25 Apr 2021 04:15:37 +0300
Subject: Update ADC driver for STM32F1xx, STM32F3xx, STM32F4xx (#12403)
* Fix default ADC_RESOLUTION for ADCv3 (and ADCv4)
Recent ChibiOS update removed ADC_CFGR1_RES_10BIT from the ADCv3 headers
(that macro should not have been there, because ADCv3 has CFGR instead of
CFGR1). Fix the default value for ADC_RESOLUTION to use ADC_CFGR_RES_10BITS
if it is defined (that name is used for ADCv3 and ADCv4).
* Update ADC docs to match the actually used resolution
ADC driver for ChibiOS actually uses the 10-bit resolution by default
(probably to match AVR); fix the documentation accordingly. Also add
both ADC_CFGR_RES_10BITS and ADC_CFGR1_RES_10BIT constants (these names
differ according to the ADC implementation in the particular MCU).
* Fix pinToMux() for B12 and B13 on STM32F3xx
Testing on STM32F303CCT6 revealed that the ADC mux values for B12 and
B13 pins were wrong.
* Add support for all possible analog pins on STM32F1xx
Added ADC mux values for pins A0...A7, B0, B1, C0...C5 on STM32F1xx
(they are the same at least for STM32F103x8 and larger F103 devices, and
also F102, F105, F107 families). Actually tested on STM32F103C8T6
(therefore pins C0...C5 were not tested).
Pins F6...F10, which are present on STM32F103x[C-G] in 144-pin packages,
cannot be supported at the moment, because those pins are connected only
to ADC3, but the ChibiOS ADC driver for STM32F1xx supports only ADC1.
* Add support for all possible analog pins on STM32F4xx
Added ADC mux values for pins A0...A7, B0, B1, C0...C5 and optionally
F3...F10 (if STM32_ADC_USE_ADC3 is enabled). These mux values are
apparently the same for all F4xx devices, except some smaller devices may
not have ADC3.
Actually tested on STM32F401CCU6, STM32F401CEU6, STM32F411CEU6 (using
various WeAct “Blackpill” boards); only pins A0...A7, B0, B1 were tested.
Pins F3...F10 are inside `#if STM32_ADC_USE_ADC3` because some devices
which don't have ADC3 also don't have the GPIOF port, therefore the code
which refers to Fx pins does not compile.
* Fix STM32F3xx ADC mux table in documentation
The ADC driver documentation had some errors in the mux table for STM32F3xx.
Fix this table to match the datasheet and the actual code (mux settings for
B12 and B13 were also tested on a real STM32F303CCT6 chip).
* Add STM32F1xx ADC pins to the documentation
* Add STM32F4xx ADC pins to the documentation---
docs/adc_driver.md | 154 ++++++++++++++++++++++++-----------------------
drivers/chibios/analog.c | 57 ++++++++++++++++--
2 files changed, 131 insertions(+), 80 deletions(-)
(limited to 'drivers')
diff --git a/docs/adc_driver.md b/docs/adc_driver.md
index 6e3d513863..69fff4b3c2 100644
--- a/docs/adc_driver.md
+++ b/docs/adc_driver.md
@@ -47,73 +47,79 @@ Note that some of these pins are doubled-up on ADCs with the same channel. This
Also note that the F0 and F3 use different numbering schemes. The F0 has a single ADC and the channels are 0-indexed, whereas the F3 has 4 ADCs and the channels are 1-indexed. This is because the F0 uses the `ADCv1` implementation of the ADC, whereas the F3 uses the `ADCv3` implementation.
-|ADC|Channel|STM32F0xx|STM32F3xx|
-|---|-------|---------|---------|
-|1 |0 |`A0` | |
-|1 |1 |`A1` |`A0` |
-|1 |2 |`A2` |`A1` |
-|1 |3 |`A3` |`A2` |
-|1 |4 |`A4` |`A3` |
-|1 |5 |`A5` |`F4` |
-|1 |6 |`A6` |`C0` |
-|1 |7 |`A7` |`C1` |
-|1 |8 |`B0` |`C2` |
-|1 |9 |`B1` |`C3` |
-|1 |10 |`C0` |`F2` |
-|1 |11 |`C1` | |
-|1 |12 |`C2` | |
-|1 |13 |`C3` | |
-|1 |14 |`C4` | |
-|1 |15 |`C5` | |
-|1 |16 | | |
-|2 |1 | |`A4` |
-|2 |2 | |`A5` |
-|2 |3 | |`A6` |
-|2 |4 | |`A7` |
-|2 |5 | |`C4` |
-|2 |6 | |`C0` |
-|2 |7 | |`C1` |
-|2 |8 | |`C2` |
-|2 |9 | |`C3` |
-|2 |10 | |`F2` |
-|2 |11 | |`C5` |
-|2 |12 | |`B2` |
-|2 |13 | | |
-|2 |14 | | |
-|2 |15 | | |
-|2 |16 | | |
-|3 |1 | |`B1` |
-|3 |2 | |`E9` |
-|3 |3 | |`E13` |
-|3 |4 | | |
-|3 |5 | | |
-|3 |6 | |`E8` |
-|3 |7 | |`D10` |
-|3 |8 | |`D11` |
-|3 |9 | |`D12` |
-|3 |10 | |`D13` |
-|3 |11 | |`D14` |
-|3 |12 | |`B0` |
-|3 |13 | |`E7` |
-|3 |14 | |`E10` |
-|3 |15 | |`E11` |
-|3 |16 | |`E12` |
-|4 |1 | |`E14` |
-|4 |2 | |`B12` |
-|4 |3 | |`B13` |
-|4 |4 | |`B14` |
-|4 |5 | |`B15` |
-|4 |6 | |`E8` |
-|4 |7 | |`D10` |
-|4 |8 | |`D11` |
-|4 |9 | |`D12` |
-|4 |10 | |`D13` |
-|4 |11 | |`D14` |
-|4 |12 | |`D8` |
-|4 |13 | |`D9` |
-|4 |14 | | |
-|4 |15 | | |
-|4 |16 | | |
+|ADC|Channel|STM32F0xx|STM32F1xx|STM32F3xx|STM32F4xx|
+|---|-------|---------|---------|---------|---------|
+|1 |0 |`A0` |`A0` | |`A0` |
+|1 |1 |`A1` |`A1` |`A0` |`A1` |
+|1 |2 |`A2` |`A2` |`A1` |`A2` |
+|1 |3 |`A3` |`A3` |`A2` |`A3` |
+|1 |4 |`A4` |`A4` |`A3` |`A4` |
+|1 |5 |`A5` |`A5` |`F4` |`A5` |
+|1 |6 |`A6` |`A6` |`C0` |`A6` |
+|1 |7 |`A7` |`A7` |`C1` |`A7` |
+|1 |8 |`B0` |`B0` |`C2` |`B0` |
+|1 |9 |`B1` |`B1` |`C3` |`B1` |
+|1 |10 |`C0` |`C0` |`F2` |`C0` |
+|1 |11 |`C1` |`C1` | |`C1` |
+|1 |12 |`C2` |`C2` | |`C2` |
+|1 |13 |`C3` |`C3` | |`C3` |
+|1 |14 |`C4` |`C4` | |`C4` |
+|1 |15 |`C5` |`C5` | |`C5` |
+|1 |16 | | | | |
+|2 |0 | |`A0`¹ | |`A0`² |
+|2 |1 | |`A1`¹ |`A4` |`A1`² |
+|2 |2 | |`A2`¹ |`A5` |`A2`² |
+|2 |3 | |`A3`¹ |`A6` |`A3`² |
+|2 |4 | |`A4`¹ |`A7` |`A4`² |
+|2 |5 | |`A5`¹ |`C4` |`A5`² |
+|2 |6 | |`A6`¹ |`C0` |`A6`² |
+|2 |7 | |`A7`¹ |`C1` |`A7`² |
+|2 |8 | |`B0`¹ |`C2` |`B0`² |
+|2 |9 | |`B1`¹ |`C3` |`B1`² |
+|2 |10 | |`C0`¹ |`F2` |`C0`² |
+|2 |11 | |`C1`¹ |`C5` |`C1`² |
+|2 |12 | |`C2`¹ |`B2` |`C2`² |
+|2 |13 | |`C3`¹ | |`C3`² |
+|2 |14 | |`C4`¹ | |`C4`² |
+|2 |15 | |`C5`¹ | |`C5`² |
+|2 |16 | | | | |
+|3 |0 | |`A0`¹ | |`A0`² |
+|3 |1 | |`A1`¹ |`B1` |`A1`² |
+|3 |2 | |`A2`¹ |`E9` |`A2`² |
+|3 |3 | |`A3`¹ |`E13` |`A3`² |
+|3 |4 | |`F6`¹ | |`F6`² |
+|3 |5 | |`F7`¹ |`B13` |`F7`² |
+|3 |6 | |`F8`¹ |`E8` |`F8`² |
+|3 |7 | |`F9`¹ |`D10` |`F9`² |
+|3 |8 | |`F10`¹ |`D11` |`F10`² |
+|3 |9 | | |`D12` |`F3`² |
+|3 |10 | |`C0`¹ |`D13` |`C0`² |
+|3 |11 | |`C1`¹ |`D14` |`C1`² |
+|3 |12 | |`C2`¹ |`B0` |`C2`² |
+|3 |13 | |`C3`¹ |`E7` |`C3`² |
+|3 |14 | | |`E10` |`F4`² |
+|3 |15 | | |`E11` |`F5`² |
+|3 |16 | | |`E12` | |
+|4 |1 | | |`E14` | |
+|4 |2 | | |`E15` | |
+|4 |3 | | |`B12` | |
+|4 |4 | | |`B14` | |
+|4 |5 | | |`B15` | |
+|4 |6 | | |`E8` | |
+|4 |7 | | |`D10` | |
+|4 |8 | | |`D11` | |
+|4 |9 | | |`D12` | |
+|4 |10 | | |`D13` | |
+|4 |11 | | |`D14` | |
+|4 |12 | | |`D8` | |
+|4 |13 | | |`D9` | |
+|4 |14 | | | | |
+|4 |15 | | | | |
+|4 |16 | | | | |
+
+¹ As of ChibiOS 20.3.4, the ADC driver for STM32F1xx devices supports only ADC1, therefore any configurations involving ADC2 or ADC3 cannot actually be used. In particular, pins `F6`…`F10`, which are present at least on some STM32F103x[C-G] devices, cannot be used as ADC inputs because of this driver limitation.
+
+² Not all STM32F4xx devices have ADC2 and/or ADC3, therefore some configurations shown in this table may be unavailable; in particular, pins `F4`…`F10` cannot be used as ADC inputs on devices which do not have ADC3. Check the device datasheet to confirm which pin functions are supported.
## Functions
@@ -141,10 +147,10 @@ Also note that the F0 and F3 use different numbering schemes. The F0 has a singl
The ARM implementation of the ADC has a few additional options that you can override in your own keyboards and keymaps to change how it operates. Please consult the corresponding `hal_adc_lld.h` in ChibiOS for your specific microcontroller for further documentation on your available options.
-|`#define` |Type |Default |Description |
-|---------------------|------|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-|`ADC_CIRCULAR_BUFFER`|`bool`|`false` |If `true`, then the implementation will use a circular buffer. |
-|`ADC_NUM_CHANNELS` |`int` |`1` |Sets the number of channels that will be scanned as part of an ADC operation. The current implementation only supports `1`. |
-|`ADC_BUFFER_DEPTH` |`int` |`2` |Sets the depth of each result. Since we are only getting a 12-bit result by default, we set this to 2 bytes so we can contain our one value. This could be set to 1 if you opt for an 8-bit or lower result.|
-|`ADC_SAMPLING_RATE` |`int` |`ADC_SMPR_SMP_1P5` |Sets the sampling rate of the ADC. By default, it is set to the fastest setting. |
-|`ADC_RESOLUTION` |`int` |`ADC_CFGR1_RES_12BIT`|The resolution of your result. We choose 12 bit by default, but you can opt for 12, 10, 8, or 6 bit. |
+|`#define` |Type |Default |Description |
+|---------------------|------|----------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+|`ADC_CIRCULAR_BUFFER`|`bool`|`false` |If `true`, then the implementation will use a circular buffer. |
+|`ADC_NUM_CHANNELS` |`int` |`1` |Sets the number of channels that will be scanned as part of an ADC operation. The current implementation only supports `1`. |
+|`ADC_BUFFER_DEPTH` |`int` |`2` |Sets the depth of each result. Since we are only getting a 10-bit result by default, we set this to 2 bytes so we can contain our one value. This could be set to 1 if you opt for an 8-bit or lower result.|
+|`ADC_SAMPLING_RATE` |`int` |`ADC_SMPR_SMP_1P5` |Sets the sampling rate of the ADC. By default, it is set to the fastest setting. |
+|`ADC_RESOLUTION` |`int` |`ADC_CFGR1_RES_10BIT` or `ADC_CFGR_RES_10BITS`|The resolution of your result. We choose 10 bit by default, but you can opt for 12, 10, 8, or 6 bit. Different MCUs use slightly different names for the resolution constants. |
diff --git a/drivers/chibios/analog.c b/drivers/chibios/analog.c
index 2b3872afbb..b1081623d3 100644
--- a/drivers/chibios/analog.c
+++ b/drivers/chibios/analog.c
@@ -101,7 +101,11 @@
// Options are 12, 10, 8, and 6 bit.
#ifndef ADC_RESOLUTION
-# define ADC_RESOLUTION ADC_CFGR1_RES_10BIT
+# ifdef ADC_CFGR_RES_10BITS // ADCv3, ADCv4
+# define ADC_RESOLUTION ADC_CFGR_RES_10BITS
+# else // ADCv1, ADCv5, or the bodge for ADCv2 above
+# define ADC_RESOLUTION ADC_CFGR1_RES_10BIT
+# endif
#endif
static ADCConfig adcCfg = {};
@@ -161,8 +165,8 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) {
case B0: return TO_MUX( ADC_CHANNEL_IN12, 2 );
case B1: return TO_MUX( ADC_CHANNEL_IN1, 2 );
case B2: return TO_MUX( ADC_CHANNEL_IN12, 1 );
- case B12: return TO_MUX( ADC_CHANNEL_IN2, 3 );
- case B13: return TO_MUX( ADC_CHANNEL_IN3, 3 );
+ case B12: return TO_MUX( ADC_CHANNEL_IN3, 3 );
+ case B13: return TO_MUX( ADC_CHANNEL_IN5, 2 );
case B14: return TO_MUX( ADC_CHANNEL_IN4, 3 );
case B15: return TO_MUX( ADC_CHANNEL_IN5, 3 );
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) {
case E15: return TO_MUX( ADC_CHANNEL_IN2, 3 );
case F2: return TO_MUX( ADC_CHANNEL_IN10, 0 ); // Can also be ADC2
case F4: return TO_MUX( ADC_CHANNEL_IN5, 0 );
-#elif defined(STM32F4XX) // TODO: add all pins
+#elif defined(STM32F4XX)
case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
- //case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
-#elif defined(STM32F1XX) // TODO: add all pins
+ case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
+ case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
+ case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 );
+ case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 );
+ case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 );
+ case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 );
+ case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 );
+ case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 );
+ case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 );
+ case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 );
+ case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 );
+ case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 );
+ case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 );
+ case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 );
+ case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 );
+# if STM32_ADC_USE_ADC3
+ case F3: return TO_MUX( ADC_CHANNEL_IN9, 2 );
+ case F4: return TO_MUX( ADC_CHANNEL_IN14, 2 );
+ case F5: return TO_MUX( ADC_CHANNEL_IN15, 2 );
+ case F6: return TO_MUX( ADC_CHANNEL_IN4, 2 );
+ case F7: return TO_MUX( ADC_CHANNEL_IN5, 2 );
+ case F8: return TO_MUX( ADC_CHANNEL_IN6, 2 );
+ case F9: return TO_MUX( ADC_CHANNEL_IN7, 2 );
+ case F10: return TO_MUX( ADC_CHANNEL_IN8, 2 );
+# endif
+#elif defined(STM32F1XX)
case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
+ case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
+ case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
+ case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 );
+ case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 );
+ case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 );
+ case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 );
+ case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 );
+ case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 );
+ case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 );
+ case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 );
+ case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 );
+ case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 );
+ case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 );
+ case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 );
+ case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 );
+ // STM32F103x[C-G] in 144-pin packages also have analog inputs on F6...F10, but they are on ADC3, and the
+ // ChibiOS ADC driver for STM32F1xx currently supports only ADC1, therefore these pins are not usable.
#endif
}
--
cgit v1.2.3
From fca7cc1747642d077898e301945df86bfdea0784 Mon Sep 17 00:00:00 2001
From: Barabas
Date: Sat, 8 May 2021 11:27:13 +0100
Subject: Added OLED fade out support (#12086)
---
docs/feature_oled_driver.md | 2 ++
drivers/oled/oled_driver.c | 21 +++++++++++++++++++--
drivers/oled/oled_driver.h | 8 ++++++++
3 files changed, 29 insertions(+), 2 deletions(-)
(limited to 'drivers')
diff --git a/docs/feature_oled_driver.md b/docs/feature_oled_driver.md
index 44202487f1..d2dc6103a6 100644
--- a/docs/feature_oled_driver.md
+++ b/docs/feature_oled_driver.md
@@ -145,6 +145,8 @@ void oled_task_user(void) {
|`OLED_FONT_WIDTH` |`6` |The font width |
|`OLED_FONT_HEIGHT` |`8` |The font height (untested) |
|`OLED_TIMEOUT` |`60000` |Turns off the OLED screen after 60000ms of keyboard inactivity. Helps reduce OLED Burn-in. Set to 0 to disable. |
+|`OLED_FADE_OUT` |*Not defined* |Enables fade out animation. Use together with `OLED_TIMEOUT`. |
+|`OLED_FADE_OUT_INTERVAL` |`0` |The speed of fade out animation, from 0 to 15. Larger values are slower. |
|`OLED_SCROLL_TIMEOUT` |`0` |Scrolls the OLED screen after 0ms of OLED inactivity. Helps reduce OLED Burn-in. Set to 0 to disable. |
|`OLED_SCROLL_TIMEOUT_RIGHT`|*Not defined* |Scroll timeout direction is right when defined, left when undefined. |
|`OLED_IC` |`OLED_IC_SSD1306`|Set to `OLED_IC_SH1106` if you're using the SH1106 OLED controller. |
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index 6c1238cd6f..082115d534 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -73,6 +73,11 @@ along with this program. If not, see .
#define PRE_CHARGE_PERIOD 0xD9
#define VCOM_DETECT 0xDB
+// Advance Graphic Commands
+#define FADE_BLINK 0x23
+#define ENABLE_FADE 0x20
+#define ENABLE_BLINK 0x30
+
// Charge Pump Commands
#define CHARGE_PUMP 0x8D
@@ -547,7 +552,13 @@ bool oled_on(void) {
oled_timeout = timer_read32() + OLED_TIMEOUT;
#endif
- static const uint8_t PROGMEM display_on[] = {I2C_CMD, DISPLAY_ON};
+ static const uint8_t PROGMEM display_on[] =
+#ifdef OLED_FADE_OUT
+ {I2C_CMD, FADE_BLINK, 0x00};
+#else
+ {I2C_CMD, DISPLAY_ON};
+#endif
+
if (!oled_active) {
if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) {
print("oled_on cmd failed\n");
@@ -563,7 +574,13 @@ bool oled_off(void) {
return !oled_active;
}
- static const uint8_t PROGMEM display_off[] = {I2C_CMD, DISPLAY_OFF};
+ static const uint8_t PROGMEM display_off[] =
+#ifdef OLED_FADE_OUT
+ {I2C_CMD, FADE_BLINK, ENABLE_FADE | OLED_FADE_OUT_INTERVAL};
+#else
+ {I2C_CMD, DISPLAY_OFF};
+#endif
+
if (oled_active) {
if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) {
print("oled_off cmd failed\n");
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h
index 00896f01c2..cbf5380ee0 100644
--- a/drivers/oled/oled_driver.h
+++ b/drivers/oled/oled_driver.h
@@ -154,6 +154,14 @@ along with this program. If not, see .
# endif
#endif
+#if !defined(OLED_FADE_OUT_INTERVAL)
+# define OLED_FADE_OUT_INTERVAL 0x00
+#endif
+
+#if OLED_FADE_OUT_INTERVAL > 0x0F || OLED_FADE_OUT_INTERVAL < 0x00
+# error OLED_FADE_OUT_INTERVAL must be between 0x00 and 0x0F
+#endif
+
#if !defined(OLED_I2C_TIMEOUT)
# define OLED_I2C_TIMEOUT 100
#endif
--
cgit v1.2.3
From 8e96c5a060896c4aa5ed181d9c86c4e66bb78cfc Mon Sep 17 00:00:00 2001
From: Donald Kjer
Date: Fri, 21 May 2021 21:42:39 -0700
Subject: Add support for up to 4 IS31FL3733 drivers (#12342)
Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com>---
docs/feature_led_matrix.md | 31 +++++++++-----
docs/feature_rgb_matrix.md | 96 +++++++++++++++++++++++++++++++++++++++-----
drivers/issi/is31fl3733.c | 2 +-
quantum/led_matrix_drivers.c | 22 +++++++---
quantum/rgb_matrix_drivers.c | 45 +++++++++++++++++++--
5 files changed, 167 insertions(+), 29 deletions(-)
(limited to 'drivers')
diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md
index 7834b940d5..e56caabfe7 100644
--- a/docs/feature_led_matrix.md
+++ b/docs/feature_led_matrix.md
@@ -15,7 +15,20 @@ LED_MATRIX_ENABLE = yes
LED_MATRIX_DRIVER = IS31FL3731
```
-Configure the hardware via your `config.h`:
+You can use between 1 and 4 IS31FL3731 IC's. Do not specify `LED_DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
+
+| Variable | Description | Default |
+|----------|-------------|---------|
+| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 |
+| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
+| `LED_DRIVER_COUNT` | (Required) How many LED driver IC's are present | |
+| `DRIVER_LED_TOTAL` | (Required) How many LED lights are present across all drivers | |
+| `LED_DRIVER_ADDR_1` | (Required) Address for the first LED driver | |
+| `LED_DRIVER_ADDR_2` | (Optional) Address for the second LED driver | |
+| `LED_DRIVER_ADDR_3` | (Optional) Address for the third LED driver | |
+| `LED_DRIVER_ADDR_4` | (Optional) Address for the fourth LED driver | |
+
+Here is an example using 2 drivers.
```c
// This is a 7-bit address, that gets left-shifted and bit 0
@@ -25,18 +38,16 @@ Configure the hardware via your `config.h`:
// 0b1110111 AD <-> VCC
// 0b1110101 AD <-> SCL
// 0b1110110 AD <-> SDA
-#define DRIVER_ADDR_1 0b1110100
-#define DRIVER_ADDR_2 0b1110110
+#define LED_DRIVER_ADDR_1 0b1110100
+#define LED_DRIVER_ADDR_2 0b1110110
-#define DRIVER_COUNT 2
-#define DRIVER_1_LED_TOTAL 25
-#define DRIVER_2_LED_TOTAL 24
-#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
+#define LED_DRIVER_COUNT 2
+#define LED_DRIVER_1_LED_TOTAL 25
+#define LED_DRIVER_2_LED_TOTAL 24
+#define DRIVER_LED_TOTAL (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL)
```
-!> Note the parentheses, this is so when `DRIVER_LED_TOTAL` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`.
-
-Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations.
+!> Note the parentheses, this is so when `LED_DRIVER_LED_TOTAL` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL)` will give very different results than `rand() % LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL`.
Define these arrays listing all the LEDs in your `.c`:
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index ffbb8c0b60..a29d5c624b 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -15,7 +15,20 @@ RGB_MATRIX_ENABLE = yes
RGB_MATRIX_DRIVER = IS31FL3731
```
-Configure the hardware via your `config.h`:
+You can use between 1 and 4 IS31FL3731 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
+
+| Variable | Description | Default |
+|----------|-------------|---------|
+| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 |
+| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
+| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | |
+| `DRIVER_LED_TOTAL` | (Required) How many RGB lights are present across all drivers | |
+| `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | |
+| `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | |
+| `DRIVER_ADDR_3` | (Optional) Address for the third RGB driver | |
+| `DRIVER_ADDR_4` | (Optional) Address for the fourth RGB driver | |
+
+Here is an example using 2 drivers.
```c
// This is a 7-bit address, that gets left-shifted and bit 0
@@ -36,8 +49,6 @@ Configure the hardware via your `config.h`:
!> Note the parentheses, this is so when `DRIVER_LED_TOTAL` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`.
-Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations.
-
Define these arrays listing all the LEDs in your `.c`:
```c
@@ -53,12 +64,10 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
}
```
-Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0` or `1` right now).
+Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3`).
---
-### IS31FL3733/IS31FL3737 :id=is31fl3733is31fl3737
-
-!> For the IS31FL3737, replace all instances of `IS31FL3733` below with `IS31FL3737`.
+### IS31FL3733 :id=is31fl3733
There is basic support for addressable RGB matrix lighting with the I2C IS31FL3733 RGB controller. To enable it, add this to your `rules.mk`:
@@ -67,7 +76,24 @@ RGB_MATRIX_ENABLE = yes
RGB_MATRIX_DRIVER = IS31FL3733
```
-Configure the hardware via your `config.h`:
+You can use between 1 and 4 IS31FL3733 IC's. Do not specify `DRIVER_ADDR_` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
+
+| Variable | Description | Default |
+|----------|-------------|---------|
+| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 |
+| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
+| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | |
+| `DRIVER_LED_TOTAL` | (Required) How many RGB lights are present across all drivers | |
+| `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | |
+| `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | |
+| `DRIVER_ADDR_3` | (Optional) Address for the third RGB driver | |
+| `DRIVER_ADDR_4` | (Optional) Address for the fourth RGB driver | |
+| `DRIVER_SYNC_1` | (Optional) Sync configuration for the first RGB driver | 0 |
+| `DRIVER_SYNC_2` | (Optional) Sync configuration for the second RGB driver | 0 |
+| `DRIVER_SYNC_3` | (Optional) Sync configuration for the third RGB driver | 0 |
+| `DRIVER_SYNC_4` | (Optional) Sync configuration for the fourth RGB driver | 0 |
+
+Here is an example using 2 drivers.
```c
// This is a 7-bit address, that gets left-shifted and bit 0
@@ -81,6 +107,58 @@ Configure the hardware via your `config.h`:
// ADDR2 represents A3:A2 of the 7-bit address.
// The result is: 0b101(ADDR2)(ADDR1)
#define DRIVER_ADDR_1 0b1010000
+#define DRIVER_ADDR_2 0b1010011
+
+#define DRIVER_COUNT 2
+#define DRIVER_1_LED_TOTAL 58
+#define DRIVER_2_LED_TOTAL 10
+#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
+```
+
+!> Note the parentheses, this is so when `DRIVER_LED_TOTAL` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`.
+
+Currently only 4 drivers are supported, but it would be trivial to support all 8 combinations.
+
+Define these arrays listing all the LEDs in your `.c`:
+
+```c
+const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+/* Refer to IS31 manual for these locations
+ * driver
+ * | R location
+ * | | G location
+ * | | | B location
+ * | | | | */
+ {0, B_1, A_1, C_1},
+ ....
+}
+```
+
+Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` for now).
+
+---
+### IS31FL3737 :id=is31fl3737
+
+There is basic support for addressable RGB matrix lighting with the I2C IS31FL3737 RGB controller. To enable it, add this to your `rules.mk`:
+
+```makefile
+RGB_MATRIX_ENABLE = yes
+RGB_MATRIX_DRIVER = IS31FL3737
+```
+
+Configure the hardware via your `config.h`:
+
+```c
+// This is a 7-bit address, that gets left-shifted and bit 0
+// set to 0 for write, 1 for read (as per I2C protocol)
+// The address will vary depending on your wiring:
+// 0000 <-> GND
+// 0101 <-> SCL
+// 1010 <-> SDA
+// 1111 <-> VCC
+// ADDR represents A3:A0 of the 7-bit address.
+// The result is: 0b101(ADDR)
+#define DRIVER_ADDR_1 0b1010000
#define DRIVER_ADDR_2 0b1010000 // this is here for compliancy reasons.
#define DRIVER_COUNT 2
@@ -105,7 +183,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
}
```
-Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now).
+Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3737.pdf) and the header file `drivers/issi/is31fl3737.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now).
---
diff --git a/drivers/issi/is31fl3733.c b/drivers/issi/is31fl3733.c
index dddf0cb734..d99e5339c9 100644
--- a/drivers/issi/is31fl3733.c
+++ b/drivers/issi/is31fl3733.c
@@ -68,7 +68,7 @@ uint8_t g_twi_transfer_buffer[20];
uint8_t g_pwm_buffer[DRIVER_COUNT][192];
bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}};
+uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
diff --git a/quantum/led_matrix_drivers.c b/quantum/led_matrix_drivers.c
index 370c5e6853..f3d4bc896e 100644
--- a/quantum/led_matrix_drivers.c
+++ b/quantum/led_matrix_drivers.c
@@ -46,16 +46,28 @@ static void init(void) {
# endif
# else
# ifdef LED_DRIVER_ADDR_1
- IS31FL3733_init(LED_DRIVER_ADDR_1, 0);
+# ifndef LED_DRIVER_SYNC_1
+# define LED_DRIVER_SYNC_1 0
+# endif
+ IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1);
# endif
# ifdef LED_DRIVER_ADDR_2
- IS31FL3733_init(LED_DRIVER_ADDR_2, 0);
+# ifndef LED_DRIVER_SYNC_2
+# define LED_DRIVER_SYNC_2 0
+# endif
+ IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2);
# endif
# ifdef LED_DRIVER_ADDR_3
- IS31FL3733_init(LED_DRIVER_ADDR_3, 0);
+# ifndef LED_DRIVER_SYNC_3
+# define LED_DRIVER_SYNC_3 0
+# endif
+ IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3);
# endif
# ifdef LED_DRIVER_ADDR_4
- IS31FL3733_init(LED_DRIVER_ADDR_4, 0);
+# ifndef LED_DRIVER_SYNC_4
+# define LED_DRIVER_SYNC_4 0
+# endif
+ IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4);
# endif
# endif
@@ -133,7 +145,7 @@ const led_matrix_driver_t led_matrix_driver = {
.set_value = IS31FL3731_set_value,
.set_value_all = IS31FL3731_set_value_all,
# else
- .set_value = IS31FL3733_set_value,
+ .set_value = IS31FL3733_set_value,
.set_value_all = IS31FL3733_set_value_all,
# endif
};
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c
index 2978e7bed9..a4db86d196 100644
--- a/quantum/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix_drivers.c
@@ -41,7 +41,28 @@ static void init(void) {
IS31FL3731_init(DRIVER_ADDR_4);
# endif
# elif defined(IS31FL3733)
- IS31FL3733_init(DRIVER_ADDR_1, 0);
+# ifndef DRIVER_SYNC_1
+# define DRIVER_SYNC_1 0
+# endif
+ IS31FL3733_init(DRIVER_ADDR_1, DRIVER_SYNC_1);
+# if defined DRIVER_ADDR_2 && (DRIVER_ADDR_1 != DRIVER_ADDR_2)
+# ifndef DRIVER_SYNC_2
+# define DRIVER_SYNC_2 0
+# endif
+ IS31FL3733_init(DRIVER_ADDR_2, DRIVER_SYNC_2);
+# endif
+# ifdef DRIVER_ADDR_3
+# ifndef DRIVER_SYNC_3
+# define DRIVER_SYNC_3 0
+# endif
+ IS31FL3733_init(DRIVER_ADDR_3, DRIVER_SYNC_3);
+# endif
+# ifdef DRIVER_ADDR_4
+# ifndef DRIVER_SYNC_4
+# define DRIVER_SYNC_4 0
+# endif
+ IS31FL3733_init(DRIVER_ADDR_4, DRIVER_SYNC_4);
+# endif
# elif defined(IS31FL3737)
IS31FL3737_init(DRIVER_ADDR_1);
# else
@@ -74,7 +95,15 @@ static void init(void) {
# endif
# elif defined(IS31FL3733)
IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0);
+# ifdef DRIVER_ADDR_2
IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1);
+# endif
+# ifdef DRIVER_ADDR_3
+ IS31FL3733_update_led_control_registers(DRIVER_ADDR_3, 2);
+# endif
+# ifdef DRIVER_ADDR_4
+ IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3);
+# endif
# elif defined(IS31FL3737)
IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
# else
@@ -105,13 +134,21 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
# elif defined(IS31FL3733)
static void flush(void) {
IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
+# ifdef DRIVER_ADDR_2
IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
+# endif
+# ifdef DRIVER_ADDR_3
+ IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3, 2);
+# endif
+# ifdef DRIVER_ADDR_4
+ IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4, 3);
+# endif
}
const rgb_matrix_driver_t rgb_matrix_driver = {
- .init = init,
- .flush = flush,
- .set_color = IS31FL3733_set_color,
+ .init = init,
+ .flush = flush,
+ .set_color = IS31FL3733_set_color,
.set_color_all = IS31FL3733_set_color_all,
};
# elif defined(IS31FL3737)
--
cgit v1.2.3
From d9610120de0452bc6a548bd36b1d4fdfba56d071 Mon Sep 17 00:00:00 2001
From: Stefan Kerkmann
Date: Thu, 27 May 2021 05:37:54 +0200
Subject: Add Full-duplex serial driver for ARM boards (#9842)
---
docs/serial_driver.md | 154 +++++++++++++++++++-
drivers/chibios/serial_usart.c | 69 +++------
drivers/chibios/serial_usart.h | 78 ++++++++++
drivers/chibios/serial_usart_duplex.c | 261 ++++++++++++++++++++++++++++++++++
4 files changed, 506 insertions(+), 56 deletions(-)
create mode 100644 drivers/chibios/serial_usart.h
create mode 100644 drivers/chibios/serial_usart_duplex.c
(limited to 'drivers')
diff --git a/docs/serial_driver.md b/docs/serial_driver.md
index c98f4c1176..359fc59551 100644
--- a/docs/serial_driver.md
+++ b/docs/serial_driver.md
@@ -3,16 +3,18 @@ This driver powers the [Split Keyboard](feature_split_keyboard.md) feature.
?> Serial in this context should be read as **sending information one bit at a time**, rather than implementing UART/USART/RS485/RS232 standards.
-All drivers in this category have the following characteristics:
-* Provides data and signaling over a single conductor
-* Limited to single master, single slave
+Drivers in this category have the following characteristics:
+* bit bang and USART Half-duplex provide data and signaling over a single conductor
+* USART Full-duplex provide data and signaling over two conductors
+* They are all limited to single master and single slave communication scheme
## Supported Driver Types
| | AVR | ARM |
-|-------------------|--------------------|--------------------|
+| ----------------- | ------------------ | ------------------ |
| bit bang | :heavy_check_mark: | :heavy_check_mark: |
| USART Half-duplex | | :heavy_check_mark: |
+| USART Full-duplex | | :heavy_check_mark: |
## Driver configuration
@@ -42,7 +44,7 @@ Configure the driver via your config.h:
Along with the generic options above, you must also turn on the `PAL_USE_CALLBACKS` feature in your halconf.h.
### USART Half-duplex
-Targeting STM32 boards where communication is offloaded to a USART hardware device. The advantage is that this provides fast and accurate timings. `SOFT_SERIAL_PIN` for this driver is the configured USART TX pin. **The TX pin must have appropriate pull-up resistors**. To configure it, add this to your rules.mk:
+Targeting STM32 boards where communication is offloaded to a USART hardware device. The advantage over bitbang is that this provides fast and accurate timings. `SERIAL_PIN_TX` for this driver is the configured USART TX pin. As this Pin is configured in open-drain mode an **external pull-up resistor is needed to keep the line high** (resistor values of 1.5k to 8.2k are known to work). To configure it, add this to your rules.mk:
```make
SERIAL_DRIVER = usart
@@ -50,7 +52,8 @@ SERIAL_DRIVER = usart
Configure the hardware via your config.h:
```c
-#define SOFT_SERIAL_PIN B6 // USART TX pin
+#define SOFT_SERIAL_PIN B6 // USART TX pin
+//#define USART1_REMAP // Remap USART TX and RX pins on STM32F103 MCUs, see table below.
#define SELECT_SOFT_SERIAL_SPEED 1 // or 0, 2, 3, 4, 5
// 0: about 460800 baud
// 1: about 230400 baud (default)
@@ -58,7 +61,7 @@ Configure the hardware via your config.h:
// 3: about 57600 baud
// 4: about 38400 baud
// 5: about 19200 baud
-#define SERIAL_USART_DRIVER SD1 // USART driver of TX pin. default: SD1
+#define SERIAL_USART_DRIVER SD1 // USART driver of TX pin. default: SD1
#define SERIAL_USART_TX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
#define SERIAL_USART_TIMEOUT 100 // USART driver timeout. default 100
```
@@ -68,3 +71,140 @@ You must also enable the ChibiOS `SERIAL` feature:
* In your board's mcuconf.h: `#define STM32_SERIAL_USE_USARTn TRUE` (where 'n' matches the peripheral number of your selected USART on the MCU)
Do note that the configuration required is for the `SERIAL` peripheral, not the `UART` peripheral.
+
+### USART Full-duplex
+Targeting STM32 boards where communication is offloaded to a USART hardware device. The advantage over bitbang is that this provides fast and accurate timings. USART Full-Duplex requires two conductors **without** pull-up resistors instead of one conductor with a pull-up resistor unlike the Half-duplex driver, but it is more efficent as it uses DMA transfers, which can result in even faster transmission speeds.
+
+#### Pin configuration
+
+`SERIAL_USART_TX_PIN` is the USART `TX` pin, `SERIAL_USART_RX_PIN` is the USART `RX` pin. No external pull-up resistors are needed as the `TX` pin operates in push-pull mode. To use this driver the usart peripherals `TX` and `RX` pins must be configured with the correct Alternate-functions. If you are using a Proton-C everything is already setup, same is true for STM32F103 MCUs. For MCUs which are using a modern flexible GPIO configuration you have to specify these by setting `SERIAL_USART_TX_PAL_MODE` and `SERIAL_USART_RX_PAL_MODE`. Refeer to the corresponding datasheets of your MCU or find those settings in the table below.
+
+#### Connecting the halves and Pin Swap
+Please note that `TX` of the master half has to be connected with the `RX` pin of the slave half and `RX` of the master half has to be connected with the `TX` pin of the slave half! Usually this pin swap has to be done outside of the MCU e.g. with cables or on the pcb. Some MCUs like the STM32F303 used on the Proton-C allow this pin swap directly inside the MCU, this feature can be enabled using `#define SERIAL_USART_PIN_SWAP` in your config.h.
+
+#### Setup
+To use the driver, add this to your rules.mk:
+
+```make
+SERIAL_DRIVER = usart_duplex
+```
+
+Next configure the hardware via your config.h:
+
+```c
+#define SERIAL_USART_TX_PIN B6 // USART TX pin
+#define SERIAL_USART_RX_PIN B7 // USART RX pin
+//#define USART1_REMAP // Remap USART TX and RX pins on STM32F103 MCUs, see table below.
+//#define SERIAL_USART_PIN_SWAP // Swap TX and RX pins if keyboard is master halve.
+ // Check if this feature is necessary with your keyboard design and available on the mcu.
+#define SELECT_SOFT_SERIAL_SPEED 1 // or 0, 2, 3, 4, 5
+ // 0: 460800 baud
+ // 1: 230400 baud (default)
+ // 2: 115200 baud
+ // 3: 57600 baud
+ // 4: 38400 baud
+ // 5: 19200 baud
+#define SERIAL_USART_DRIVER UARTD1 // USART driver of TX and RX pin. default: UARTD1
+#define SERIAL_USART_TX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
+#define SERIAL_USART_RX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
+#define SERIAL_USART_TIMEOUT 100 // USART driver timeout. default 100
+```
+
+You must also enable the ChibiOS `UART` with blocking api feature:
+* In your board's halconf.h: `#define HAL_USE_UART TRUE` and `#define UART_USE_WAIT TRUE`
+* In your board's mcuconf.h: `#define STM32_UART_USE_USARTn TRUE` (where 'n' matches the peripheral number of your selected USART on the MCU)
+
+Do note that the configuration required is for the `UART` peripheral, not the `SERIAL` peripheral.
+
+#### Pins for USART Peripherals with Alternate Functions for selected STM32 MCUs
+
+##### STM32F303 / Proton-C [Datasheet](https://www.st.com/resource/en/datasheet/stm32f303cc.pdf)
+
+Pin Swap available: :heavy_check_mark:
+
+| Pin | Function | Mode |
+| ---------- | -------- | ---- |
+| **USART1** | | |
+| PA9 | TX | AF7 |
+| PA10 | RX | AF7 |
+| PB6 | TX | AF7 |
+| PB7 | RX | AF7 |
+| PC4 | TX | AF7 |
+| PC5 | RX | AF7 |
+| PE0 | TX | AF7 |
+| PE1 | RX | AF7 |
+| **USART2** | | |
+| PA2 | TX | AF7 |
+| PA3 | RX | AF7 |
+| PA14 | TX | AF7 |
+| PA15 | RX | AF7 |
+| PB3 | TX | AF7 |
+| PB4 | RX | AF7 |
+| PD5 | TX | AF7 |
+| PD6 | RX | AF7 |
+| **USART3** | | |
+| PB10 | TX | AF7 |
+| PB11 | RX | AF7 |
+| PC10 | TX | AF7 |
+| PC11 | RX | AF7 |
+| PD8 | TX | AF7 |
+| PD9 | RX | AF7 |
+
+##### STM32F072 [Datasheet](https://www.st.com/resource/en/datasheet/stm32f072c8.pdf)
+
+Pin Swap available: :heavy_check_mark:
+
+| Pin | Function | Mode |
+| ------ | -------- | ---- |
+| USART1 | | |
+| PA9 | TX | AF1 |
+| PA10 | RX | AF1 |
+| PB6 | TX | AF0 |
+| PB7 | RX | AF0 |
+| USART2 | | |
+| PA2 | TX | AF1 |
+| PA3 | RX | AF1 |
+| PA14 | TX | AF1 |
+| PA15 | RX | AF1 |
+| USART3 | | |
+| PB10 | TX | AF4 |
+| PB11 | RX | AF4 |
+| PC4 | TX | AF1 |
+| PC5 | RX | AF1 |
+| PC10 | TX | AF1 |
+| PC11 | RX | AF1 |
+| PD8 | TX | AF0 |
+| PD9 | RX | AF0 |
+| USART4 | | |
+| PA0 | TX | AF4 |
+| PA1 | RX | AF4 |
+
+##### STM32F103 Medium Density (C8-CB) [Datasheet](https://www.st.com/resource/en/datasheet/stm32f103c8.pdf)
+
+Pin Swap available: N/A
+
+TX Pin is always Alternate Function Push-Pull, RX Pin is always regular input pin for any USART peripheral. **For STM32F103 no additional Alternate Function configuration is necessary. QMK is already configured.**
+
+Pin remapping:
+
+The pins of USART Peripherals use default Pins that can be remapped to use other pins using the AFIO registers. Default pins are marked **bold**. Add the appropriate defines to your config.h file.
+
+| Pin | Function | Mode | USART_REMAP |
+| ---------- | -------- | ---- | ------------------- |
+| **USART1** | | | |
+| **PA9** | TX | AFPP | |
+| **PA10** | RX | IN | |
+| PB6 | TX | AFPP | USART1_REMAP |
+| PB7 | RX | IN | USART1_REMAP |
+| **USART2** | | | |
+| **PA2** | TX | AFPP | |
+| **PA3** | RX | IN | |
+| PD5 | TX | AFPP | USART2_REMAP |
+| PD6 | RX | IN | USART2_REMAP |
+| **USART3** | | | |
+| **PB10** | TX | AFPP | |
+| **PB11** | RX | IN | |
+| PC10 | TX | AFPP | USART3_PARTIALREMAP |
+| PC11 | RX | IN | USART3_PARTIALREMAP |
+| PD8 | TX | AFPP | USART3_FULLREMAP |
+| PD9 | RX | IN | USART3_FULLREMAP |
diff --git a/drivers/chibios/serial_usart.c b/drivers/chibios/serial_usart.c
index 7c81b16464..cae29388c3 100644
--- a/drivers/chibios/serial_usart.c
+++ b/drivers/chibios/serial_usart.c
@@ -1,13 +1,20 @@
-#include "quantum.h"
-#include "serial.h"
-#include "print.h"
-
-#include
-#include
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
-#ifndef USART_CR1_M0
-# define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so
-#endif
+#include "serial_usart.h"
#ifndef USE_GPIOV1
// The default PAL alternate modes are used to signal that the pins are used for USART
@@ -20,50 +27,10 @@
# define SERIAL_USART_DRIVER SD1
#endif
-#ifndef SERIAL_USART_CR1
-# define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length
-#endif
-
-#ifndef SERIAL_USART_CR2
-# define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits
-#endif
-
-#ifndef SERIAL_USART_CR3
-# define SERIAL_USART_CR3 0
-#endif
-
#ifdef SOFT_SERIAL_PIN
# define SERIAL_USART_TX_PIN SOFT_SERIAL_PIN
#endif
-#ifndef SELECT_SOFT_SERIAL_SPEED
-# define SELECT_SOFT_SERIAL_SPEED 1
-#endif
-
-#ifdef SERIAL_USART_SPEED
-// Allow advanced users to directly set SERIAL_USART_SPEED
-#elif SELECT_SOFT_SERIAL_SPEED == 0
-# define SERIAL_USART_SPEED 460800
-#elif SELECT_SOFT_SERIAL_SPEED == 1
-# define SERIAL_USART_SPEED 230400
-#elif SELECT_SOFT_SERIAL_SPEED == 2
-# define SERIAL_USART_SPEED 115200
-#elif SELECT_SOFT_SERIAL_SPEED == 3
-# define SERIAL_USART_SPEED 57600
-#elif SELECT_SOFT_SERIAL_SPEED == 4
-# define SERIAL_USART_SPEED 38400
-#elif SELECT_SOFT_SERIAL_SPEED == 5
-# define SERIAL_USART_SPEED 19200
-#else
-# error invalid SELECT_SOFT_SERIAL_SPEED value
-#endif
-
-#ifndef SERIAL_USART_TIMEOUT
-# define SERIAL_USART_TIMEOUT 100
-#endif
-
-#define HANDSHAKE_MAGIC 7
-
static inline msg_t sdWriteHalfDuplex(SerialDriver* driver, uint8_t* data, uint8_t size) {
msg_t ret = sdWrite(driver, data, size);
@@ -123,6 +90,10 @@ __attribute__((weak)) void usart_init(void) {
#else
palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
#endif
+
+#if defined(USART_REMAP)
+ USART_REMAP;
+#endif
}
void usart_master_init(void) {
diff --git a/drivers/chibios/serial_usart.h b/drivers/chibios/serial_usart.h
new file mode 100644
index 0000000000..d35b5d12c6
--- /dev/null
+++ b/drivers/chibios/serial_usart.h
@@ -0,0 +1,78 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include "quantum.h"
+#include "serial.h"
+#include "printf.h"
+
+#include
+#include
+
+#ifndef USART_CR1_M0
+# define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so
+#endif
+
+#ifndef SERIAL_USART_CR1
+# define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length
+#endif
+
+#ifndef SERIAL_USART_CR2
+# define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits
+#endif
+
+#ifndef SERIAL_USART_CR3
+# define SERIAL_USART_CR3 0
+#endif
+
+#if defined(USART1_REMAP)
+# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART1_REMAP); } while(0)
+#elif defined(USART2_REMAP)
+# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART2_REMAP); } while(0)
+#elif defined(USART3_PARTIALREMAP)
+# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP); } while(0)
+#elif defined(USART3_FULLREMAP)
+# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); } while(0)
+#endif
+
+#ifndef SELECT_SOFT_SERIAL_SPEED
+# define SELECT_SOFT_SERIAL_SPEED 1
+#endif
+
+#ifdef SERIAL_USART_SPEED
+// Allow advanced users to directly set SERIAL_USART_SPEED
+#elif SELECT_SOFT_SERIAL_SPEED == 0
+# define SERIAL_USART_SPEED 460800
+#elif SELECT_SOFT_SERIAL_SPEED == 1
+# define SERIAL_USART_SPEED 230400
+#elif SELECT_SOFT_SERIAL_SPEED == 2
+# define SERIAL_USART_SPEED 115200
+#elif SELECT_SOFT_SERIAL_SPEED == 3
+# define SERIAL_USART_SPEED 57600
+#elif SELECT_SOFT_SERIAL_SPEED == 4
+# define SERIAL_USART_SPEED 38400
+#elif SELECT_SOFT_SERIAL_SPEED == 5
+# define SERIAL_USART_SPEED 19200
+#else
+# error invalid SELECT_SOFT_SERIAL_SPEED value
+#endif
+
+#ifndef SERIAL_USART_TIMEOUT
+# define SERIAL_USART_TIMEOUT 100
+#endif
+
+#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 0000000000..cc9b889ac2
--- /dev/null
+++ b/drivers/chibios/serial_usart_duplex.c
@@ -0,0 +1,261 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "serial_usart.h"
+
+#include
+
+#if !defined(USE_GPIOV1)
+// The default PAL alternate modes are used to signal that the pins are used for USART
+# if !defined(SERIAL_USART_TX_PAL_MODE)
+# define SERIAL_USART_TX_PAL_MODE 7
+# endif
+# if !defined(SERIAL_USART_RX_PAL_MODE)
+# define SERIAL_USART_RX_PAL_MODE 7
+# endif
+#endif
+
+#if !defined(SERIAL_USART_DRIVER)
+# define SERIAL_USART_DRIVER UARTD1
+#endif
+
+#if !defined(SERIAL_USART_TX_PIN)
+# define SERIAL_USART_TX_PIN A9
+#endif
+
+#if !defined(SERIAL_USART_RX_PIN)
+# define SERIAL_USART_RX_PIN A10
+#endif
+
+#define SIGNAL_HANDSHAKE_RECEIVED 0x1
+
+void handle_transactions_slave(uint8_t sstd_index);
+static void receive_transaction_handshake(UARTDriver* uartp, uint16_t received_handshake);
+
+/*
+ * UART driver configuration structure. We use the blocking DMA enabled API and
+ * the rxchar callback to receive handshake tokens but only on the slave halve.
+ */
+// clang-format off
+static UARTConfig uart_config = {
+ .txend1_cb = NULL,
+ .txend2_cb = NULL,
+ .rxend_cb = NULL,
+ .rxchar_cb = NULL,
+ .rxerr_cb = NULL,
+ .timeout_cb = NULL,
+ .speed = (SERIAL_USART_SPEED),
+ .cr1 = (SERIAL_USART_CR1),
+ .cr2 = (SERIAL_USART_CR2),
+ .cr3 = (SERIAL_USART_CR3)
+};
+// clang-format on
+
+static SSTD_t* Transaction_table = NULL;
+static uint8_t Transaction_table_size = 0;
+static atomic_uint_least8_t handshake = 0xFF;
+static thread_reference_t tp_target = NULL;
+
+/*
+ * This callback is invoked when a character is received but the application
+ * was not ready to receive it, the character is passed as parameter.
+ * Receive transaction table index from initiator, which doubles as basic handshake token. */
+static void receive_transaction_handshake(UARTDriver* uartp, uint16_t received_handshake) {
+ /* Check if received handshake is not a valid transaction id.
+ * Please note that we can still catch a seemingly valid handshake
+ * i.e. a byte from a ongoing transfer which is in the allowed range.
+ * So this check mainly prevents any obviously wrong handshakes and
+ * subsequent wakeups of the receiving thread, which is a costly operation. */
+ if (received_handshake > Transaction_table_size) {
+ return;
+ }
+
+ handshake = (uint8_t)received_handshake;
+ chSysLockFromISR();
+ /* Wakeup receiving thread to start a transaction. */
+ chEvtSignalI(tp_target, (eventmask_t)SIGNAL_HANDSHAKE_RECEIVED);
+ chSysUnlockFromISR();
+}
+
+__attribute__((weak)) void usart_init(void) {
+#if defined(USE_GPIOV1)
+ palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
+ palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);
+#else
+ palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
+ palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_RX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
+#endif
+}
+
+/*
+ * This thread runs on the slave half and reacts to transactions initiated from the master.
+ */
+static THD_WORKING_AREA(waSlaveThread, 1024);
+static THD_FUNCTION(SlaveThread, arg) {
+ (void)arg;
+ chRegSetThreadName("slave_usart_tx_rx");
+
+ while (true) {
+ /* We sleep as long as there is no handshake waiting for us. */
+ chEvtWaitAny((eventmask_t)SIGNAL_HANDSHAKE_RECEIVED);
+ handle_transactions_slave(handshake);
+ }
+}
+
+void soft_serial_target_init(SSTD_t* const sstd_table, int sstd_table_size) {
+ Transaction_table = sstd_table;
+ Transaction_table_size = (uint8_t)sstd_table_size;
+ usart_init();
+
+#if defined(USART_REMAP)
+ USART_REMAP;
+#endif
+
+ tp_target = chThdCreateStatic(waSlaveThread, sizeof(waSlaveThread), HIGHPRIO, SlaveThread, NULL);
+
+ // Start receiving handshake tokens on slave halve
+ uart_config.rxchar_cb = receive_transaction_handshake;
+ uartStart(&SERIAL_USART_DRIVER, &uart_config);
+}
+
+/**
+ * @brief React to transactions started by the master.
+ * This version uses duplex send and receive usart pheriphals and DMA backed transfers.
+ */
+void inline handle_transactions_slave(uint8_t sstd_index) {
+ size_t buffer_size = 0;
+ msg_t msg = 0;
+ SSTD_t* trans = &Transaction_table[sstd_index];
+
+ /* Send back the handshake which is XORed as a simple checksum,
+ to signal that the slave is ready to receive possible transaction buffers */
+ sstd_index ^= HANDSHAKE_MAGIC;
+ buffer_size = (size_t)sizeof(sstd_index);
+ msg = uartSendTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index, TIME_MS2I(SERIAL_USART_TIMEOUT));
+
+ if (msg != MSG_OK) {
+ if (trans->status) {
+ *trans->status = TRANSACTION_NO_RESPONSE;
+ }
+ return;
+ }
+
+ /* Receive transaction buffer from the master. If this transaction requires it.*/
+ buffer_size = (size_t)trans->initiator2target_buffer_size;
+ if (buffer_size) {
+ msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->initiator2target_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
+ if (msg != MSG_OK) {
+ if (trans->status) {
+ *trans->status = TRANSACTION_NO_RESPONSE;
+ }
+ return;
+ }
+ }
+
+ /* Send transaction buffer to the master. If this transaction requires it. */
+ buffer_size = (size_t)trans->target2initiator_buffer_size;
+ if (buffer_size) {
+ msg = uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->target2initiator_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
+ if (msg != MSG_OK) {
+ if (trans->status) {
+ *trans->status = TRANSACTION_NO_RESPONSE;
+ }
+ return;
+ }
+ }
+
+ if (trans->status) {
+ *trans->status = TRANSACTION_ACCEPTED;
+ }
+}
+
+void soft_serial_initiator_init(SSTD_t* const sstd_table, int sstd_table_size) {
+ Transaction_table = sstd_table;
+ Transaction_table_size = (uint8_t)sstd_table_size;
+ usart_init();
+
+#if defined(SERIAL_USART_PIN_SWAP)
+ uart_config.cr2 |= USART_CR2_SWAP; // master has swapped TX/RX pins
+#endif
+
+#if defined(USART_REMAP)
+ USART_REMAP;
+#endif
+
+ uartStart(&SERIAL_USART_DRIVER, &uart_config);
+}
+
+/**
+ * @brief Start transaction from the master to the slave.
+ * This version uses duplex send and receive usart pheriphals and DMA backed transfers.
+ *
+ * @param index Transaction Table index of the transaction to start.
+ * @return int TRANSACTION_NO_RESPONSE in case of Timeout.
+ * TRANSACTION_TYPE_ERROR in case of invalid transaction index.
+ * TRANSACTION_END in case of success.
+ */
+#if !defined(SERIAL_USE_MULTI_TRANSACTION)
+int soft_serial_transaction(void) {
+ uint8_t sstd_index = 0;
+#else
+int soft_serial_transaction(int index) {
+ uint8_t sstd_index = index;
+#endif
+
+ if (sstd_index > Transaction_table_size) {
+ return TRANSACTION_TYPE_ERROR;
+ }
+
+ SSTD_t* const trans = &Transaction_table[sstd_index];
+ msg_t msg = 0;
+ size_t buffer_size = (size_t)sizeof(sstd_index);
+
+ /* Send transaction table index to the slave, which doubles as basic handshake token. */
+ uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index, TIME_MS2I(SERIAL_USART_TIMEOUT));
+
+ uint8_t sstd_index_shake = 0xFF;
+ buffer_size = (size_t)sizeof(sstd_index_shake);
+
+ /* Receive the handshake token from the slave. The token was XORed by the slave as a simple checksum.
+ If the tokens match, the master will start to send and receive possible transaction buffers. */
+ msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index_shake, TIME_MS2I(SERIAL_USART_TIMEOUT));
+ if (msg != MSG_OK || (sstd_index_shake != (sstd_index ^ HANDSHAKE_MAGIC))) {
+ dprintln("USART: Handshake Failed");
+ return TRANSACTION_NO_RESPONSE;
+ }
+
+ /* Send transaction buffer to the slave. If this transaction requires it. */
+ buffer_size = (size_t)trans->initiator2target_buffer_size;
+ if (buffer_size) {
+ msg = uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->initiator2target_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
+ if (msg != MSG_OK) {
+ dprintln("USART: Send Failed");
+ return TRANSACTION_NO_RESPONSE;
+ }
+ }
+
+ /* Receive transaction buffer from the slave. If this transaction requires it. */
+ buffer_size = (size_t)trans->target2initiator_buffer_size;
+ if (buffer_size) {
+ msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->target2initiator_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
+ if (msg != MSG_OK) {
+ dprintln("USART: Receive Failed");
+ return TRANSACTION_NO_RESPONSE;
+ }
+ }
+
+ return TRANSACTION_END;
+}
--
cgit v1.2.3
From 7d1194de01ea94f065bd5176607b4d66279ef51b Mon Sep 17 00:00:00 2001
From: James Young
Date: Sat, 29 May 2021 13:53:10 -0700
Subject: run: qmk cformat --core-only
---
drivers/chibios/analog.c | 2 +-
drivers/chibios/serial_usart.h | 20 ++++--
quantum/led_matrix_animations/alpha_mods_anim.h | 2 +-
quantum/led_matrix_animations/band_anim.h | 6 +-
quantum/led_matrix_animations/band_pinwheel_anim.h | 10 +--
quantum/led_matrix_animations/band_spiral_anim.h | 10 +--
quantum/led_matrix_animations/breathing_anim.h | 2 +-
.../led_matrix_animations/cycle_left_right_anim.h | 10 +--
quantum/led_matrix_animations/cycle_out_in_anim.h | 10 +--
quantum/led_matrix_animations/cycle_up_down_anim.h | 10 +--
quantum/led_matrix_animations/dual_beacon_anim.h | 10 +--
.../led_matrix_animations/solid_reactive_cross.h | 12 ++--
.../led_matrix_animations/solid_reactive_nexus.h | 12 ++--
.../solid_reactive_simple_anim.h | 12 ++--
.../led_matrix_animations/solid_reactive_wide.h | 12 ++--
quantum/led_matrix_animations/solid_splash_anim.h | 12 ++--
.../led_matrix_animations/wave_left_right_anim.h | 10 +--
quantum/led_matrix_animations/wave_up_down_anim.h | 10 +--
quantum/led_matrix_drivers.c | 2 +-
quantum/quantum_keycodes.h | 12 ++--
quantum/rgb_matrix_drivers.c | 6 +-
quantum/rgblight.c | 8 +--
quantum/split_common/transport.c | 34 ++++-----
tmk_core/common/action.c | 83 ++++++++++------------
tmk_core/common/action.h | 2 +-
tmk_core/common/chibios/sleep_led.c | 4 +-
tmk_core/common/keyboard.h | 6 +-
27 files changed, 139 insertions(+), 190 deletions(-)
(limited to 'drivers')
diff --git a/drivers/chibios/analog.c b/drivers/chibios/analog.c
index b1081623d3..8c476fcac2 100644
--- a/drivers/chibios/analog.c
+++ b/drivers/chibios/analog.c
@@ -123,7 +123,7 @@ static ADCConversionGroup adcConversionGroup = {
.smpr = ADC_SAMPLING_RATE,
#elif defined(USE_ADCV2)
# if !defined(STM32F1XX)
- .cr2 = ADC_CR2_SWSTART, // F103 seem very unhappy with, F401 seems very unhappy without...
+ .cr2 = ADC_CR2_SWSTART, // F103 seem very unhappy with, F401 seems very unhappy without...
# endif
.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),
.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),
diff --git a/drivers/chibios/serial_usart.h b/drivers/chibios/serial_usart.h
index d35b5d12c6..fee7b4d159 100644
--- a/drivers/chibios/serial_usart.h
+++ b/drivers/chibios/serial_usart.h
@@ -40,13 +40,25 @@
#endif
#if defined(USART1_REMAP)
-# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART1_REMAP); } while(0)
+# define USART_REMAP \
+ do { \
+ (AFIO->MAPR |= AFIO_MAPR_USART1_REMAP); \
+ } while (0)
#elif defined(USART2_REMAP)
-# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART2_REMAP); } while(0)
+# define USART_REMAP \
+ do { \
+ (AFIO->MAPR |= AFIO_MAPR_USART2_REMAP); \
+ } while (0)
#elif defined(USART3_PARTIALREMAP)
-# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP); } while(0)
+# define USART_REMAP \
+ do { \
+ (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP); \
+ } while (0)
#elif defined(USART3_FULLREMAP)
-# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); } while(0)
+# define USART_REMAP \
+ do { \
+ (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); \
+ } while (0)
#endif
#ifndef SELECT_SOFT_SERIAL_SPEED
diff --git a/quantum/led_matrix_animations/alpha_mods_anim.h b/quantum/led_matrix_animations/alpha_mods_anim.h
index a4638fde69..6f69f6892b 100644
--- a/quantum/led_matrix_animations/alpha_mods_anim.h
+++ b/quantum/led_matrix_animations/alpha_mods_anim.h
@@ -21,4 +21,4 @@ bool ALPHAS_MODS(effect_params_t* params) {
}
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_ALPHAS_MODS
+#endif // DISABLE_LED_MATRIX_ALPHAS_MODS
diff --git a/quantum/led_matrix_animations/band_anim.h b/quantum/led_matrix_animations/band_anim.h
index 4a2b746a76..523dba1b78 100644
--- a/quantum/led_matrix_animations/band_anim.h
+++ b/quantum/led_matrix_animations/band_anim.h
@@ -7,9 +7,7 @@ static uint8_t BAND_math(uint8_t val, uint8_t i, uint8_t time) {
return scale8(v < 0 ? 0 : v, val);
}
-bool BAND(effect_params_t* params) {
- return effect_runner_i(params, &BAND_math);
-}
+bool BAND(effect_params_t* params) { return effect_runner_i(params, &BAND_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_BAND
+#endif // DISABLE_LED_MATRIX_BAND
diff --git a/quantum/led_matrix_animations/band_pinwheel_anim.h b/quantum/led_matrix_animations/band_pinwheel_anim.h
index 9836320d2a..fb3b835cad 100644
--- a/quantum/led_matrix_animations/band_pinwheel_anim.h
+++ b/quantum/led_matrix_animations/band_pinwheel_anim.h
@@ -2,13 +2,9 @@
LED_MATRIX_EFFECT(BAND_PINWHEEL)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t BAND_PINWHEEL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t time) {
- return scale8(val - time - atan2_8(dy, dx) * 3, val);
-}
+static uint8_t BAND_PINWHEEL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t time) { return scale8(val - time - atan2_8(dy, dx) * 3, val); }
-bool BAND_PINWHEEL(effect_params_t* params) {
- return effect_runner_dx_dy(params, &BAND_PINWHEEL_math);
-}
+bool BAND_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_BAND_PINWHEEL
+#endif // DISABLE_LED_MATRIX_BAND_PINWHEEL
diff --git a/quantum/led_matrix_animations/band_spiral_anim.h b/quantum/led_matrix_animations/band_spiral_anim.h
index be17c03aad..fca22aad9c 100644
--- a/quantum/led_matrix_animations/band_spiral_anim.h
+++ b/quantum/led_matrix_animations/band_spiral_anim.h
@@ -2,13 +2,9 @@
LED_MATRIX_EFFECT(BAND_SPIRAL)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t BAND_SPIRAL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
- return scale8(val + dist - time - atan2_8(dy, dx), val);
-}
+static uint8_t BAND_SPIRAL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(val + dist - time - atan2_8(dy, dx), val); }
-bool BAND_SPIRAL(effect_params_t* params) {
- return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_math);
-}
+bool BAND_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_BAND_SPIRAL
+#endif // DISABLE_LED_MATRIX_BAND_SPIRAL
diff --git a/quantum/led_matrix_animations/breathing_anim.h b/quantum/led_matrix_animations/breathing_anim.h
index 4f49f50690..00310e3f65 100644
--- a/quantum/led_matrix_animations/breathing_anim.h
+++ b/quantum/led_matrix_animations/breathing_anim.h
@@ -16,4 +16,4 @@ bool BREATHING(effect_params_t* params) {
}
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_BREATHING
+#endif // DISABLE_LED_MATRIX_BREATHING
diff --git a/quantum/led_matrix_animations/cycle_left_right_anim.h b/quantum/led_matrix_animations/cycle_left_right_anim.h
index 404fda26f5..51e81d57ca 100644
--- a/quantum/led_matrix_animations/cycle_left_right_anim.h
+++ b/quantum/led_matrix_animations/cycle_left_right_anim.h
@@ -2,13 +2,9 @@
LED_MATRIX_EFFECT(CYCLE_LEFT_RIGHT)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t CYCLE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) {
- return scale8(g_led_config.point[i].x - time, val);
-}
+static uint8_t CYCLE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].x - time, val); }
-bool CYCLE_LEFT_RIGHT(effect_params_t* params) {
- return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math);
-}
+bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT
+#endif // DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT
diff --git a/quantum/led_matrix_animations/cycle_out_in_anim.h b/quantum/led_matrix_animations/cycle_out_in_anim.h
index 3f5fc5b187..f62061552c 100644
--- a/quantum/led_matrix_animations/cycle_out_in_anim.h
+++ b/quantum/led_matrix_animations/cycle_out_in_anim.h
@@ -2,13 +2,9 @@
LED_MATRIX_EFFECT(CYCLE_OUT_IN)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t CYCLE_OUT_IN_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
- return scale8(3 * dist / 2 + time, val);
-}
+static uint8_t CYCLE_OUT_IN_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(3 * dist / 2 + time, val); }
-bool CYCLE_OUT_IN(effect_params_t* params) {
- return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math);
-}
+bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_CYCLE_OUT_IN
+#endif // DISABLE_LED_MATRIX_CYCLE_OUT_IN
diff --git a/quantum/led_matrix_animations/cycle_up_down_anim.h b/quantum/led_matrix_animations/cycle_up_down_anim.h
index 25fc211b17..bd1d125672 100644
--- a/quantum/led_matrix_animations/cycle_up_down_anim.h
+++ b/quantum/led_matrix_animations/cycle_up_down_anim.h
@@ -2,13 +2,9 @@
LED_MATRIX_EFFECT(CYCLE_UP_DOWN)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t CYCLE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) {
- return scale8(g_led_config.point[i].y - time, val);
-}
+static uint8_t CYCLE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].y - time, val); }
-bool CYCLE_UP_DOWN(effect_params_t* params) {
- return effect_runner_i(params, &CYCLE_UP_DOWN_math);
-}
+bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_CYCLE_UP_DOWN
+#endif // DISABLE_LED_MATRIX_CYCLE_UP_DOWN
diff --git a/quantum/led_matrix_animations/dual_beacon_anim.h b/quantum/led_matrix_animations/dual_beacon_anim.h
index 1fa1df1395..9b8a7877c9 100644
--- a/quantum/led_matrix_animations/dual_beacon_anim.h
+++ b/quantum/led_matrix_animations/dual_beacon_anim.h
@@ -2,13 +2,9 @@
LED_MATRIX_EFFECT(DUAL_BEACON)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t DUAL_BEACON_math(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time) {
- return scale8(((g_led_config.point[i].y - k_led_matrix_center.y) * cos + (g_led_config.point[i].x - k_led_matrix_center.x) * sin) / 128, val);
-}
+static uint8_t DUAL_BEACON_math(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { return scale8(((g_led_config.point[i].y - k_led_matrix_center.y) * cos + (g_led_config.point[i].x - k_led_matrix_center.x) * sin) / 128, val); }
-bool DUAL_BEACON(effect_params_t* params) {
- return effect_runner_sin_cos_i(params, &DUAL_BEACON_math);
-}
+bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_DUAL_BEACON
+#endif // DISABLE_LED_MATRIX_DUAL_BEACON
diff --git a/quantum/led_matrix_animations/solid_reactive_cross.h b/quantum/led_matrix_animations/solid_reactive_cross.h
index a50d1fc629..f402d99b37 100644
--- a/quantum/led_matrix_animations/solid_reactive_cross.h
+++ b/quantum/led_matrix_animations/solid_reactive_cross.h
@@ -23,17 +23,13 @@ static uint8_t SOLID_REACTIVE_CROSS_math(uint8_t val, int16_t dx, int16_t dy, ui
}
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS
-bool SOLID_REACTIVE_CROSS(effect_params_t* params) {
- return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math);
-}
+bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); }
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS
-bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) {
- return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math);
-}
+bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); }
# endif
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS)
-#endif // LED_MATRIX_KEYREACTIVE_ENABLED
+# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS)
+#endif // LED_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/led_matrix_animations/solid_reactive_nexus.h b/quantum/led_matrix_animations/solid_reactive_nexus.h
index 4638aac5a4..4d0d252263 100644
--- a/quantum/led_matrix_animations/solid_reactive_nexus.h
+++ b/quantum/led_matrix_animations/solid_reactive_nexus.h
@@ -20,17 +20,13 @@ static uint8_t SOLID_REACTIVE_NEXUS_math(uint8_t val, int16_t dx, int16_t dy, ui
}
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS
-bool SOLID_REACTIVE_NEXUS(effect_params_t* params) {
- return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math);
-}
+bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); }
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS
-bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) {
- return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math);
-}
+bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); }
# endif
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS)
-#endif // LED_MATRIX_KEYREACTIVE_ENABLED
+# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS)
+#endif // LED_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/led_matrix_animations/solid_reactive_simple_anim.h b/quantum/led_matrix_animations/solid_reactive_simple_anim.h
index e1166a4fb6..30e2527f60 100644
--- a/quantum/led_matrix_animations/solid_reactive_simple_anim.h
+++ b/quantum/led_matrix_animations/solid_reactive_simple_anim.h
@@ -3,14 +3,10 @@
LED_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t SOLID_REACTIVE_SIMPLE_math(uint8_t val, uint16_t offset) {
- return scale8(255 - offset, val);
-}
+static uint8_t SOLID_REACTIVE_SIMPLE_math(uint8_t val, uint16_t offset) { return scale8(255 - offset, val); }
-bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) {
- return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math);
-}
+bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-# endif // DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE
-#endif // LED_MATRIX_KEYREACTIVE_ENABLED
+# endif // DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE
+#endif // LED_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/led_matrix_animations/solid_reactive_wide.h b/quantum/led_matrix_animations/solid_reactive_wide.h
index 4bcaba331e..34a230c259 100644
--- a/quantum/led_matrix_animations/solid_reactive_wide.h
+++ b/quantum/led_matrix_animations/solid_reactive_wide.h
@@ -18,17 +18,13 @@ static uint8_t SOLID_REACTIVE_WIDE_math(uint8_t val, int16_t dx, int16_t dy, uin
}
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE
-bool SOLID_REACTIVE_WIDE(effect_params_t* params) {
- return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math);
-}
+bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); }
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE
-bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) {
- return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math);
-}
+bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); }
# endif
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE)
-#endif // LED_MATRIX_KEYREACTIVE_ENABLED
+# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE)
+#endif // LED_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/led_matrix_animations/solid_splash_anim.h b/quantum/led_matrix_animations/solid_splash_anim.h
index 3e9046640e..4f6ba3d343 100644
--- a/quantum/led_matrix_animations/solid_splash_anim.h
+++ b/quantum/led_matrix_animations/solid_splash_anim.h
@@ -18,17 +18,13 @@ uint8_t SOLID_SPLASH_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uin
}
# ifndef DISABLE_LED_MATRIX_SOLID_SPLASH
-bool SOLID_SPLASH(effect_params_t* params) {
- return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math);
-}
+bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); }
# endif
# ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH
-bool SOLID_MULTISPLASH(effect_params_t* params) {
- return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math);
-}
+bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); }
# endif
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-# endif // !defined(DISABLE_LED_MATRIX_SPLASH) && !defined(DISABLE_LED_MATRIX_MULTISPLASH)
-#endif // LED_MATRIX_KEYREACTIVE_ENABLED
+# endif // !defined(DISABLE_LED_MATRIX_SPLASH) && !defined(DISABLE_LED_MATRIX_MULTISPLASH)
+#endif // LED_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/led_matrix_animations/wave_left_right_anim.h b/quantum/led_matrix_animations/wave_left_right_anim.h
index d547c72cee..736f22ddc5 100644
--- a/quantum/led_matrix_animations/wave_left_right_anim.h
+++ b/quantum/led_matrix_animations/wave_left_right_anim.h
@@ -2,13 +2,9 @@
LED_MATRIX_EFFECT(WAVE_LEFT_RIGHT)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t WAVE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) {
- return scale8(sin8(g_led_config.point[i].x - time), val);
-}
+static uint8_t WAVE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].x - time), val); }
-bool WAVE_LEFT_RIGHT(effect_params_t* params) {
- return effect_runner_i(params, &WAVE_LEFT_RIGHT_math);
-}
+bool WAVE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &WAVE_LEFT_RIGHT_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT
+#endif // DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT
diff --git a/quantum/led_matrix_animations/wave_up_down_anim.h b/quantum/led_matrix_animations/wave_up_down_anim.h
index b68ff9bbc6..3cab0597d4 100644
--- a/quantum/led_matrix_animations/wave_up_down_anim.h
+++ b/quantum/led_matrix_animations/wave_up_down_anim.h
@@ -2,13 +2,9 @@
LED_MATRIX_EFFECT(WAVE_UP_DOWN)
# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS
-static uint8_t WAVE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) {
- return scale8(sin8(g_led_config.point[i].y - time), val);
-}
+static uint8_t WAVE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].y - time), val); }
-bool WAVE_UP_DOWN(effect_params_t* params) {
- return effect_runner_i(params, &WAVE_UP_DOWN_math);
-}
+bool WAVE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &WAVE_UP_DOWN_math); }
# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
-#endif // DISABLE_LED_MATRIX_WAVE_UP_DOWN
+#endif // DISABLE_LED_MATRIX_WAVE_UP_DOWN
diff --git a/quantum/led_matrix_drivers.c b/quantum/led_matrix_drivers.c
index f3d4bc896e..1d46b2c506 100644
--- a/quantum/led_matrix_drivers.c
+++ b/quantum/led_matrix_drivers.c
@@ -145,7 +145,7 @@ const led_matrix_driver_t led_matrix_driver = {
.set_value = IS31FL3731_set_value,
.set_value_all = IS31FL3731_set_value_all,
# else
- .set_value = IS31FL3733_set_value,
+ .set_value = IS31FL3733_set_value,
.set_value_all = IS31FL3733_set_value_all,
# endif
};
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 26021598a1..316c20fcef 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -760,12 +760,12 @@ enum quantum_keycodes {
#define CMD_T(kc) LCMD_T(kc)
#define WIN_T(kc) LWIN_T(kc)
-#define C_S_T(kc) MT(MOD_LCTL | MOD_LSFT, kc) // Left Control + Shift e.g. for gnome-terminal
-#define MEH_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT, kc) // Meh is a less hyper version of the Hyper key -- doesn't include GUI, so just Left Control + Shift + Alt
-#define LCAG_T(kc) MT(MOD_LCTL | MOD_LALT | MOD_LGUI, kc) // Left Control + Alt + GUI
-#define RCAG_T(kc) MT(MOD_RCTL | MOD_RALT | MOD_RGUI, kc) // Right Control + Alt + GUI
+#define C_S_T(kc) MT(MOD_LCTL | MOD_LSFT, kc) // Left Control + Shift e.g. for gnome-terminal
+#define MEH_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT, kc) // Meh is a less hyper version of the Hyper key -- doesn't include GUI, so just Left Control + Shift + Alt
+#define LCAG_T(kc) MT(MOD_LCTL | MOD_LALT | MOD_LGUI, kc) // Left Control + Alt + GUI
+#define RCAG_T(kc) MT(MOD_RCTL | MOD_RALT | MOD_RGUI, kc) // Right Control + Alt + GUI
#define HYPR_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI, kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
-#define SGUI_T(kc) MT(MOD_LGUI | MOD_LSFT, kc) // Left Shift + GUI
+#define SGUI_T(kc) MT(MOD_LGUI | MOD_LSFT, kc) // Left Shift + GUI
#define SCMD_T(kc) SGUI_T(kc)
#define SWIN_T(kc) SGUI_T(kc)
#define LCA_T(kc) MT(MOD_LCTL | MOD_LALT, kc) // Left Control + Alt
@@ -792,7 +792,7 @@ enum quantum_keycodes {
#define UC_M_MA UNICODE_MODE_MAC
#define UNICODE_MODE_OSX UNICODE_MODE_MAC // Deprecated alias
-#define UC_M_OS UNICODE_MODE_MAC // Deprecated alias
+#define UC_M_OS UNICODE_MODE_MAC // Deprecated alias
#define UC_M_LN UNICODE_MODE_LNX
#define UC_M_WI UNICODE_MODE_WIN
#define UC_M_BS UNICODE_MODE_BSD
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c
index a4db86d196..896fa6d0ef 100644
--- a/quantum/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix_drivers.c
@@ -146,9 +146,9 @@ static void flush(void) {
}
const rgb_matrix_driver_t rgb_matrix_driver = {
- .init = init,
- .flush = flush,
- .set_color = IS31FL3733_set_color,
+ .init = init,
+ .flush = flush,
+ .set_color = IS31FL3733_set_color,
.set_color_all = IS31FL3733_set_color_all,
};
# elif defined(IS31FL3737)
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index e4c4d555e5..baa10ec416 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -727,13 +727,11 @@ static uint16_t _repeat_timer;
static uint8_t _times_remaining;
static uint16_t _dur;
-void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) {
- rgblight_blink_layer_repeat(layer, duration_ms, 1);
-}
+void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { rgblight_blink_layer_repeat(layer, duration_ms, 1); }
void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times) {
_times_remaining = times * 2;
- _dur = duration_ms;
+ _dur = duration_ms;
rgblight_set_layer_state(layer, true);
_times_remaining--;
@@ -892,7 +890,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) {
animation_status.restart = true;
}
# endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */
-# endif /* RGBLIGHT_USE_TIMER */
+# endif /* RGBLIGHT_USE_TIMER */
}
#endif /* RGBLIGHT_SPLIT */
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c
index bf942c5260..9ed0f7591b 100644
--- a/quantum/split_common/transport.c
+++ b/quantum/split_common/transport.c
@@ -240,38 +240,38 @@ typedef struct _Serial_s2m_buffer_t {
matrix_row_t smatrix[ROWS_PER_HAND];
# ifdef ENCODER_ENABLE
- uint8_t encoder_state[NUMBER_OF_ENCODERS];
+ uint8_t encoder_state[NUMBER_OF_ENCODERS];
# endif
} Serial_s2m_buffer_t;
typedef struct _Serial_m2s_buffer_t {
# ifdef SPLIT_MODS_ENABLE
- uint8_t real_mods;
- uint8_t weak_mods;
+ uint8_t real_mods;
+ uint8_t weak_mods;
# ifndef NO_ACTION_ONESHOT
- uint8_t oneshot_mods;
+ uint8_t oneshot_mods;
# endif
# endif
# ifndef DISABLE_SYNC_TIMER
- uint32_t sync_timer;
+ uint32_t sync_timer;
# endif
# ifdef SPLIT_TRANSPORT_MIRROR
- matrix_row_t mmatrix[ROWS_PER_HAND];
+ matrix_row_t mmatrix[ROWS_PER_HAND];
# endif
# ifdef BACKLIGHT_ENABLE
- uint8_t backlight_level;
+ uint8_t backlight_level;
# endif
# ifdef WPM_ENABLE
- uint8_t current_wpm;
+ uint8_t current_wpm;
# endif
# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
led_eeconfig_t led_matrix;
bool led_suspend_state;
# endif
# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- rgb_config_t rgb_matrix;
- bool rgb_suspend_state;
+ rgb_config_t rgb_matrix;
+ bool rgb_suspend_state;
# endif
} Serial_m2s_buffer_t;
@@ -363,7 +363,7 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
// TODO: if MATRIX_COLS > 8 change to unpack()
for (int i = 0; i < ROWS_PER_HAND; ++i) {
- slave_matrix[i] = serial_s2m_buffer.smatrix[i];
+ slave_matrix[i] = serial_s2m_buffer.smatrix[i];
# ifdef SPLIT_TRANSPORT_MIRROR
serial_m2s_buffer.mmatrix[i] = master_matrix[i];
# endif
@@ -380,14 +380,14 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
# ifdef WPM_ENABLE
// Write wpm to slave
- serial_m2s_buffer.current_wpm = get_current_wpm();
+ serial_m2s_buffer.current_wpm = get_current_wpm();
# endif
# ifdef SPLIT_MODS_ENABLE
- serial_m2s_buffer.real_mods = get_mods();
- serial_m2s_buffer.weak_mods = get_weak_mods();
+ serial_m2s_buffer.real_mods = get_mods();
+ serial_m2s_buffer.weak_mods = get_weak_mods();
# ifndef NO_ACTION_ONESHOT
- serial_m2s_buffer.oneshot_mods = get_oneshot_mods();
+ serial_m2s_buffer.oneshot_mods = get_oneshot_mods();
# endif
# endif
@@ -401,7 +401,7 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
# endif
# ifndef DISABLE_SYNC_TIMER
- serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
+ serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
# endif
return true;
}
@@ -416,7 +416,7 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
for (int i = 0; i < ROWS_PER_HAND; ++i) {
serial_s2m_buffer.smatrix[i] = slave_matrix[i];
# ifdef SPLIT_TRANSPORT_MIRROR
- master_matrix[i] = serial_m2s_buffer.mmatrix[i];
+ master_matrix[i] = serial_m2s_buffer.mmatrix[i];
# endif
}
# ifdef BACKLIGHT_ENABLE
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index f41665b06c..bd41d28b66 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -773,10 +773,9 @@ void register_code(uint8_t code) {
}
#endif
- else if
- IS_KEY(code) {
- // TODO: should push command_proc out of this block?
- if (command_proc(code)) return;
+ else if IS_KEY (code) {
+ // TODO: should push command_proc out of this block?
+ if (command_proc(code)) return;
#ifndef NO_ACTION_ONESHOT
/* TODO: remove
@@ -793,35 +792,33 @@ void register_code(uint8_t code) {
} else
*/
#endif
- {
- // Force a new key press if the key is already pressed
- // without this, keys with the same keycode, but different
- // modifiers will be reported incorrectly, see issue #1708
- if (is_key_pressed(keyboard_report, code)) {
- del_key(code);
- send_keyboard_report();
- }
- add_key(code);
+ {
+ // Force a new key press if the key is already pressed
+ // without this, keys with the same keycode, but different
+ // modifiers will be reported incorrectly, see issue #1708
+ if (is_key_pressed(keyboard_report, code)) {
+ del_key(code);
send_keyboard_report();
}
- }
- else if
- IS_MOD(code) {
- add_mods(MOD_BIT(code));
+ add_key(code);
send_keyboard_report();
}
+ } else if IS_MOD (code) {
+ add_mods(MOD_BIT(code));
+ send_keyboard_report();
+ }
#ifdef EXTRAKEY_ENABLE
- else if
- IS_SYSTEM(code) { host_system_send(KEYCODE2SYSTEM(code)); }
- else if
- IS_CONSUMER(code) { host_consumer_send(KEYCODE2CONSUMER(code)); }
+ else if IS_SYSTEM (code) {
+ host_system_send(KEYCODE2SYSTEM(code));
+ } else if IS_CONSUMER (code) {
+ host_consumer_send(KEYCODE2CONSUMER(code));
+ }
#endif
#ifdef MOUSEKEY_ENABLE
- else if
- IS_MOUSEKEY(code) {
- mousekey_on(code);
- mousekey_send();
- }
+ else if IS_MOUSEKEY (code) {
+ mousekey_on(code);
+ mousekey_send();
+ }
#endif
}
@@ -866,26 +863,22 @@ void unregister_code(uint8_t code) {
}
#endif
- else if
- IS_KEY(code) {
- del_key(code);
- send_keyboard_report();
- }
- else if
- IS_MOD(code) {
- del_mods(MOD_BIT(code));
- send_keyboard_report();
- }
- else if
- IS_SYSTEM(code) { host_system_send(0); }
- else if
- IS_CONSUMER(code) { host_consumer_send(0); }
+ else if IS_KEY (code) {
+ del_key(code);
+ send_keyboard_report();
+ } else if IS_MOD (code) {
+ del_mods(MOD_BIT(code));
+ send_keyboard_report();
+ } else if IS_SYSTEM (code) {
+ host_system_send(0);
+ } else if IS_CONSUMER (code) {
+ host_consumer_send(0);
+ }
#ifdef MOUSEKEY_ENABLE
- else if
- IS_MOUSEKEY(code) {
- mousekey_off(code);
- mousekey_send();
- }
+ else if IS_MOUSEKEY (code) {
+ mousekey_off(code);
+ mousekey_send();
+ }
#endif
}
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index 6c84561785..8cb4722c6e 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -77,7 +77,7 @@ extern bool disable_action_cache;
/* Code for handling one-handed key modifiers. */
#ifdef SWAP_HANDS_ENABLE
-extern bool swap_hands;
+extern bool swap_hands;
extern const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
# if (MATRIX_COLS <= 8)
typedef uint8_t swap_state_row_t;
diff --git a/tmk_core/common/chibios/sleep_led.c b/tmk_core/common/chibios/sleep_led.c
index 477056a454..1c65016a42 100644
--- a/tmk_core/common/chibios/sleep_led.c
+++ b/tmk_core/common/chibios/sleep_led.c
@@ -65,7 +65,7 @@ void sleep_led_timer_callback(void) {
/* LPTMR clock options */
# define LPTMR_CLOCK_MCGIRCLK 0 /* 4MHz clock */
-# define LPTMR_CLOCK_LPO 1 /* 1kHz clock */
+# define LPTMR_CLOCK_LPO 1 /* 1kHz clock */
# define LPTMR_CLOCK_ERCLK32K 2 /* external 32kHz crystal */
# define LPTMR_CLOCK_OSCERCLK 3 /* output from OSC */
@@ -121,7 +121,7 @@ void sleep_led_init(void) {
MCG->C2 |= MCG_C2_IRCS; // fast (4MHz) internal ref clock
# if defined(KL27) // divide the 8MHz IRC by 2, to have the same MCGIRCLK speed as others
MCG->MC |= MCG_MC_LIRC_DIV2_DIV2;
-# endif /* KL27 */
+# endif /* KL27 */
MCG->C1 |= MCG_C1_IRCLKEN; // enable internal ref clock
// to work in stop mode, also MCG_C1_IREFSTEN
// Divide 4MHz by 2^N (N=6) => 62500 irqs/sec =>
diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h
index 779973f1d6..08f4e84f94 100644
--- a/tmk_core/common/keyboard.h
+++ b/tmk_core/common/keyboard.h
@@ -70,9 +70,9 @@ void keyboard_pre_init_user(void);
void keyboard_post_init_kb(void);
void keyboard_post_init_user(void);
-void housekeeping_task(void); // To be executed by the main loop in each backend TMK protocol
-void housekeeping_task_kb(void); // To be overridden by keyboard-level code
-void housekeeping_task_user(void); // To be overridden by user/keymap-level code
+void housekeeping_task(void); // To be executed by the main loop in each backend TMK protocol
+void housekeeping_task_kb(void); // To be overridden by keyboard-level code
+void housekeeping_task_user(void); // To be overridden by user/keymap-level code
uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity
uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity
--
cgit v1.2.3
From 17d0fad7626aafef02b57156723414cb4d180d18 Mon Sep 17 00:00:00 2001
From: Ryan
Date: Tue, 8 Jun 2021 19:54:33 +1000
Subject: `spi_master` Kinetis support (#13098)
---
drivers/chibios/spi_master.c | 70 +++++++++++++++++++++++++++++++++++++++-----
drivers/chibios/spi_master.h | 19 ++++++++++--
2 files changed, 78 insertions(+), 11 deletions(-)
(limited to 'drivers')
diff --git a/drivers/chibios/spi_master.c b/drivers/chibios/spi_master.c
index 4852a6eba4..28ddcbb2ba 100644
--- a/drivers/chibios/spi_master.c
+++ b/drivers/chibios/spi_master.c
@@ -18,8 +18,13 @@
#include "timer.h"
-static pin_t currentSlavePin = NO_PIN;
-static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0};
+static pin_t currentSlavePin = NO_PIN;
+
+#if defined(K20x) || defined(KL2x)
+static SPIConfig spiConfig = {NULL, 0, 0, 0};
+#else
+static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0};
+#endif
__attribute__((weak)) void spi_init(void) {
static bool is_initialised = false;
@@ -27,15 +32,15 @@ __attribute__((weak)) void spi_init(void) {
is_initialised = true;
// Try releasing special pins for a short time
- palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_INPUT);
- palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_INPUT);
- palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_INPUT);
+ setPinInput(SPI_SCK_PIN);
+ setPinInput(SPI_MOSI_PIN);
+ setPinInput(SPI_MISO_PIN);
chThdSleepMilliseconds(10);
#if defined(USE_GPIOV1)
- palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL);
- palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL);
- palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL);
+ 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);
#else
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);
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);
@@ -58,6 +63,54 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) {
return false;
}
+#if defined(K20x) || defined(KL2x)
+ spiConfig.tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(1);
+
+ if (lsbFirst) {
+ spiConfig.tar0 |= SPIx_CTARn_LSBFE;
+ }
+
+ switch (mode) {
+ case 0:
+ break;
+ case 1:
+ spiConfig.tar0 |= SPIx_CTARn_CPHA;
+ break;
+ case 2:
+ spiConfig.tar0 |= SPIx_CTARn_CPOL;
+ break;
+ case 3:
+ spiConfig.tar0 |= SPIx_CTARn_CPHA | SPIx_CTARn_CPOL;
+ break;
+ }
+
+ switch (roundedDivisor) {
+ case 2:
+ spiConfig.tar0 |= SPIx_CTARn_BR(0);
+ break;
+ case 4:
+ spiConfig.tar0 |= SPIx_CTARn_BR(1);
+ break;
+ case 8:
+ spiConfig.tar0 |= SPIx_CTARn_BR(3);
+ break;
+ case 16:
+ spiConfig.tar0 |= SPIx_CTARn_BR(4);
+ break;
+ case 32:
+ spiConfig.tar0 |= SPIx_CTARn_BR(5);
+ break;
+ case 64:
+ spiConfig.tar0 |= SPIx_CTARn_BR(6);
+ break;
+ case 128:
+ spiConfig.tar0 |= SPIx_CTARn_BR(7);
+ break;
+ case 256:
+ spiConfig.tar0 |= SPIx_CTARn_BR(8);
+ break;
+ }
+#else
spiConfig.cr1 = 0;
if (lsbFirst) {
@@ -103,6 +156,7 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) {
spiConfig.cr1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0;
break;
}
+#endif
currentSlavePin = slavePin;
spiConfig.ssport = PAL_PORT(slavePin);
diff --git a/drivers/chibios/spi_master.h b/drivers/chibios/spi_master.h
index e93580e319..b5a6ef1437 100644
--- a/drivers/chibios/spi_master.h
+++ b/drivers/chibios/spi_master.h
@@ -21,6 +21,7 @@
#include
#include "gpio.h"
+#include "chibios_config.h"
#ifndef SPI_DRIVER
# define SPI_DRIVER SPID2
@@ -31,7 +32,11 @@
#endif
#ifndef SPI_SCK_PAL_MODE
-# define SPI_SCK_PAL_MODE 5
+# if defined(USE_GPIOV1)
+# define SPI_SCK_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
+# else
+# define SPI_SCK_PAL_MODE 5
+# endif
#endif
#ifndef SPI_MOSI_PIN
@@ -39,7 +44,11 @@
#endif
#ifndef SPI_MOSI_PAL_MODE
-# define SPI_MOSI_PAL_MODE 5
+# if defined(USE_GPIOV1)
+# define SPI_MOSI_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
+# else
+# define SPI_MOSI_PAL_MODE 5
+# endif
#endif
#ifndef SPI_MISO_PIN
@@ -47,7 +56,11 @@
#endif
#ifndef SPI_MISO_PAL_MODE
-# define SPI_MISO_PAL_MODE 5
+# if defined(USE_GPIOV1)
+# define SPI_MISO_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
+# else
+# define SPI_MISO_PAL_MODE 5
+# endif
#endif
typedef int16_t spi_status_t;
--
cgit v1.2.3
From 32b2ac0a807bdb088df685e6118f4c0966b6cca4 Mon Sep 17 00:00:00 2001
From: Gigahawk
Date: Wed, 9 Jun 2021 18:40:25 -0700
Subject: GMMK Pro RGB Support (#13147)
* Enable SPI1 for GMMK pro
* Setup initial boilerplate for new LED driver
* RGB matrix minimally functional
* Map full LED matrix
* Return keymap to default
* Fix printscreen LED mapping
* Reduce max brightness
* Default values for AW20216
* Add documentation for AW20216
* Disable console and warnings
* Run cformat
* Update drivers/awinic/aw20216.h
Co-authored-by: Drashna Jaelre
* make aw struct match issi struct
Co-authored-by: Drashna Jaelre
* add led location defines
Co-authored-by: Drashna Jaelre
* Use led pin definitions in keyboard.c
* Add driver indices to led map
* Fix elif typo
* Run cformat
* Update docs
* Fix typo in docs
* Document global brightness limits
Co-authored-by: Drashna Jaelre ---
common_features.mk | 9 +-
docs/feature_rgb_matrix.md | 68 ++++++++++++
drivers/awinic/aw20216.c | 166 ++++++++++++++++++++++++++++
drivers/awinic/aw20216.h | 251 +++++++++++++++++++++++++++++++++++++++++++
keyboards/gmmk/pro/config.h | 17 +++
keyboards/gmmk/pro/halconf.h | 7 ++
keyboards/gmmk/pro/mcuconf.h | 6 ++
keyboards/gmmk/pro/pro.c | 222 ++++++++++++++++++++++++++++++++++++++
keyboards/gmmk/pro/rules.mk | 2 +
quantum/rgb_matrix.h | 2 +
quantum/rgb_matrix_drivers.c | 16 +++
11 files changed, 765 insertions(+), 1 deletion(-)
create mode 100644 drivers/awinic/aw20216.c
create mode 100644 drivers/awinic/aw20216.h
create mode 100644 keyboards/gmmk/pro/halconf.h
create mode 100644 keyboards/gmmk/pro/mcuconf.h
(limited to 'drivers')
diff --git a/common_features.mk b/common_features.mk
index 1a9fd46b55..37ce928e2a 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -244,7 +244,7 @@ endif
endif
RGB_MATRIX_ENABLE ?= no
-VALID_RGB_MATRIX_TYPES := IS31FL3731 IS31FL3733 IS31FL3737 IS31FL3741 WS2812 custom
+VALID_RGB_MATRIX_TYPES := AW20216 IS31FL3731 IS31FL3733 IS31FL3737 IS31FL3741 WS2812 custom
ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes)
ifeq ($(filter $(RGB_MATRIX_DRIVER),$(VALID_RGB_MATRIX_TYPES)),)
@@ -261,6 +261,13 @@ endif
CIE1931_CURVE := yes
RGB_KEYCODES_ENABLE := yes
+ ifeq ($(strip $(RGB_MATRIX_DRIVER)), AW20216)
+ OPT_DEFS += -DAW20216 -DSTM32_SPI -DHAL_USE_SPI=TRUE
+ COMMON_VPATH += $(DRIVER_PATH)/awinic
+ SRC += aw20216.c
+ QUANTUM_LIB_SRC += spi_master.c
+ endif
+
ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3731)
OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE
COMMON_VPATH += $(DRIVER_PATH)/issi
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index 169443fb85..afd72fecff 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -227,6 +227,74 @@ Configure the hardware via your `config.h`:
#define DRIVER_LED_TOTAL 70
```
+---
+### AW20216 :id=aw20216
+There is basic support for addressable RGB matrix lighting with the SPI AW20216 RGB controller. To enable it, add this to your `rules.mk`:
+
+```makefile
+RGB_MATRIX_ENABLE = yes
+RGB_MATRIX_DRIVER = AW20216
+```
+
+You can use up to 2 AW20216 IC's. Do not specify `DRIVER__xxx` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
+
+| Variable | Description | Default |
+|----------|-------------|---------|
+| `DRIVER_1_CS` | (Required) MCU pin connected to first RGB driver chip select line | B13 |
+| `DRIVER_2_CS` | (Optional) MCU pin connected to second RGB driver chip select line | |
+| `DRIVER_1_EN` | (Required) MCU pin connected to first RGB driver hardware enable line | C13 |
+| `DRIVER_2_EN` | (Optional) MCU pin connected to second RGB driver hardware enable line | |
+| `DRIVER_1_LED_TOTAL` | (Required) How many RGB lights are connected to first RGB driver | |
+| `DRIVER_2_LED_TOTAL` | (Optional) How many RGB lights are connected to second RGB driver | |
+| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | |
+| `DRIVER_LED_TOTAL` | (Required) How many RGB lights are present across all drivers | |
+| `AW_SCALING_MAX` | (Optional) LED current scaling value (0-255, higher values mean LED is brighter at full PWM) | 150 |
+| `AW_GLOBAL_CURRENT_MAX` | (Optional) Driver global current limit (0-255, higher values means the driver may consume more power) | 150 |
+
+Here is an example using 2 drivers.
+
+```c
+#define DRIVER_1_CS B13
+#define DRIVER_2_CS B14
+// Hardware enable lines may be connected to the same pin
+#define DRIVER_1_EN C13
+#define DRIVER_2_EN C13
+
+#define DRIVER_COUNT 2
+#define DRIVER_1_LED_TOTAL 66
+#define DRIVER_2_LED_TOTAL 32
+#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
+```
+
+!> Note the parentheses, this is so when `DRIVER_LED_TOTAL` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`.
+
+Define these arrays listing all the LEDs in your `.c`:
+
+```c
+const aw_led g_aw_leds[DRIVER_LED_TOTAL] = {
+/* Each AW20216 channel is controlled by a register at some offset between 0x00
+ * and 0xD7 inclusive.
+ * See drivers/awinic/aw20216.h for the mapping between register offsets and
+ * driver pin locations.
+ * driver
+ * | R location
+ * | | G location
+ * | | | B location
+ * | | | | */
+ { 0, CS1_SW1, CS2_SW1, CS3_SW1 },
+ { 0, CS4_SW1, CS5_SW1, CS6_SW1 },
+ { 0, CS7_SW1, CS8_SW1, CS9_SW1 },
+ { 0, CS10_SW1, CS11_SW1, CS12_SW1 },
+ { 0, CS13_SW1, CS14_SW1, CS15_SW1 },
+ ...
+ { 1, CS1_SW1, CS2_SW1, CS3_SW1 },
+ { 1, CS13_SW1, CS14_SW1, CS15_SW1 },
+ { 1, CS16_SW1, CS17_SW1, CS18_SW1 },
+ { 1, CS4_SW2, CS5_SW2, CS6_SW2 },
+ ...
+};
+```
+
---
From this point forward the configuration is the same for all the drivers. The `led_config_t` struct provides a key electrical matrix to led index lookup table, what the physical position of each LED is on the board, and what type of key or usage the LED if the LED represents. Here is a brief example:
diff --git a/drivers/awinic/aw20216.c b/drivers/awinic/aw20216.c
new file mode 100644
index 0000000000..236c42a3cd
--- /dev/null
+++ b/drivers/awinic/aw20216.c
@@ -0,0 +1,166 @@
+/* Copyright 2021 Jasper Chan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "aw20216.h"
+#include "spi_master.h"
+
+/* The AW20216 appears to be somewhat similar to the IS31FL743, although quite
+ * a few things are different, such as the command byte format and page ordering.
+ * The LED addresses start from 0x00 instead of 0x01.
+ */
+#define AWINIC_ID 0b1010 << 4
+
+#define AW_PAGE_FUNCTION 0x00 << 1 // PG0, Function registers
+#define AW_PAGE_PWM 0x01 << 1 // PG1, LED PWM control
+#define AW_PAGE_SCALING 0x02 << 1 // PG2, LED current scaling control
+#define AW_PAGE_PATCHOICE 0x03 << 1 // PG3, Pattern choice?
+#define AW_PAGE_PWMSCALING 0x04 << 1 // PG4, LED PWM + Scaling control?
+
+#define AW_WRITE 0
+#define AW_READ 1
+
+#define AW_REG_CONFIGURATION 0x00 // PG0
+#define AW_REG_GLOBALCURRENT 0x01 // PG0
+
+// Default value of AW_REG_CONFIGURATION
+// D7:D4 = 1011, SWSEL (SW1~SW12 active)
+// D3 = 0?, reserved (apparently this should be 1 but it doesn't seem to matter)
+// D2:D1 = 00, OSDE (open/short detection enable)
+// D0 = 0, CHIPEN (write 1 to enable LEDs when hardware enable pulled high)
+#define AW_CONFIG_DEFAULT 0b10110000
+#define AW_CHIPEN 1
+
+#ifndef AW_SCALING_MAX
+# define AW_SCALING_MAX 150
+#endif
+
+#ifndef AW_GLOBAL_CURRENT_MAX
+# define AW_GLOBAL_CURRENT_MAX 150
+#endif
+
+#ifndef DRIVER_1_CS
+# define DRIVER_1_CS B13
+#endif
+
+#ifndef DRIVER_1_EN
+# define DRIVER_1_EN C13
+#endif
+
+uint8_t g_spi_transfer_buffer[20] = {0};
+aw_led g_pwm_buffer[DRIVER_LED_TOTAL];
+bool g_pwm_buffer_update_required[DRIVER_LED_TOTAL];
+
+bool AW20216_write_register(pin_t slave_pin, uint8_t page, uint8_t reg, uint8_t data) {
+ // Do we need to call spi_stop() if this fails?
+ if (!spi_start(slave_pin, false, 0, 16)) {
+ return false;
+ }
+
+ g_spi_transfer_buffer[0] = (AWINIC_ID | page | AW_WRITE);
+ g_spi_transfer_buffer[1] = reg;
+ g_spi_transfer_buffer[2] = data;
+
+ if (spi_transmit(g_spi_transfer_buffer, 3) != SPI_STATUS_SUCCESS) {
+ spi_stop();
+ return false;
+ }
+ spi_stop();
+ return true;
+}
+
+bool AW20216_init_scaling(void) {
+ // Set constant current to the max, control brightness with PWM
+ aw_led led;
+ for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
+ led = g_aw_leds[i];
+ if (led.driver == 0) {
+ AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.r, AW_SCALING_MAX);
+ AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.g, AW_SCALING_MAX);
+ AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.b, AW_SCALING_MAX);
+ }
+#ifdef DRIVER_2_CS
+ else if (led.driver == 1) {
+ AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.r, AW_SCALING_MAX);
+ AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.g, AW_SCALING_MAX);
+ AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.b, AW_SCALING_MAX);
+ }
+#endif
+ }
+ return true;
+}
+
+bool AW20216_soft_enable(void) {
+ AW20216_write_register(DRIVER_1_CS, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN);
+#ifdef DRIVER_2_CS
+ AW20216_write_register(DRIVER_2_CS, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN);
+#endif
+ return true;
+}
+
+void AW20216_update_pwm(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ aw_led led = g_aw_leds[index];
+ if (led.driver == 0) {
+ AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.r, red);
+ AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.g, green);
+ AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.b, blue);
+ }
+#ifdef DRIVER_2_CS
+ else if (led.driver == 1) {
+ AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.r, red);
+ AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.g, green);
+ AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.b, blue);
+ }
+#endif
+ return;
+}
+
+void AW20216_init(void) {
+ // All LEDs should start with all scaling and PWM registers as off
+ setPinOutput(DRIVER_1_EN);
+ writePinHigh(DRIVER_1_EN);
+ AW20216_write_register(DRIVER_1_CS, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX);
+#ifdef DRIVER_2_EN
+ setPinOutput(DRIVER_2_EN);
+ writePinHigh(DRIVER_2_EN);
+ AW20216_write_register(DRIVER_2_CS, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX);
+#endif
+ AW20216_init_scaling();
+ AW20216_soft_enable();
+ return;
+}
+
+void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ g_pwm_buffer[index].r = red;
+ g_pwm_buffer[index].g = green;
+ g_pwm_buffer[index].b = blue;
+ g_pwm_buffer_update_required[index] = true;
+ return;
+}
+void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
+ AW20216_set_color(i, red, green, blue);
+ }
+ return;
+}
+void AW20216_update_pwm_buffers(void) {
+ for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
+ if (g_pwm_buffer_update_required[i]) {
+ AW20216_update_pwm(i, g_pwm_buffer[i].r, g_pwm_buffer[i].g, g_pwm_buffer[i].b);
+ g_pwm_buffer_update_required[i] = false;
+ }
+ }
+ return;
+}
diff --git a/drivers/awinic/aw20216.h b/drivers/awinic/aw20216.h
new file mode 100644
index 0000000000..9c6865cc82
--- /dev/null
+++ b/drivers/awinic/aw20216.h
@@ -0,0 +1,251 @@
+/* Copyright 2021 Jasper Chan (Gigahawk)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+typedef struct aw_led {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} aw_led;
+
+extern const aw_led g_aw_leds[DRIVER_LED_TOTAL];
+
+void AW20216_init(void);
+void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+void AW20216_update_pwm_buffers(void);
+
+#define CS1_SW1 0x00
+#define CS2_SW1 0x01
+#define CS3_SW1 0x02
+#define CS4_SW1 0x03
+#define CS5_SW1 0x04
+#define CS6_SW1 0x05
+#define CS7_SW1 0x06
+#define CS8_SW1 0x07
+#define CS9_SW1 0x08
+#define CS10_SW1 0x09
+#define CS11_SW1 0x0A
+#define CS12_SW1 0x0B
+#define CS13_SW1 0x0C
+#define CS14_SW1 0x0D
+#define CS15_SW1 0x0E
+#define CS16_SW1 0x0F
+#define CS17_SW1 0x10
+#define CS18_SW1 0x11
+#define CS1_SW2 0x12
+#define CS2_SW2 0x13
+#define CS3_SW2 0x14
+#define CS4_SW2 0x15
+#define CS5_SW2 0x16
+#define CS6_SW2 0x17
+#define CS7_SW2 0x18
+#define CS8_SW2 0x19
+#define CS9_SW2 0x1A
+#define CS10_SW2 0x1B
+#define CS11_SW2 0x1C
+#define CS12_SW2 0x1D
+#define CS13_SW2 0x1E
+#define CS14_SW2 0x1F
+#define CS15_SW2 0x20
+#define CS16_SW2 0x21
+#define CS17_SW2 0x22
+#define CS18_SW2 0x23
+#define CS1_SW3 0x24
+#define CS2_SW3 0x25
+#define CS3_SW3 0x26
+#define CS4_SW3 0x27
+#define CS5_SW3 0x28
+#define CS6_SW3 0x29
+#define CS7_SW3 0x2A
+#define CS8_SW3 0x2B
+#define CS9_SW3 0x2C
+#define CS10_SW3 0x2D
+#define CS11_SW3 0x2E
+#define CS12_SW3 0x2F
+#define CS13_SW3 0x30
+#define CS14_SW3 0x31
+#define CS15_SW3 0x32
+#define CS16_SW3 0x33
+#define CS17_SW3 0x34
+#define CS18_SW3 0x35
+#define CS1_SW4 0x36
+#define CS2_SW4 0x37
+#define CS3_SW4 0x38
+#define CS4_SW4 0x39
+#define CS5_SW4 0x3A
+#define CS6_SW4 0x3B
+#define CS7_SW4 0x3C
+#define CS8_SW4 0x3D
+#define CS9_SW4 0x3E
+#define CS10_SW4 0x3F
+#define CS11_SW4 0x40
+#define CS12_SW4 0x41
+#define CS13_SW4 0x42
+#define CS14_SW4 0x43
+#define CS15_SW4 0x44
+#define CS16_SW4 0x45
+#define CS17_SW4 0x46
+#define CS18_SW4 0x47
+#define CS1_SW5 0x48
+#define CS2_SW5 0x49
+#define CS3_SW5 0x4A
+#define CS4_SW5 0x4B
+#define CS5_SW5 0x4C
+#define CS6_SW5 0x4D
+#define CS7_SW5 0x4E
+#define CS8_SW5 0x4F
+#define CS9_SW5 0x50
+#define CS10_SW5 0x51
+#define CS11_SW5 0x52
+#define CS12_SW5 0x53
+#define CS13_SW5 0x54
+#define CS14_SW5 0x55
+#define CS15_SW5 0x56
+#define CS16_SW5 0x57
+#define CS17_SW5 0x58
+#define CS18_SW5 0x59
+#define CS1_SW6 0x5A
+#define CS2_SW6 0x5B
+#define CS3_SW6 0x5C
+#define CS4_SW6 0x5D
+#define CS5_SW6 0x5E
+#define CS6_SW6 0x5F
+#define CS7_SW6 0x60
+#define CS8_SW6 0x61
+#define CS9_SW6 0x62
+#define CS10_SW6 0x63
+#define CS11_SW6 0x64
+#define CS12_SW6 0x65
+#define CS13_SW6 0x66
+#define CS14_SW6 0x67
+#define CS15_SW6 0x68
+#define CS16_SW6 0x69
+#define CS17_SW6 0x6A
+#define CS18_SW6 0x6B
+#define CS1_SW7 0x6C
+#define CS2_SW7 0x6D
+#define CS3_SW7 0x6E
+#define CS4_SW7 0x6F
+#define CS5_SW7 0x70
+#define CS6_SW7 0x71
+#define CS7_SW7 0x72
+#define CS8_SW7 0x73
+#define CS9_SW7 0x74
+#define CS10_SW7 0x75
+#define CS11_SW7 0x76
+#define CS12_SW7 0x77
+#define CS13_SW7 0x78
+#define CS14_SW7 0x79
+#define CS15_SW7 0x7A
+#define CS16_SW7 0x7B
+#define CS17_SW7 0x7C
+#define CS18_SW7 0x7D
+#define CS1_SW8 0x7E
+#define CS2_SW8 0x7F
+#define CS3_SW8 0x80
+#define CS4_SW8 0x81
+#define CS5_SW8 0x82
+#define CS6_SW8 0x83
+#define CS7_SW8 0x84
+#define CS8_SW8 0x85
+#define CS9_SW8 0x86
+#define CS10_SW8 0x87
+#define CS11_SW8 0x88
+#define CS12_SW8 0x89
+#define CS13_SW8 0x8A
+#define CS14_SW8 0x8B
+#define CS15_SW8 0x8C
+#define CS16_SW8 0x8D
+#define CS17_SW8 0x8E
+#define CS18_SW8 0x8F
+#define CS1_SW9 0x90
+#define CS2_SW9 0x91
+#define CS3_SW9 0x92
+#define CS4_SW9 0x93
+#define CS5_SW9 0x94
+#define CS6_SW9 0x95
+#define CS7_SW9 0x96
+#define CS8_SW9 0x97
+#define CS9_SW9 0x98
+#define CS10_SW9 0x99
+#define CS11_SW9 0x9A
+#define CS12_SW9 0x9B
+#define CS13_SW9 0x9C
+#define CS14_SW9 0x9D
+#define CS15_SW9 0x9E
+#define CS16_SW9 0x9F
+#define CS17_SW9 0xA0
+#define CS18_SW9 0xA1
+#define CS1_SW10 0xA2
+#define CS2_SW10 0xA3
+#define CS3_SW10 0xA4
+#define CS4_SW10 0xA5
+#define CS5_SW10 0xA6
+#define CS6_SW10 0xA7
+#define CS7_SW10 0xA8
+#define CS8_SW10 0xA9
+#define CS9_SW10 0xAA
+#define CS10_SW10 0xAB
+#define CS11_SW10 0xAC
+#define CS12_SW10 0xAD
+#define CS13_SW10 0xAE
+#define CS14_SW10 0xAF
+#define CS15_SW10 0xB0
+#define CS16_SW10 0xB1
+#define CS17_SW10 0xB2
+#define CS18_SW10 0xB3
+#define CS1_SW11 0xB4
+#define CS2_SW11 0xB5
+#define CS3_SW11 0xB6
+#define CS4_SW11 0xB7
+#define CS5_SW11 0xB8
+#define CS6_SW11 0xB9
+#define CS7_SW11 0xBA
+#define CS8_SW11 0xBB
+#define CS9_SW11 0xBC
+#define CS10_SW11 0xBD
+#define CS11_SW11 0xBE
+#define CS12_SW11 0xBF
+#define CS13_SW11 0xC0
+#define CS14_SW11 0xC1
+#define CS15_SW11 0xC2
+#define CS16_SW11 0xC3
+#define CS17_SW11 0xC4
+#define CS18_SW11 0xC5
+#define CS1_SW12 0xC6
+#define CS2_SW12 0xC7
+#define CS3_SW12 0xC8
+#define CS4_SW12 0xC9
+#define CS5_SW12 0xCA
+#define CS6_SW12 0xCB
+#define CS7_SW12 0xCC
+#define CS8_SW12 0xCD
+#define CS9_SW12 0xCE
+#define CS10_SW12 0xCF
+#define CS11_SW12 0xD0
+#define CS12_SW12 0xD1
+#define CS13_SW12 0xD2
+#define CS14_SW12 0xD3
+#define CS15_SW12 0xD4
+#define CS16_SW12 0xD5
+#define CS17_SW12 0xD6
+#define CS18_SW12 0xD7
diff --git a/keyboards/gmmk/pro/config.h b/keyboards/gmmk/pro/config.h
index ab3c7a7a21..64062becea 100644
--- a/keyboards/gmmk/pro/config.h
+++ b/keyboards/gmmk/pro/config.h
@@ -46,3 +46,20 @@
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE
+
+/* SPI Config for LED Driver */
+#define SPI_DRIVER SPID1
+#define SPI_SCK_PIN A5
+#define SPI_MOSI_PIN A6
+#define SPI_MISO_PIN A7
+
+#define DRIVER_1_CS B13
+#define DRIVER_2_CS B14
+#define DRIVER_1_EN C13
+#define DRIVER_2_EN C13
+
+#define DRIVER_COUNT 2
+#define DRIVER_1_LED_TOTAL 66
+#define DRIVER_2_LED_TOTAL 32
+#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
+
diff --git a/keyboards/gmmk/pro/halconf.h b/keyboards/gmmk/pro/halconf.h
new file mode 100644
index 0000000000..23ecb202a1
--- /dev/null
+++ b/keyboards/gmmk/pro/halconf.h
@@ -0,0 +1,7 @@
+#pragma once
+
+#define HAL_USE_SPI TRUE
+#define SPI_USE_WAIT TRUE
+#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
+
+#include_next
diff --git a/keyboards/gmmk/pro/mcuconf.h b/keyboards/gmmk/pro/mcuconf.h
new file mode 100644
index 0000000000..bb1c0acde2
--- /dev/null
+++ b/keyboards/gmmk/pro/mcuconf.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#include_next
+
+#undef STM32_SPI_USE_SPI1
+#define STM32_SPI_USE_SPI1 TRUE
diff --git a/keyboards/gmmk/pro/pro.c b/keyboards/gmmk/pro/pro.c
index 816d089a58..3a343f2237 100644
--- a/keyboards/gmmk/pro/pro.c
+++ b/keyboards/gmmk/pro/pro.c
@@ -14,3 +14,225 @@
* along with this program. If not, see .
*/
#include "pro.h"
+
+#ifdef RGB_MATRIX_ENABLE
+led_config_t g_led_config = { {
+ { 4, NO_LED, NO_LED, 97, 65, 79, 5, 28 },
+ { 8, 2, 9, 0, 10, 75, 1, 7 },
+ { 14, 3, 15, NO_LED, 16, 86, 6, 13 },
+ { 20, 18, 21, 23, 22, 94, 12, 19 },
+ { 25, 30, 26, 31, 27, 32, 29, 24 },
+ { 41, 36, 42, 37, 43, 38, 35, 40 },
+ { 46, 89, 47, 34, 48, 72, 78, 45 },
+ { 52, 39, 53, 101, 54, 82, 44, 51 },
+ { 58, 63, 59, 64, NO_LED, 60, 62, 57 },
+ { 11, 90, 55, 17, 33, 49, NO_LED, 69 },
+ { NO_LED, 85, 93, 61, 100, 66, 50, 56 }
+}, {
+ { 0, 0 }, // 0, ESC, k13
+ { 0, 15 }, // 1, ~, k16
+ { 4, 26 }, // 2, Tab, k11
+ { 5, 38 }, // 3, Caps, k21
+ { 9, 49 }, // 4, Sh_L, k00
+ { 2, 61 }, // 5, Ct_L, k06
+ { 18, 0 }, // 6, F1, k26
+ { 14, 15 }, // 7, 1, k17
+ { 22, 26 }, // 8, Q, k10
+ { 25, 38 }, // 9, A, k12
+ { 33, 49 }, // 10, Z, k14
+ { 20, 61 }, // 11, Win_L, k90
+ { 33, 0 }, // 12, F2, k36
+ { 29, 15 }, // 13, 2, k27
+ { 36, 26 }, // 14, W, k20
+ { 40, 38 }, // 15, S, k22
+ { 47, 49 }, // 16, X, k24
+ { 38, 61 }, // 17, Alt_L, k93
+ { 47, 0 }, // 18, F3, k31
+ { 43, 15 }, // 19, 3, k37
+ { 51, 26 }, // 20, E, k30
+ { 54, 38 }, // 21, D, k32
+ { 61, 49 }, // 22, C, k34
+ { 61, 0 }, // 23, F4, k33
+ { 58, 15 }, // 24, 4, k47
+ { 65, 26 }, // 25, R, k40
+ { 69, 38 }, // 26, F, k42
+ { 76, 49 }, // 27, V, k44
+ { 79, 0 }, // 28, F5, k07
+ { 72, 15 }, // 29, 5, k46
+ { 79, 26 }, // 30, T, k41
+ { 83, 38 }, // 31, G, k43
+ { 90, 49 }, // 32, B, k45
+ { 92, 61 }, // 33, SPACE, k94
+ { 94, 0 }, // 34, F6, k63
+ { 87, 15 }, // 35, 6, k56
+ { 94, 26 }, // 36, Y, k51
+ { 98, 38 }, // 37, H, k53
+ { 105, 49 }, // 38, N, k55
+ { 108, 0 }, // 39, F7, k71
+ { 101, 15 }, // 40, 7, k57
+ { 108, 26 }, // 41, U, k50
+ { 112, 38 }, // 42, J, k52
+ { 119, 49 }, // 43, M, k54
+ { 123, 0 }, // 44, F8, k76
+ { 116, 15 }, // 45, 8, k67
+ { 123, 26 }, // 46, I, k60
+ { 126, 38 }, // 47, K, k62
+ { 134, 49 }, // 48, ,, k64
+ { 145, 61 }, // 49, Alt_R, k95
+ { 141, 0 }, // 50, F9, ka6
+ { 130, 15 }, // 51, 9, k77
+ { 137, 26 }, // 52, O, k70
+ { 141, 38 }, // 53, L, k72
+ { 148, 49 }, // 54, ., k74
+ { 159, 61 }, // 55, FN, k92
+ { 155, 0 }, // 56, F10, ka7
+ { 145, 15 }, // 57, 0, k87
+ { 152, 26 }, // 58, P, k80
+ { 155, 38 }, // 59, ;, k82
+ { 163, 49 }, // 60, ?, k85
+ { 170, 0 }, // 61, F11, ka3
+ { 159, 15 }, // 62, -, k86
+ { 166, 26 }, // 63, [, k81
+ { 170, 38 }, // 64, ", k83
+ { 173, 61 }, // 65, Ct_R, k04
+ { 184, 0 }, // 66, F12, ka5
+ { 0, 8 }, // 67, LED, l01
+ { 224, 8 }, // 68, LED, l11
+ { 202, 0 }, // 69, Prt, k97
+ { 0, 15 }, // 70, LED, l02
+ { 224, 15 }, // 71, LED, l12
+ { 224, 15 }, // 72, Del, k65
+ { 0, 21 }, // 73, LED, l03
+ { 224, 21 }, // 74, LED, l13
+ { 224, 26 }, // 75, PgUp, k15
+ { 0, 28 }, // 76, LED, l04
+ { 224, 28 }, // 77, LED, l14
+ { 173, 15 }, // 78, =, k66
+ { 220, 64 }, // 79, Right, k05
+ { 0, 35 }, // 80, LED, l05
+ { 224, 35 }, // 81, LED, l15
+ { 224, 49 }, // 82, End, k75
+ { 0, 42 }, // 83, LED, l06
+ { 224, 42 }, // 84, LED, l16
+ { 195, 15 }, // 85, BSpc, ka1
+ { 224, 38 }, // 86, PgDn, k25
+ { 0, 48 }, // 87, LED, l07
+ { 224, 48 }, // 88, LED, l17
+ { 181, 26 }, // 89, ], k61
+ { 182, 49 }, // 90, Sh_R, k91
+ { 0, 55 }, // 91, LED, l08
+ { 224, 55 }, // 92, LED, l18
+ { 199, 26 }, // 93, \, ka2
+ { 206, 52 }, // 94, Up, k35
+ { 191, 64 }, // 95, Left, k03
+ { 193, 38 }, // 96, Enter, ka4
+ { 206, 64 } // 97, Down, k73
+}, {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 4, 2, 2, 4, 2, 2,
+ 4, 2, 2, 4, 4, 2, 2, 4, 2, 2, 4, 4, 2, 2, 4, 4, 2, 2, 4, 4, 4, 4, 4
+} };
+
+const aw_led g_aw_leds[DRIVER_LED_TOTAL] = {
+ { 0, CS1_SW1, CS2_SW1, CS3_SW1 }, // 0, ESC, k13
+ { 0, CS4_SW1, CS5_SW1, CS6_SW1 }, // 1, ~, k16
+ { 0, CS7_SW1, CS8_SW1, CS9_SW1 }, // 2, Tab, k11
+ { 0, CS10_SW1, CS11_SW1, CS12_SW1 }, // 3, Caps, k21
+ { 0, CS13_SW1, CS14_SW1, CS15_SW1 }, // 4, Sh_L, k00
+ { 0, CS16_SW1, CS17_SW1, CS18_SW1 }, // 5, Ct_L, k06
+ { 0, CS1_SW2, CS2_SW2, CS3_SW2 }, // 6, F1, k26
+ { 0, CS4_SW2, CS5_SW2, CS6_SW2 }, // 7, 1, k17
+ { 0, CS7_SW2, CS8_SW2, CS9_SW2 }, // 8, Q, k10
+ { 0, CS10_SW2, CS11_SW2, CS12_SW2 }, // 9, A, k12
+ { 0, CS13_SW2, CS14_SW2, CS15_SW2 }, // 10, Z, k14
+ { 0, CS16_SW2, CS17_SW2, CS18_SW2 }, // 11, Win_L, k90
+ { 0, CS1_SW3, CS2_SW3, CS3_SW3 }, // 12, F2, k36
+ { 0, CS4_SW3, CS5_SW3, CS6_SW3 }, // 13, 2, k27
+ { 0, CS7_SW3, CS8_SW3, CS9_SW3 }, // 14, W, k20
+ { 0, CS10_SW3, CS11_SW3, CS12_SW3 }, // 15, S, k22
+ { 0, CS13_SW3, CS14_SW3, CS15_SW3 }, // 16, X, k24
+ { 0, CS16_SW3, CS17_SW3, CS18_SW3 }, // 17, Alt_L, k93
+ { 0, CS1_SW4, CS2_SW4, CS3_SW4 }, // 18, F3, k31
+ { 0, CS4_SW4, CS5_SW4, CS6_SW4 }, // 19, 3, k37
+ { 0, CS7_SW4, CS8_SW4, CS9_SW4 }, // 20, E, k30
+ { 0, CS10_SW4, CS11_SW4, CS12_SW4 }, // 21, D, k32
+ { 0, CS13_SW4, CS14_SW4, CS15_SW4 }, // 22, C, k34
+ { 0, CS1_SW5, CS2_SW5, CS3_SW5 }, // 23, F4, k33
+ { 0, CS4_SW5, CS5_SW5, CS6_SW5 }, // 24, 4, k47
+ { 0, CS7_SW5, CS8_SW5, CS9_SW5 }, // 25, R, k40
+ { 0, CS10_SW5, CS11_SW5, CS12_SW5 }, // 26, F, k42
+ { 0, CS13_SW5, CS14_SW5, CS15_SW5 }, // 27, V, k44
+ { 0, CS1_SW6, CS2_SW6, CS3_SW6 }, // 28, F5, k07
+ { 0, CS4_SW6, CS5_SW6, CS6_SW6 }, // 29, 5, k46
+ { 0, CS7_SW6, CS8_SW6, CS9_SW6 }, // 30, T, k41
+ { 0, CS10_SW6, CS11_SW6, CS12_SW6 }, // 31, G, k43
+ { 0, CS13_SW6, CS14_SW6, CS15_SW6 }, // 32, B, k45
+ { 0, CS16_SW6, CS17_SW6, CS18_SW6 }, // 33, SPACE, k94
+ { 0, CS1_SW7, CS2_SW7, CS3_SW7 }, // 34, F6, k63
+ { 0, CS4_SW7, CS5_SW7, CS6_SW7 }, // 35, 6, k56
+ { 0, CS7_SW7, CS8_SW7, CS9_SW7 }, // 36, Y, k51
+ { 0, CS10_SW7, CS11_SW7, CS12_SW7 }, // 37, H, k53
+ { 0, CS13_SW7, CS14_SW7, CS15_SW7 }, // 38, N, k55
+ { 0, CS1_SW8, CS2_SW8, CS3_SW8 }, // 39, F7, k71
+ { 0, CS4_SW8, CS5_SW8, CS6_SW8 }, // 40, 7, k57
+ { 0, CS7_SW8, CS8_SW8, CS9_SW8 }, // 41, U, k50
+ { 0, CS10_SW8, CS11_SW8, CS12_SW8 }, // 42, J, k52
+ { 0, CS13_SW8, CS14_SW8, CS15_SW8 }, // 43, M, k54
+ { 0, CS1_SW9, CS2_SW9, CS3_SW9 }, // 44, F8, k76
+ { 0, CS4_SW9, CS5_SW9, CS6_SW9 }, // 45, 8, k67
+ { 0, CS7_SW9, CS8_SW9, CS9_SW9 }, // 46, I, k60
+ { 0, CS10_SW9, CS11_SW9, CS12_SW9 }, // 47, K, k62
+ { 0, CS13_SW9, CS14_SW9, CS15_SW9 }, // 48, ,, k64
+ { 0, CS16_SW9, CS17_SW9, CS18_SW9 }, // 49, Alt_R, k95
+ { 0, CS1_SW10, CS2_SW10, CS3_SW10 }, // 50, F9, ka6
+ { 0, CS4_SW10, CS5_SW10, CS6_SW10 }, // 51, 9, k77
+ { 0, CS7_SW10, CS8_SW10, CS9_SW10 }, // 52, O, k70
+ { 0, CS10_SW10, CS11_SW10, CS12_SW10 }, // 53, L, k72
+ { 0, CS13_SW10, CS14_SW10, CS15_SW10 }, // 54, ., k74
+ { 0, CS16_SW10, CS17_SW10, CS18_SW10 }, // 55, FN, k92
+ { 0, CS1_SW11, CS2_SW11, CS3_SW11 }, // 56, F10, ka7
+ { 0, CS4_SW11, CS5_SW11, CS6_SW11 }, // 57, 0, k87
+ { 0, CS7_SW11, CS8_SW11, CS9_SW11 }, // 58, P, k80
+ { 0, CS10_SW11, CS11_SW11, CS12_SW11 }, // 59, ;, k82
+ { 0, CS13_SW11, CS14_SW11, CS15_SW11 }, // 60, ?, k85
+ { 0, CS1_SW12, CS2_SW12, CS3_SW12 }, // 61, F11, ka3
+ { 0, CS4_SW12, CS5_SW12, CS6_SW12 }, // 62, -, k86
+ { 0, CS7_SW12, CS8_SW12, CS9_SW12 }, // 63, [, k81
+ { 0, CS10_SW12, CS11_SW12, CS12_SW12 }, // 64, ", k83
+ { 0, CS16_SW12, CS17_SW12, CS18_SW12 }, // 65, Ct_R, k04
+
+ { 1, CS1_SW1, CS2_SW1, CS3_SW1 }, // 66, F12, ka5
+ { 1, CS13_SW1, CS14_SW1, CS15_SW1 }, // 67, LED, l01
+ { 1, CS16_SW1, CS17_SW1, CS18_SW1 }, // 68, LED, l11
+ { 1, CS4_SW2, CS5_SW2, CS6_SW2 }, // 69, Prt, k97
+ { 1, CS13_SW2, CS14_SW2, CS15_SW2 }, // 70, LED, l02
+ { 1, CS16_SW2, CS17_SW2, CS18_SW2 }, // 71, LED, l12
+ { 1, CS4_SW3, CS5_SW3, CS6_SW3 }, // 72, Del, k65
+ { 1, CS13_SW3, CS14_SW3, CS15_SW3 }, // 73, LED, l03
+ { 1, CS16_SW3, CS17_SW3, CS18_SW3 }, // 74, LED, l13
+ { 1, CS4_SW4, CS5_SW4, CS6_SW4 }, // 75, PgUp, k15
+ { 1, CS13_SW4, CS14_SW4, CS15_SW4 }, // 76, LED, l04
+ { 1, CS16_SW4, CS17_SW4, CS18_SW4 }, // 77, LED, l14
+ { 1, CS1_SW5, CS2_SW5, CS3_SW5 }, // 78, =, k66
+ { 1, CS10_SW5, CS11_SW5, CS12_SW5 }, // 79, Right, k05
+ { 1, CS13_SW5, CS14_SW5, CS15_SW5 }, // 80, LED, l05
+ { 1, CS16_SW5, CS17_SW5, CS18_SW5 }, // 81, LED, l15
+ { 1, CS4_SW6, CS5_SW6, CS6_SW6 }, // 82, End, k75
+ { 1, CS13_SW6, CS14_SW6, CS15_SW6 }, // 83, LED, l06
+ { 1, CS16_SW6, CS17_SW6, CS18_SW6 }, // 84, LED, l16
+ { 1, CS1_SW7, CS2_SW7, CS3_SW7 }, // 85, BSpc, ka1
+ { 1, CS4_SW7, CS5_SW7, CS6_SW7 }, // 86, PgDn, k25
+ { 1, CS13_SW7, CS14_SW7, CS15_SW7 }, // 87, LED, l07
+ { 1, CS16_SW7, CS17_SW7, CS18_SW7 }, // 88, LED, l17
+ { 1, CS1_SW8, CS2_SW8, CS3_SW8 }, // 89, ], k61
+ { 1, CS4_SW8, CS5_SW8, CS6_SW8 }, // 90, Sh_R, k91
+ { 1, CS13_SW8, CS14_SW8, CS15_SW8 }, // 91, LED, l08
+ { 1, CS16_SW8, CS17_SW8, CS18_SW8 }, // 92, LED, l18
+ { 1, CS1_SW9, CS2_SW9, CS3_SW9 }, // 93, \, ka2
+ { 1, CS4_SW9, CS5_SW9, CS6_SW9 }, // 94, Up, k35
+ { 1, CS4_SW10, CS5_SW10, CS6_SW10 }, // 95, Left, k03
+ { 1, CS1_SW11, CS2_SW11, CS3_SW11 }, // 96, Enter, ka4
+ { 1, CS4_SW11, CS5_SW11, CS6_SW11 }, // 97, Down, k73
+};
+#endif
diff --git a/keyboards/gmmk/pro/rules.mk b/keyboards/gmmk/pro/rules.mk
index b12d055a3d..6221d64082 100644
--- a/keyboards/gmmk/pro/rules.mk
+++ b/keyboards/gmmk/pro/rules.mk
@@ -21,3 +21,5 @@ RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
BLUETOOTH_ENABLE = no # Enable Bluetooth
AUDIO_ENABLE = no # Audio output
ENCODER_ENABLE = yes
+RGB_MATRIX_ENABLE = yes
+RGB_MATRIX_DRIVER = AW20216
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index a615b8422c..741a2fe446 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -33,6 +33,8 @@
# include "is31fl3737.h"
#elif defined(IS31FL3741)
# include "is31fl3741.h"
+#elif defined(AW20216)
+# include "aw20216.h"
#elif defined(WS2812)
# include "ws2812.h"
#endif
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c
index 896fa6d0ef..6a11d4791e 100644
--- a/quantum/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix_drivers.c
@@ -171,6 +171,22 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
};
# endif
+#elif defined(AW20216)
+# include "spi_master.h"
+static void init(void) {
+ spi_init();
+ AW20216_init();
+}
+
+static void flush(void) { AW20216_update_pwm_buffers(); }
+
+const rgb_matrix_driver_t rgb_matrix_driver = {
+ .init = init,
+ .flush = flush,
+ .set_color = AW20216_set_color,
+ .set_color_all = AW20216_set_color_all,
+};
+
#elif defined(WS2812)
# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_CUSTOM_DRIVER)
# pragma message "Cannot use RGBLIGHT and RGB Matrix using WS2812 at the same time."
--
cgit v1.2.3
From b2fdd4874434ef6921a436fc82d9f24909c726f8 Mon Sep 17 00:00:00 2001
From: Ryan
Date: Thu, 10 Jun 2021 17:16:09 +1000
Subject: Add ST7565 LCD driver (#13089)
Co-authored-by: Joakim Tufvegren ---
common_features.mk | 8 +
docs/_summary.md | 1 +
docs/feature_st7565.md | 270 +++++++++++++++++++++++++
drivers/lcd/st7565.c | 479 +++++++++++++++++++++++++++++++++++++++++++++
drivers/lcd/st7565.h | 215 ++++++++++++++++++++
quantum/quantum.h | 4 +
tmk_core/common/keyboard.c | 18 ++
7 files changed, 995 insertions(+)
create mode 100644 docs/feature_st7565.md
create mode 100644 drivers/lcd/st7565.c
create mode 100644 drivers/lcd/st7565.h
(limited to 'drivers')
diff --git a/common_features.mk b/common_features.mk
index 37ce928e2a..b259af46c0 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -587,6 +587,14 @@ ifeq ($(strip $(OLED_DRIVER_ENABLE)), yes)
SRC += oled_driver.c
endif
+ifeq ($(strip $(ST7565_ENABLE)), yes)
+ OPT_DEFS += -DST7565_ENABLE
+ COMMON_VPATH += $(DRIVER_PATH)/oled # For glcdfont.h
+ COMMON_VPATH += $(DRIVER_PATH)/lcd
+ QUANTUM_LIB_SRC += spi_master.c
+ SRC += st7565.c
+endif
+
include $(DRIVER_PATH)/qwiic/qwiic.mk
ifeq ($(strip $(UCIS_ENABLE)), yes)
diff --git a/docs/_summary.md b/docs/_summary.md
index 9798ef5127..4141e01e77 100644
--- a/docs/_summary.md
+++ b/docs/_summary.md
@@ -93,6 +93,7 @@
* Hardware Features
* Displays
* [HD44780 LCD Controller](feature_hd44780.md)
+ * [ST7565 LCD Driver](feature_st7565.md)
* [OLED Driver](feature_oled_driver.md)
* Lighting
* [Backlight](feature_backlight.md)
diff --git a/docs/feature_st7565.md b/docs/feature_st7565.md
new file mode 100644
index 0000000000..7db0f9ac4a
--- /dev/null
+++ b/docs/feature_st7565.md
@@ -0,0 +1,270 @@
+# ST7565 LCD Driver
+
+## Supported Hardware
+
+LCD modules using ST7565 driver IC, communicating over SPI.
+
+|Module |IC |Size |Notes |
+|------------------------------|-------|------|----------------------------------------------------------|
+|Newhaven Display NHD-C12832A1Z|ST7565R|128x32|Used by Ergodox Infinity; primary consumer of this feature|
+|Zolentech ZLE12864B |ST7565P|128x64|Requires contrast adjustment |
+
+## Usage
+
+To enable the feature, there are three steps. First, when compiling your keyboard, you'll need to add the following to your `rules.mk`:
+
+```make
+ST7565_ENABLE = yes
+```
+
+Then in your `keymap.c` file, implement the ST7565 task call. This example assumes your keymap has three layers named `_QWERTY`, `_FN` and `_ADJ`:
+
+```c
+#ifdef ST7565_ENABLE
+void st7565_task_user(void) {
+ // Host Keyboard Layer Status
+ st7565_write_P(PSTR("Layer: "), false);
+
+ switch (get_highest_layer(layer_state)) {
+ case _QWERTY:
+ st7565_write_P(PSTR("Default\n"), false);
+ break;
+ case _FN:
+ st7565_write_P(PSTR("FN\n"), false);
+ break;
+ case _ADJ:
+ st7565_write_P(PSTR("ADJ\n"), false);
+ break;
+ default:
+ // Or use the write_ln shortcut over adding '\n' to the end of your string
+ st7565_write_ln_P(PSTR("Undefined"), false);
+ }
+
+ // Host Keyboard LED Status
+ led_t led_state = host_keyboard_led_state();
+ st7565_write_P(led_state.num_lock ? PSTR("NUM ") : PSTR(" "), false);
+ st7565_write_P(led_state.caps_lock ? PSTR("CAP ") : PSTR(" "), false);
+ st7565_write_P(led_state.scroll_lock ? PSTR("SCR ") : PSTR(" "), false);
+}
+#endif
+```
+
+## Logo Example
+
+In the default font, certain ranges of characters are reserved for a QMK logo. To render this logo to the screen, use the following code example:
+
+```c
+static void render_logo(void) {
+ static const char PROGMEM qmk_logo[] = {
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94,
+ 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4,
+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0x00
+ };
+
+ st7565_write_P(qmk_logo, false);
+}
+```
+
+## Buffer Read Example
+For some purposes, you may need to read the current state of the display buffer. The `st7565_read_raw` function can be used to safely read bytes from the buffer.
+
+In this example, calling `fade_display` in the `st7565_task_user` function will slowly fade away whatever is on the screen by turning random pixels off over time.
+```c
+//Setup some mask which can be or'd with bytes to turn off pixels
+const uint8_t single_bit_masks[8] = {127, 191, 223, 239, 247, 251, 253, 254};
+
+static void fade_display(void) {
+ //Define the reader structure
+ display_buffer_reader_t reader;
+ uint8_t buff_char;
+ if (random() % 30 == 0) {
+ srand(timer_read());
+ // Fetch a pointer for the buffer byte at index 0. The return structure
+ // will have the pointer and the number of bytes remaining from this
+ // index position if we want to perform a sequential read by
+ // incrementing the buffer pointer
+ reader = st7565_read_raw(0);
+ //Loop over the remaining buffer and erase pixels as we go
+ for (uint16_t i = 0; i < reader.remaining_element_count; i++) {
+ //Get the actual byte in the buffer by dereferencing the pointer
+ buff_char = *reader.current_element;
+ if (buff_char != 0) {
+ st7565_write_raw_byte(buff_char & single_bit_masks[rand() % 8], i);
+ }
+ //increment the pointer to fetch a new byte during the next loop
+ reader.current_element++;
+ }
+ }
+}
+```
+
+## Other Examples
+
+In split keyboards, it is very common to have two displays that each render different content and are oriented or flipped differently. You can do this by switching which content to render by using the return value from `is_keyboard_master()` or `is_keyboard_left()` found in `split_util.h`, e.g:
+
+```c
+#ifdef ST7565_ENABLE
+display_rotation_t st7565_init_user(display_rotation_t rotation) {
+ if (!is_keyboard_master()) {
+ return DISPLAY_ROTATION_180; // flips the display 180 degrees if offhand
+ }
+
+ return rotation;
+}
+
+void st7565_task_user(void) {
+ if (is_keyboard_master()) {
+ render_status(); // Renders the current keyboard state (layer, lock, caps, scroll, etc)
+ } else {
+ render_logo(); // Renders a static logo
+ }
+}
+#endif
+```
+
+## Basic Configuration
+
+|Define |Default |Description |
+|------------------------|--------------|-----------------------------------------------------------------------------------------------------|
+|`ST7565_A0_PIN` |*Not defined* |(Required) The GPIO connected to the display's A0 (data/command) pin |
+|`ST7565_RST_PIN` |*Not defined* |(Required) The GPIO connected to the display's reset pin |
+|`ST7565_SS_PIN` |*Not defined* |(Required) The GPIO connected to the display's slave select pin |
+|`ST7565_SPI_CLK_DIVISOR`|`4` |The SPI clock divisor to use |
+|`ST7565_FONT_H` |`"glcdfont.c"`|The font code file to use for custom fonts |
+|`ST7565_FONT_START` |`0` |The starting character index for custom fonts |
+|`ST7565_FONT_END` |`223` |The ending character index for custom fonts |
+|`ST7565_FONT_WIDTH` |`6` |The font width |
+|`ST7565_FONT_HEIGHT` |`8` |The font height (untested) |
+|`ST7565_TIMEOUT` |`60000` |Turns off the screen after 60000ms of keyboard inactivity. Helps reduce burn-in. Set to 0 to disable.|
+|`ST7565_COLUMN_OFFSET` |`0` |Shift output to the right this many pixels. |
+|`ST7565_CONTRAST` |`32` |The default contrast level of the display, from 0 to 255. |
+|`ST7565_UPDATE_INTERVAL`|`0` |Set the time interval for updating the display in ms. This will improve the matrix scan rate. |
+
+## Custom sized displays
+
+The default display size for this feature is 128x32 and all necessary defines are precalculated with that in mind.
+
+|Define |Default |Description |
+|-----------------------|----------|-----------------------------------------------------------------------------------------------------------|
+|`ST7565_DISPLAY_WIDTH` |`128` |The width of the display. |
+|`ST7565_DISPLAY_HEIGHT`|`32` |The height of the display. |
+|`ST7565_MATRIX_SIZE` |`512` |The local buffer size to allocate.
`(ST7565_DISPLAY_HEIGHT / 8 * ST7565_DISPLAY_WIDTH)`. |
+|`ST7565_BLOCK_TYPE` |`uint16_t`|The unsigned integer type to use for dirty rendering. |
+|`ST7565_BLOCK_COUNT` |`16` |The number of blocks the display is divided into for dirty rendering.
`(sizeof(ST7565_BLOCK_TYPE) * 8)`.|
+|`ST7565_BLOCK_SIZE` |`32` |The size of each block for dirty rendering
`(ST7565_MATRIX_SIZE / ST7565_BLOCK_COUNT)`. |
+
+## API
+
+```c
+// Rotation enum values are flags
+typedef enum {
+ DISPLAY_ROTATION_0,
+ DISPLAY_ROTATION_180
+} display_rotation_t;
+
+// Initialize the display, rotating the rendered output based on the define passed in.
+// Returns true if the was initialized successfully
+bool st7565_init(display_rotation_t rotation);
+
+// Called at the start of st7565_init, weak function overridable by the user
+// rotation - the value passed into st7565_init
+// Return new display_rotation_t if you want to override default rotation
+display_rotation_t st7565_init_user(display_rotation_t rotation);
+
+// Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
+void st7565_clear(void);
+
+// Renders the dirty chunks of the buffer to display
+void st7565_render(void);
+
+// Moves cursor to character position indicated by column and line, wraps if out of bounds
+// Max column denoted by 'st7565_max_chars()' and max lines by 'st7565_max_lines()' functions
+void st7565_set_cursor(uint8_t col, uint8_t line);
+
+// Advances the cursor to the next page, writing ' ' if true
+// Wraps to the begining when out of bounds
+void st7565_advance_page(bool clearPageRemainder);
+
+// Moves the cursor forward 1 character length
+// Advance page if there is not enough room for the next character
+// Wraps to the begining when out of bounds
+void st7565_advance_char(void);
+
+// Writes a single character to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Main handler that writes character data to the display buffer
+void st7565_write_char(const char data, bool invert);
+
+// Writes a string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+void st7565_write(const char *data, bool invert);
+
+// Writes a string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
+void st7565_write_ln(const char *data, bool invert);
+
+// Pans the buffer to the right (or left by passing true) by moving contents of the buffer
+// Useful for moving the screen in preparation for new drawing
+void st7565_pan(bool left);
+
+// Returns a pointer to the requested start index in the buffer plus remaining
+// buffer length as struct
+display_buffer_reader_t st7565_read_raw(uint16_t start_index);
+
+// Writes a string to the buffer at current cursor position
+void st7565_write_raw(const char *data, uint16_t size);
+
+// Writes a single byte into the buffer at the specified index
+void st7565_write_raw_byte(const char data, uint16_t index);
+
+// Sets a specific pixel on or off
+// Coordinates start at top-left and go right and down for positive x and y
+void st7565_write_pixel(uint8_t x, uint8_t y, bool on);
+
+// Writes a PROGMEM string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Remapped to call 'void st7565_write(const char *data, bool invert);' on ARM
+void st7565_write_P(const char *data, bool invert);
+
+// Writes a PROGMEM string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
+// Remapped to call 'void st7565_write_ln(const char *data, bool invert);' on ARM
+void st7565_write_ln_P(const char *data, bool invert);
+
+// Writes a PROGMEM string to the buffer at current cursor position
+void st7565_write_raw_P(const char *data, uint16_t size);
+
+// Can be used to manually turn on the screen if it is off
+// Returns true if the screen was on or turns on
+bool st7565_on(void);
+
+// Called when st7565_on() turns on the screen, weak function overridable by the user
+// Not called if the screen is already on
+void st7565_on_user(void);
+
+// Can be used to manually turn off the screen if it is on
+// Returns true if the screen was off or turns off
+bool st7565_off(void);
+
+// Called when st7565_off() turns off the screen, weak function overridable by the user
+// Not called if the screen is already off
+void st7565_off_user(void);
+
+// Returns true if the screen is currently on, false if it is
+// not
+bool st7565_is_on(void);
+
+// Basically it's st7565_render, but with timeout management and st7565_task_user calling!
+void st7565_task(void);
+
+// Called at the start of st7565_task, weak function overridable by the user
+void st7565_task_user(void);
+
+// Returns the maximum number of characters that will fit on a line
+uint8_t st7565_max_chars(void);
+
+// Returns the maximum number of lines that will fit on the display
+uint8_t st7565_max_lines(void);
+```
diff --git a/drivers/lcd/st7565.c b/drivers/lcd/st7565.c
new file mode 100644
index 0000000000..4b4891ce71
--- /dev/null
+++ b/drivers/lcd/st7565.c
@@ -0,0 +1,479 @@
+/*
+Copyright 2021
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+#include "st7565.h"
+
+#include
+
+#include "keyboard.h"
+#include "progmem.h"
+#include "timer.h"
+#include "wait.h"
+
+#include ST7565_FONT_H
+
+// Fundamental Commands
+#define CONTRAST 0x81
+#define DISPLAY_ALL_ON 0xA5
+#define DISPLAY_ALL_ON_RESUME 0xA4
+#define NORMAL_DISPLAY 0xA6
+#define DISPLAY_ON 0xAF
+#define DISPLAY_OFF 0xAE
+#define NOP 0xE3
+
+// Addressing Setting Commands
+#define PAM_SETCOLUMN_LSB 0x00
+#define PAM_SETCOLUMN_MSB 0x10
+#define PAM_PAGE_ADDR 0xB0 // 0xb0 -- 0xb7
+
+// Hardware Configuration Commands
+#define DISPLAY_START_LINE 0x40
+#define SEGMENT_REMAP 0xA0
+#define SEGMENT_REMAP_INV 0xA1
+#define COM_SCAN_INC 0xC0
+#define COM_SCAN_DEC 0xC8
+#define LCD_BIAS_7 0xA3
+#define LCD_BIAS_9 0xA2
+#define RESISTOR_RATIO 0x20
+#define POWER_CONTROL 0x28
+
+// Misc defines
+#ifndef ST7565_BLOCK_COUNT
+# define ST7565_BLOCK_COUNT (sizeof(ST7565_BLOCK_TYPE) * 8)
+#endif
+#ifndef ST7565_BLOCK_SIZE
+# define ST7565_BLOCK_SIZE (ST7565_MATRIX_SIZE / ST7565_BLOCK_COUNT)
+#endif
+
+#define ST7565_ALL_BLOCKS_MASK (((((ST7565_BLOCK_TYPE)1 << (ST7565_BLOCK_COUNT - 1)) - 1) << 1) | 1)
+
+#define HAS_FLAGS(bits, flags) ((bits & flags) == flags)
+
+// Display buffer's is the same as the display memory layout
+// this is so we don't end up with rounding errors with
+// parts of the display unusable or don't get cleared correctly
+// and also allows for drawing & inverting
+uint8_t st7565_buffer[ST7565_MATRIX_SIZE];
+uint8_t * st7565_cursor;
+ST7565_BLOCK_TYPE st7565_dirty = 0;
+bool st7565_initialized = false;
+bool st7565_active = false;
+display_rotation_t st7565_rotation = DISPLAY_ROTATION_0;
+#if ST7565_TIMEOUT > 0
+uint32_t st7565_timeout;
+#endif
+#if ST7565_UPDATE_INTERVAL > 0
+uint16_t st7565_update_timeout;
+#endif
+
+// Flips the rendering bits for a character at the current cursor position
+static void InvertCharacter(uint8_t *cursor) {
+ const uint8_t *end = cursor + ST7565_FONT_WIDTH;
+ while (cursor < end) {
+ *cursor = ~(*cursor);
+ cursor++;
+ }
+}
+
+bool st7565_init(display_rotation_t rotation) {
+ setPinOutput(ST7565_A0_PIN);
+ writePinHigh(ST7565_A0_PIN);
+ setPinOutput(ST7565_RST_PIN);
+ writePinHigh(ST7565_RST_PIN);
+
+ st7565_rotation = st7565_init_user(rotation);
+
+ spi_init();
+ spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR);
+
+ st7565_reset();
+
+ st7565_send_cmd(LCD_BIAS_7);
+ if (!HAS_FLAGS(st7565_rotation, DISPLAY_ROTATION_180)) {
+ st7565_send_cmd(SEGMENT_REMAP);
+ st7565_send_cmd(COM_SCAN_DEC);
+ } else {
+ st7565_send_cmd(SEGMENT_REMAP_INV);
+ st7565_send_cmd(COM_SCAN_INC);
+ }
+ st7565_send_cmd(DISPLAY_START_LINE | 0x00);
+ st7565_send_cmd(CONTRAST);
+ st7565_send_cmd(ST7565_CONTRAST);
+ st7565_send_cmd(RESISTOR_RATIO | 0x01);
+ st7565_send_cmd(POWER_CONTROL | 0x04);
+ wait_ms(50);
+ st7565_send_cmd(POWER_CONTROL | 0x06);
+ wait_ms(50);
+ st7565_send_cmd(POWER_CONTROL | 0x07);
+ wait_ms(10);
+ st7565_send_cmd(DISPLAY_ON);
+ st7565_send_cmd(DISPLAY_ALL_ON_RESUME);
+ st7565_send_cmd(NORMAL_DISPLAY);
+
+ spi_stop();
+
+#if ST7565_TIMEOUT > 0
+ st7565_timeout = timer_read32() + ST7565_TIMEOUT;
+#endif
+
+ st7565_clear();
+ st7565_initialized = true;
+ st7565_active = true;
+ return true;
+}
+
+__attribute__((weak)) display_rotation_t st7565_init_user(display_rotation_t rotation) { return rotation; }
+
+void st7565_clear(void) {
+ memset(st7565_buffer, 0, sizeof(st7565_buffer));
+ st7565_cursor = &st7565_buffer[0];
+ st7565_dirty = ST7565_ALL_BLOCKS_MASK;
+}
+
+uint8_t crot(uint8_t a, int8_t n) {
+ const uint8_t mask = 0x7;
+ n &= mask;
+ return a << n | a >> (-n & mask);
+}
+
+void st7565_render(void) {
+ if (!st7565_initialized) {
+ return;
+ }
+
+ // Do we have work to do?
+ st7565_dirty &= ST7565_ALL_BLOCKS_MASK;
+ if (!st7565_dirty) {
+ return;
+ }
+
+ // Find first dirty block
+ uint8_t update_start = 0;
+ while (!(st7565_dirty & ((ST7565_BLOCK_TYPE)1 << update_start))) {
+ ++update_start;
+ }
+
+ // Calculate commands to set memory addressing bounds.
+ uint8_t start_page = ST7565_BLOCK_SIZE * update_start / ST7565_DISPLAY_WIDTH;
+ uint8_t start_column = ST7565_BLOCK_SIZE * update_start % ST7565_DISPLAY_WIDTH;
+ // IC has 132 segment drivers, for panels with less width we need to offset the starting column
+ if (HAS_FLAGS(st7565_rotation, DISPLAY_ROTATION_180)) {
+ start_column += (132 - ST7565_DISPLAY_WIDTH);
+ }
+
+ spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR);
+
+ st7565_send_cmd(PAM_PAGE_ADDR | start_page);
+ st7565_send_cmd(PAM_SETCOLUMN_LSB | ((ST7565_COLUMN_OFFSET + start_column) & 0x0f));
+ st7565_send_cmd(PAM_SETCOLUMN_MSB | ((ST7565_COLUMN_OFFSET + start_column) >> 4 & 0x0f));
+
+ st7565_send_data(&st7565_buffer[ST7565_BLOCK_SIZE * update_start], ST7565_BLOCK_SIZE);
+
+ // Turn on display if it is off
+ st7565_on();
+
+ // Clear dirty flag
+ st7565_dirty &= ~((ST7565_BLOCK_TYPE)1 << update_start);
+}
+
+void st7565_set_cursor(uint8_t col, uint8_t line) {
+ uint16_t index = line * ST7565_DISPLAY_WIDTH + col * ST7565_FONT_WIDTH;
+
+ // Out of bounds?
+ if (index >= ST7565_MATRIX_SIZE) {
+ index = 0;
+ }
+
+ st7565_cursor = &st7565_buffer[index];
+}
+
+void st7565_advance_page(bool clearPageRemainder) {
+ uint16_t index = st7565_cursor - &st7565_buffer[0];
+ uint8_t remaining = ST7565_DISPLAY_WIDTH - (index % ST7565_DISPLAY_WIDTH);
+
+ if (clearPageRemainder) {
+ // Remaining Char count
+ remaining = remaining / ST7565_FONT_WIDTH;
+
+ // Write empty character until next line
+ while (remaining--) st7565_write_char(' ', false);
+ } else {
+ // Next page index out of bounds?
+ if (index + remaining >= ST7565_MATRIX_SIZE) {
+ index = 0;
+ remaining = 0;
+ }
+
+ st7565_cursor = &st7565_buffer[index + remaining];
+ }
+}
+
+void st7565_advance_char(void) {
+ uint16_t nextIndex = st7565_cursor - &st7565_buffer[0] + ST7565_FONT_WIDTH;
+ uint8_t remainingSpace = ST7565_DISPLAY_WIDTH - (nextIndex % ST7565_DISPLAY_WIDTH);
+
+ // Do we have enough space on the current line for the next character
+ if (remainingSpace < ST7565_FONT_WIDTH) {
+ nextIndex += remainingSpace;
+ }
+
+ // Did we go out of bounds
+ if (nextIndex >= ST7565_MATRIX_SIZE) {
+ nextIndex = 0;
+ }
+
+ // Update cursor position
+ st7565_cursor = &st7565_buffer[nextIndex];
+}
+
+// Main handler that writes character data to the display buffer
+void st7565_write_char(const char data, bool invert) {
+ // Advance to the next line if newline
+ if (data == '\n') {
+ // Old source wrote ' ' until end of line...
+ st7565_advance_page(true);
+ return;
+ }
+
+ if (data == '\r') {
+ st7565_advance_page(false);
+ return;
+ }
+
+ // copy the current render buffer to check for dirty after
+ static uint8_t st7565_temp_buffer[ST7565_FONT_WIDTH];
+ memcpy(&st7565_temp_buffer, st7565_cursor, ST7565_FONT_WIDTH);
+
+ _Static_assert(sizeof(font) >= ((ST7565_FONT_END + 1 - ST7565_FONT_START) * ST7565_FONT_WIDTH), "ST7565_FONT_END references outside array");
+
+ // set the reder buffer data
+ uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index
+ if (cast_data < ST7565_FONT_START || cast_data > ST7565_FONT_END) {
+ memset(st7565_cursor, 0x00, ST7565_FONT_WIDTH);
+ } else {
+ const uint8_t *glyph = &font[(cast_data - ST7565_FONT_START) * ST7565_FONT_WIDTH];
+ memcpy_P(st7565_cursor, glyph, ST7565_FONT_WIDTH);
+ }
+
+ // Invert if needed
+ if (invert) {
+ InvertCharacter(st7565_cursor);
+ }
+
+ // Dirty check
+ if (memcmp(&st7565_temp_buffer, st7565_cursor, ST7565_FONT_WIDTH)) {
+ uint16_t index = st7565_cursor - &st7565_buffer[0];
+ st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (index / ST7565_BLOCK_SIZE));
+ // Edgecase check if the written data spans the 2 chunks
+ st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << ((index + ST7565_FONT_WIDTH - 1) / ST7565_BLOCK_SIZE));
+ }
+
+ // Finally move to the next char
+ st7565_advance_char();
+}
+
+void st7565_write(const char *data, bool invert) {
+ const char *end = data + strlen(data);
+ while (data < end) {
+ st7565_write_char(*data, invert);
+ data++;
+ }
+}
+
+void st7565_write_ln(const char *data, bool invert) {
+ st7565_write(data, invert);
+ st7565_advance_page(true);
+}
+
+void st7565_pan(bool left) {
+ uint16_t i = 0;
+ for (uint16_t y = 0; y < ST7565_DISPLAY_HEIGHT / 8; y++) {
+ if (left) {
+ for (uint16_t x = 0; x < ST7565_DISPLAY_WIDTH - 1; x++) {
+ i = y * ST7565_DISPLAY_WIDTH + x;
+ st7565_buffer[i] = st7565_buffer[i + 1];
+ }
+ } else {
+ for (uint16_t x = ST7565_DISPLAY_WIDTH - 1; x > 0; x--) {
+ i = y * ST7565_DISPLAY_WIDTH + x;
+ st7565_buffer[i] = st7565_buffer[i - 1];
+ }
+ }
+ }
+ st7565_dirty = ST7565_ALL_BLOCKS_MASK;
+}
+
+display_buffer_reader_t st7565_read_raw(uint16_t start_index) {
+ if (start_index > ST7565_MATRIX_SIZE) start_index = ST7565_MATRIX_SIZE;
+ display_buffer_reader_t ret_reader;
+ ret_reader.current_element = &st7565_buffer[start_index];
+ ret_reader.remaining_element_count = ST7565_MATRIX_SIZE - start_index;
+ return ret_reader;
+}
+
+void st7565_write_raw_byte(const char data, uint16_t index) {
+ if (index > ST7565_MATRIX_SIZE) index = ST7565_MATRIX_SIZE;
+ if (st7565_buffer[index] == data) return;
+ st7565_buffer[index] = data;
+ st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (index / ST7565_BLOCK_SIZE));
+}
+
+void st7565_write_raw(const char *data, uint16_t size) {
+ uint16_t cursor_start_index = st7565_cursor - &st7565_buffer[0];
+ if ((size + cursor_start_index) > ST7565_MATRIX_SIZE) size = ST7565_MATRIX_SIZE - cursor_start_index;
+ for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) {
+ if (st7565_buffer[i] == data[i]) continue;
+ st7565_buffer[i] = data[i];
+ st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (i / ST7565_BLOCK_SIZE));
+ }
+}
+
+void st7565_write_pixel(uint8_t x, uint8_t y, bool on) {
+ if (x >= ST7565_DISPLAY_WIDTH) {
+ return;
+ }
+ uint16_t index = x + (y / 8) * ST7565_DISPLAY_WIDTH;
+ if (index >= ST7565_MATRIX_SIZE) {
+ return;
+ }
+ uint8_t data = st7565_buffer[index];
+ if (on) {
+ data |= (1 << (y % 8));
+ } else {
+ data &= ~(1 << (y % 8));
+ }
+ if (st7565_buffer[index] != data) {
+ st7565_buffer[index] = data;
+ st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (index / ST7565_BLOCK_SIZE));
+ }
+}
+
+#if defined(__AVR__)
+void st7565_write_P(const char *data, bool invert) {
+ uint8_t c = pgm_read_byte(data);
+ while (c != 0) {
+ st7565_write_char(c, invert);
+ c = pgm_read_byte(++data);
+ }
+}
+
+void st7565_write_ln_P(const char *data, bool invert) {
+ st7565_write_P(data, invert);
+ st7565_advance_page(true);
+}
+
+void st7565_write_raw_P(const char *data, uint16_t size) {
+ uint16_t cursor_start_index = st7565_cursor - &st7565_buffer[0];
+ if ((size + cursor_start_index) > ST7565_MATRIX_SIZE) size = ST7565_MATRIX_SIZE - cursor_start_index;
+ for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) {
+ uint8_t c = pgm_read_byte(data++);
+ if (st7565_buffer[i] == c) continue;
+ st7565_buffer[i] = c;
+ st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (i / ST7565_BLOCK_SIZE));
+ }
+}
+#endif // defined(__AVR__)
+
+bool st7565_on(void) {
+ if (!st7565_initialized) {
+ return st7565_active;
+ }
+
+#if ST7565_TIMEOUT > 0
+ st7565_timeout = timer_read32() + ST7565_TIMEOUT;
+#endif
+
+ if (!st7565_active) {
+ spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR);
+ st7565_send_cmd(DISPLAY_ON);
+ spi_stop();
+ st7565_active = true;
+ st7565_on_user();
+ }
+ return st7565_active;
+}
+
+__attribute__((weak)) void st7565_on_user(void) {}
+
+bool st7565_off(void) {
+ if (!st7565_initialized) {
+ return !st7565_active;
+ }
+
+ if (st7565_active) {
+ spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR);
+ st7565_send_cmd(DISPLAY_OFF);
+ spi_stop();
+ st7565_active = false;
+ st7565_off_user();
+ }
+ return !st7565_active;
+}
+
+__attribute__((weak)) void st7565_off_user(void) {}
+
+bool st7565_is_on(void) { return st7565_active; }
+
+uint8_t st7565_max_chars(void) { return ST7565_DISPLAY_WIDTH / ST7565_FONT_WIDTH; }
+
+uint8_t st7565_max_lines(void) { return ST7565_DISPLAY_HEIGHT / ST7565_FONT_HEIGHT; }
+
+void st7565_task(void) {
+ if (!st7565_initialized) {
+ return;
+ }
+
+#if ST7565_UPDATE_INTERVAL > 0
+ if (timer_elapsed(st7565_update_timeout) >= ST7565_UPDATE_INTERVAL) {
+ st7565_update_timeout = timer_read();
+ st7565_set_cursor(0, 0);
+ st7565_task_user();
+ }
+#else
+ st7565_set_cursor(0, 0);
+ st7565_task_user();
+#endif
+
+ // Smart render system, no need to check for dirty
+ st7565_render();
+
+ // Display timeout check
+#if ST7565_TIMEOUT > 0
+ if (st7565_active && timer_expired32(timer_read32(), st7565_timeout)) {
+ st7565_off();
+ }
+#endif
+}
+
+__attribute__((weak)) void st7565_task_user(void) {}
+
+void st7565_reset(void) {
+ writePinLow(ST7565_RST_PIN);
+ wait_ms(20);
+ writePinHigh(ST7565_RST_PIN);
+ wait_ms(20);
+}
+
+spi_status_t st7565_send_cmd(uint8_t cmd) {
+ writePinLow(ST7565_A0_PIN);
+ return spi_write(cmd);
+}
+
+spi_status_t st7565_send_data(uint8_t *data, uint16_t length) {
+ writePinHigh(ST7565_A0_PIN);
+ return spi_transmit(data, length);
+}
diff --git a/drivers/lcd/st7565.h b/drivers/lcd/st7565.h
new file mode 100644
index 0000000000..53cfc9a810
--- /dev/null
+++ b/drivers/lcd/st7565.h
@@ -0,0 +1,215 @@
+/*
+Copyright 2021
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+#pragma once
+
+#include
+#include
+
+#include "spi_master.h"
+
+#ifndef ST7565_DISPLAY_WIDTH
+# define ST7565_DISPLAY_WIDTH 128
+#endif
+#ifndef ST7565_DISPLAY_HEIGHT
+# define ST7565_DISPLAY_HEIGHT 32
+#endif
+#ifndef ST7565_MATRIX_SIZE
+# define ST7565_MATRIX_SIZE (ST7565_DISPLAY_HEIGHT / 8 * ST7565_DISPLAY_WIDTH) // 1024 (compile time mathed)
+#endif
+#ifndef ST7565_BLOCK_TYPE
+# define ST7565_BLOCK_TYPE uint16_t
+#endif
+#ifndef ST7565_BLOCK_COUNT
+# define ST7565_BLOCK_COUNT (sizeof(ST7565_BLOCK_TYPE) * 8) // 32 (compile time mathed)
+#endif
+#ifndef ST7565_BLOCK_SIZE
+# define ST7565_BLOCK_SIZE (ST7565_MATRIX_SIZE / ST7565_BLOCK_COUNT) // 32 (compile time mathed)
+#endif
+
+// the column address corresponding to the first column in the display hardware
+#if !defined(ST7565_COLUMN_OFFSET)
+# define ST7565_COLUMN_OFFSET 0
+#endif
+
+// spi clock divisor
+#if !defined(ST7565_SPI_CLK_DIVISOR)
+# define ST7565_SPI_CLK_DIVISOR 4
+#endif
+
+// Custom font file to use
+#if !defined(ST7565_FONT_H)
+# define ST7565_FONT_H "glcdfont.c"
+#endif
+// unsigned char value of the first character in the font file
+#if !defined(ST7565_FONT_START)
+# define ST7565_FONT_START 0
+#endif
+// unsigned char value of the last character in the font file
+#if !defined(ST7565_FONT_END)
+# define ST7565_FONT_END 223
+#endif
+// Font render width
+#if !defined(ST7565_FONT_WIDTH)
+# define ST7565_FONT_WIDTH 6
+#endif
+// Font render height
+#if !defined(ST7565_FONT_HEIGHT)
+# define ST7565_FONT_HEIGHT 8
+#endif
+// Default contrast level
+#if !defined(ST7565_CONTRAST)
+# define ST7565_CONTRAST 32
+#endif
+
+#if !defined(ST7565_TIMEOUT)
+# if defined(ST7565_DISABLE_TIMEOUT)
+# define ST7565_TIMEOUT 0
+# else
+# define ST7565_TIMEOUT 60000
+# endif
+#endif
+
+#if !defined(ST7565_UPDATE_INTERVAL) && defined(SPLIT_KEYBOARD)
+# define ST7565_UPDATE_INTERVAL 50
+#endif
+
+typedef struct __attribute__((__packed__)) {
+ uint8_t *current_element;
+ uint16_t remaining_element_count;
+} display_buffer_reader_t;
+
+// Rotation enum values are flags
+typedef enum { DISPLAY_ROTATION_0, DISPLAY_ROTATION_180 } display_rotation_t;
+
+// Initialize the display, rotating the rendered output based on the define passed in.
+// Returns true if the display was initialized successfully
+bool st7565_init(display_rotation_t rotation);
+
+// Called at the start of st7565_init, weak function overridable by the user
+// rotation - the value passed into st7565_init
+// Return new display_rotation_t if you want to override default rotation
+display_rotation_t st7565_init_user(display_rotation_t rotation);
+
+// Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
+void st7565_clear(void);
+
+// Renders the dirty chunks of the buffer to display
+void st7565_render(void);
+
+// Moves cursor to character position indicated by column and line, wraps if out of bounds
+// Max column denoted by 'st7565_max_chars()' and max lines by 'st7565_max_lines()' functions
+void st7565_set_cursor(uint8_t col, uint8_t line);
+
+// Advances the cursor to the next page, writing ' ' if true
+// Wraps to the begining when out of bounds
+void st7565_advance_page(bool clearPageRemainder);
+
+// Moves the cursor forward 1 character length
+// Advance page if there is not enough room for the next character
+// Wraps to the begining when out of bounds
+void st7565_advance_char(void);
+
+// Writes a single character to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Main handler that writes character data to the display buffer
+void st7565_write_char(const char data, bool invert);
+
+// Writes a string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+void st7565_write(const char *data, bool invert);
+
+// Writes a string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
+void st7565_write_ln(const char *data, bool invert);
+
+// Pans the buffer to the right (or left by passing true) by moving contents of the buffer
+// Useful for moving the screen in preparation for new drawing
+void st7565_pan(bool left);
+
+// Returns a pointer to the requested start index in the buffer plus remaining
+// buffer length as struct
+display_buffer_reader_t st7565_read_raw(uint16_t start_index);
+
+// Writes a string to the buffer at current cursor position
+void st7565_write_raw(const char *data, uint16_t size);
+
+// Writes a single byte into the buffer at the specified index
+void st7565_write_raw_byte(const char data, uint16_t index);
+
+// Sets a specific pixel on or off
+// Coordinates start at top-left and go right and down for positive x and y
+void st7565_write_pixel(uint8_t x, uint8_t y, bool on);
+
+#if defined(__AVR__)
+// Writes a PROGMEM string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Remapped to call 'void st7565_write(const char *data, bool invert);' on ARM
+void st7565_write_P(const char *data, bool invert);
+
+// Writes a PROGMEM string to the buffer at current cursor position
+// Advances the cursor while writing, inverts the pixels if true
+// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
+// Remapped to call 'void st7565_write_ln(const char *data, bool invert);' on ARM
+void st7565_write_ln_P(const char *data, bool invert);
+
+// Writes a PROGMEM string to the buffer at current cursor position
+void st7565_write_raw_P(const char *data, uint16_t size);
+#else
+# define st7565_write_P(data, invert) st7565_write(data, invert)
+# define st7565_write_ln_P(data, invert) st7565_write_ln(data, invert)
+# define st7565_write_raw_P(data, size) st7565_write_raw(data, size)
+#endif // defined(__AVR__)
+
+// Can be used to manually turn on the screen if it is off
+// Returns true if the screen was on or turns on
+bool st7565_on(void);
+
+// Called when st7565_on() turns on the screen, weak function overridable by the user
+// Not called if the screen is already on
+void st7565_on_user(void);
+
+// Can be used to manually turn off the screen if it is on
+// Returns true if the screen was off or turns off
+bool st7565_off(void);
+
+// Called when st7565_off() turns off the screen, weak function overridable by the user
+// Not called if the screen is already off
+void st7565_off_user(void);
+
+// Returns true if the screen is currently on, false if it is
+// not
+bool st7565_is_on(void);
+
+// Basically it's st7565_render, but with timeout management and st7565_task_user calling!
+void st7565_task(void);
+
+// Called at the start of st7565_task, weak function overridable by the user
+void st7565_task_user(void);
+
+// Returns the maximum number of characters that will fit on a line
+uint8_t st7565_max_chars(void);
+
+// Returns the maximum number of lines that will fit on the display
+uint8_t st7565_max_lines(void);
+
+void st7565_reset(void);
+
+spi_status_t st7565_send_cmd(uint8_t cmd);
+
+spi_status_t st7565_send_data(uint8_t *data, uint16_t length);
diff --git a/quantum/quantum.h b/quantum/quantum.h
index e4a7c5723c..66ba96fde8 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -176,6 +176,10 @@ extern layer_state_t layer_state;
# include "oled_driver.h"
#endif
+#ifdef ST7565_ENABLE
+# include "st7565.h"
+#endif
+
#ifdef DIP_SWITCH_ENABLE
# include "dip_switch.h"
#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 3d6092e71c..249da85bd2 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -85,6 +85,9 @@ along with this program. If not, see .
#ifdef OLED_DRIVER_ENABLE
# include "oled_driver.h"
#endif
+#ifdef ST7565_ENABLE
+# include "st7565.h"
+#endif
#ifdef VELOCIKEY_ENABLE
# include "velocikey.h"
#endif
@@ -306,6 +309,9 @@ void keyboard_init(void) {
#ifdef OLED_DRIVER_ENABLE
oled_init(OLED_ROTATION_0);
#endif
+#ifdef ST7565_ENABLE
+ st7565_init(DISPLAY_ROTATION_0);
+#endif
#ifdef PS2_MOUSE_ENABLE
ps2_mouse_init();
#endif
@@ -470,6 +476,18 @@ MATRIX_LOOP_END:
# endif
#endif
+#ifdef ST7565_ENABLE
+ st7565_task();
+# ifndef ST7565_DISABLE_TIMEOUT
+ // Wake up display if user is using those fabulous keys or spinning those encoders!
+# ifdef ENCODER_ENABLE
+ if (matrix_changed || encoders_changed) st7565_on();
+# else
+ if (matrix_changed) st7565_on();
+# endif
+# endif
+#endif
+
#ifdef MOUSEKEY_ENABLE
// mousekey repeat & acceleration
mousekey_task();
--
cgit v1.2.3
From d59f8d1c022234140a94c643f4b78bf5487d39f7 Mon Sep 17 00:00:00 2001
From: Jonathan Rascher
Date: Wed, 16 Jun 2021 00:30:27 -0500
Subject: Fix overrun in st7565_write_raw when not at (0, 0) (#13209)
---
drivers/lcd/st7565.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'drivers')
diff --git a/drivers/lcd/st7565.c b/drivers/lcd/st7565.c
index 4b4891ce71..ee2661a5eb 100644
--- a/drivers/lcd/st7565.c
+++ b/drivers/lcd/st7565.c
@@ -336,8 +336,9 @@ void st7565_write_raw(const char *data, uint16_t size) {
uint16_t cursor_start_index = st7565_cursor - &st7565_buffer[0];
if ((size + cursor_start_index) > ST7565_MATRIX_SIZE) size = ST7565_MATRIX_SIZE - cursor_start_index;
for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) {
- if (st7565_buffer[i] == data[i]) continue;
- st7565_buffer[i] = data[i];
+ uint8_t c = *data++;
+ if (st7565_buffer[i] == c) continue;
+ st7565_buffer[i] = c;
st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (i / ST7565_BLOCK_SIZE));
}
}
--
cgit v1.2.3
From 172e6a703041363decd6fc829542f33180c13beb Mon Sep 17 00:00:00 2001
From: Nick Brassel
Date: Fri, 18 Jun 2021 09:10:06 +1000
Subject: Extensible split data sync (#11930)
* Extensible split data sync capability through transactions.
- Split common transport has been split up between the transport layer
and data layer.
- Split "transactions" model used, with convergence between I2C and
serial data definitions.
- Slave matrix "generation count" is used to determine if the full slave
matrix needs to be retrieved.
- Encoders get the same "generation count" treatment.
- All other blocks of data are synchronised when a change is detected.
- All transmissions have a globally-configurable deadline before a
transmission is forced (`FORCED_SYNC_THROTTLE_MS`, default 100ms).
- Added atomicity for all core-synced data, preventing partial updates
- Added retries to AVR i2c_master's i2c_start, to minimise the number of
failed transactions when interrupts are disabled on the slave due to
atomicity checks.
- Some keyboards have had slight modifications made in order to ensure
that they still build due to firmware size restrictions.
* Fixup LED_MATRIX compile.
* Parameterise ERROR_DISCONNECT_COUNT.---
common_features.mk | 6 +-
docs/config_options.md | 26 +-
docs/feature_split_keyboard.md | 114 ++++-
drivers/avr/i2c_master.c | 19 +-
drivers/avr/i2c_slave.c | 29 +-
drivers/avr/i2c_slave.h | 13 +-
drivers/avr/serial.c | 82 +---
drivers/avr/serial.h | 62 ---
drivers/chibios/serial.c | 52 +-
drivers/chibios/serial.h | 62 ---
drivers/chibios/serial_usart.c | 47 +-
drivers/serial.h | 46 ++
keyboards/draculad/config.h | 2 +
keyboards/handwired/freoduo/rules.mk | 4 +-
keyboards/helix/rev2/keymaps/default/rules.mk | 2 +-
keyboards/keebio/iris/rev2/rules.mk | 2 +
keyboards/keebio/iris/rev3/rules.mk | 1 +
keyboards/keebio/iris/rev4/rules.mk | 2 +
keyboards/keebio/quefrency/rules.mk | 1 +
keyboards/keebio/viterbi/rev2/rules.mk | 2 +
keyboards/keebio/viterbi/rules.mk | 8 +-
quantum/split_common/matrix.c | 6 +-
quantum/split_common/post_config.h | 9 -
quantum/split_common/transaction_id_define.h | 94 ++++
quantum/split_common/transactions.c | 670 ++++++++++++++++++++++++++
quantum/split_common/transactions.h | 54 +++
quantum/split_common/transport.c | 484 +++----------------
quantum/split_common/transport.h | 165 +++++++
tmk_core/common/host.c | 14 +-
29 files changed, 1387 insertions(+), 691 deletions(-)
delete mode 100644 drivers/avr/serial.h
delete mode 100644 drivers/chibios/serial.h
create mode 100644 drivers/serial.h
create mode 100644 quantum/split_common/transaction_id_define.h
create mode 100644 quantum/split_common/transactions.c
create mode 100644 quantum/split_common/transactions.h
(limited to 'drivers')
diff --git a/common_features.mk b/common_features.mk
index 1a079a8df2..15637d7608 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -537,7 +537,11 @@ ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
# Determine which (if any) transport files are required
ifneq ($(strip $(SPLIT_TRANSPORT)), custom)
- QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/transport.c
+ QUANTUM_SRC += $(QUANTUM_DIR)/split_common/transport.c \
+ $(QUANTUM_DIR)/split_common/transactions.c
+
+ OPT_DEFS += -DSPLIT_COMMON_TRANSACTIONS
+
# Functions added via QUANTUM_LIB_SRC are only included in the final binary if they're called.
# Unused functions are pruned away, which is why we can add multiple drivers here without bloat.
ifeq ($(PLATFORM),AVR)
diff --git a/docs/config_options.md b/docs/config_options.md
index 26fe8cea55..980195ac68 100644
--- a/docs/config_options.md
+++ b/docs/config_options.md
@@ -274,7 +274,7 @@ There are a few different ways to set handedness for split keyboards (listed in
### Other Options
* `#define USE_I2C`
- * For using I2C instead of Serial (defaults to serial)
+ * For using I2C instead of Serial (default is serial; serial transport is supported on ARM -- I2C is AVR-only)
* `#define SOFT_SERIAL_PIN D0`
* When using serial, define this. `D0` or `D1`,`D2`,`D3`,`E6`.
@@ -303,7 +303,7 @@ There are a few different ways to set handedness for split keyboards (listed in
* `#define SPLIT_USB_DETECT`
* Detect (with timeout) USB connection when delegating master/slave
* Default behavior for ARM
- * Required for AVR Teensy
+ * Required for AVR Teensy (without hardware mods)
* `#define SPLIT_USB_TIMEOUT 2000`
* Maximum timeout when detecting master/slave when using `SPLIT_USB_DETECT`
@@ -311,6 +311,28 @@ There are a few different ways to set handedness for split keyboards (listed in
* `#define SPLIT_USB_TIMEOUT_POLL 10`
* Poll frequency when detecting master/slave when using `SPLIT_USB_DETECT`
+* `#define FORCED_SYNC_THROTTLE_MS 100`
+ * Deadline for synchronizing data from master to slave when using the QMK-provided split transport.
+
+* `#define SPLIT_TRANSPORT_MIRROR`
+ * Mirrors the master-side matrix on the slave when using the QMK-provided split transport.
+
+* `#define SPLIT_LAYER_STATE_ENABLE`
+ * Ensures the current layer state is available on the slave when using the QMK-provided split transport.
+
+* `#define SPLIT_LED_STATE_ENABLE`
+ * Ensures the current host indicator state (caps/num/scroll) is available on the slave when using the QMK-provided split transport.
+
+* `#define SPLIT_MODS_ENABLE`
+ * Ensures the current modifier state (normal, weak, and oneshot) is available on the slave when using the QMK-provided split transport.
+
+* `#define SPLIT_WPM_ENABLE`
+ * Ensures the current WPM is available on the slave when using the QMK-provided split transport.
+
+* `#define SPLIT_TRANSACTION_IDS_KB .....`
+* `#define SPLIT_TRANSACTION_IDS_USER .....`
+ * Allows for custom data sync with the slave when using the QMK-provided split transport. See [custom data sync between sides](feature_split_keyboard.md#custom-data-sync) for more information.
+
# The `rules.mk` File
This is a [make](https://www.gnu.org/software/make/manual/make.html) file that is included by the top-level `Makefile`. It is used to set some information about the MCU that we will be compiling for as well as enabling and disabling certain features.
diff --git a/docs/feature_split_keyboard.md b/docs/feature_split_keyboard.md
index 4ebf585f5c..603c387c2d 100644
--- a/docs/feature_split_keyboard.md
+++ b/docs/feature_split_keyboard.md
@@ -8,8 +8,7 @@ QMK Firmware has a generic implementation that is usable by any board, as well a
For this, we will mostly be talking about the generic implementation used by the Let's Split and other keyboards.
-!> ARM is not yet fully supported for Split Keyboards and has many limitations. Progress is being made, but we have not yet reached 100% feature parity.
-
+!> ARM split supports most QMK subsystems when using the 'serial' and 'serial_usart' drivers. I2C slave is currently unsupported.
## Compatibility Overview
@@ -169,7 +168,7 @@ Because not every split keyboard is identical, there are a number of additional
#define USE_I2C
```
-This enables I2C support for split keyboards. This isn't strictly for communication, but can be used for OLED or other I2C-based devices.
+This configures the use of I2C support for split keyboard transport (AVR only).
```c
#define SOFT_SERIAL_PIN D0
@@ -193,20 +192,115 @@ If you're having issues with serial communication, you can change this value, as
* **`5`**: about 20kbps
```c
-#define SPLIT_MODS_ENABLE
+#define FORCED_SYNC_THROTTLE_MS 100
```
-This enables transmitting modifier state (normal, weak and oneshot) to the non
-primary side of the split keyboard. This adds a few bytes of data to the split
-communication protocol and may impact the matrix scan speed when enabled.
-The purpose of this feature is to support cosmetic use of modifer state (e.g.
-displaying status on an OLED screen).
+This sets the maximum number of milliseconds before forcing a synchronization of data from master to slave. Under normal circumstances this sync occurs whenever the data _changes_, for safety a data transfer occurs after this number of milliseconds if no change has been detected since the last sync.
```c
#define SPLIT_TRANSPORT_MIRROR
```
-This mirrors the master side matrix to the slave side for features that react or require knowledge of master side key presses on the slave side. This adds a few bytes of data to the split communication protocol and may impact the matrix scan speed when enabled. The purpose of this feature is to support cosmetic use of key events (e.g. RGB reacting to Keypresses).
+This mirrors the master side matrix to the slave side for features that react or require knowledge of master side key presses on the slave side. The purpose of this feature is to support cosmetic use of key events (e.g. RGB reacting to keypresses). This adds overhead to the split communication protocol and may negatively impact the matrix scan speed when enabled.
+
+```c
+#define SPLIT_LAYER_STATE_ENABLE
+```
+
+This enables syncing of the layer state between both halves of the split keyboard. The main purpose of this feature is to enable support for use of things like OLED display of the currently active layer. This adds overhead to the split communication protocol and may negatively impact the matrix scan speed when enabled.
+
+```c
+#define SPLIT_LED_STATE_ENABLE
+```
+
+This enables syncing of the Host LED status (caps lock, num lock, etc) between both halves of the split keyboard. The main purpose of this feature is to enable support for use of things like OLED display of the Host LED status. This adds overhead to the split communication protocol and may negatively impact the matrix scan speed when enabled.
+
+```c
+#define SPLIT_MODS_ENABLE
+```
+
+This enables transmitting modifier state (normal, weak and oneshot) to the non primary side of the split keyboard. The purpose of this feature is to support cosmetic use of modifer state (e.g. displaying status on an OLED screen). This adds overhead to the split communication protocol and may negatively impact the matrix scan speed when enabled.
+
+```c
+#define SPLIT_WPM_ENABLE
+```
+
+This enables transmitting the current WPM to the slave side of the split keyboard. The purpose of this feature is to support cosmetic use of WPM (e.g. displaying the current value on an OLED screen). This adds overhead to the split communication protocol and may negatively impact the matrix scan speed when enabled.
+
+### Custom data sync between sides :id=custom-data-sync
+
+QMK's split transport allows for arbitrary data transactions at both the keyboard and user levels. This is modelled on a remote procedure call, with the master invoking a function on the slave side, with the ability to send data from master to slave, process it slave side, and send data back from slave to master.
+
+To leverage this, a keyboard or user/keymap can define a comma-separated list of _transaction IDs_:
+
+```c
+// for keyboard-level data sync:
+#define SPLIT_TRANSACTION_IDS_KB KEYBOARD_SYNC_A, KEYBOARD_SYNC_B
+// or, for user:
+#define SPLIT_TRANSACTION_IDS_USER USER_SYNC_A, USER_SYNC_B, USER_SYNC_C
+```
+
+These _transaction IDs_ then need a slave-side handler function to be registered with the split transport, for example:
+
+```c
+typedef struct _master_to_slave_t {
+ int m2s_data;
+} master_to_slave_t;
+
+typedef struct _slave_to_master_t {
+ int s2m_data;
+} slave_to_master_t;
+
+void user_sync_a_slave_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) {
+ const master_to_slave_t *m2s = (const master_to_slave_t*)in_data;
+ slave_to_master_t *s2m = (slave_to_master_t*)out_data;
+ s2m->s2m_data = m2s->m2s_data + 5; // whatever comes in, add 5 so it can be sent back
+}
+
+void keyboard_post_init_user(void) {
+ transaction_register_rpc(USER_SYNC_A, user_sync_a_slave_handler);
+}
+```
+
+The master side can then invoke the slave-side handler - for normal keyboard functionality to be minimally affected, any keyboard- or user-level code attempting to sync data should be throttled:
+
+```c
+void housekeeping_task_user(void) {
+ if (is_keyboard_master()) {
+ // Interact with slave every 500ms
+ static uint32_t last_sync = 0;
+ if (timer_elapsed32(last_sync) > 500) {
+ master_to_slave_t m2s = {6};
+ slave_to_master_t s2m = {0};
+ if(transaction_rpc_exec(USER_SYNC_A, sizeof(m2s), &m2s, sizeof(s2m), &s2m)) {
+ last_sync = timer_read32();
+ dprintf("Slave value: %d\n", s2m.s2m_data); // this will now be 11, as the slave adds 5
+ } else {
+ dprint("Slave sync failed!\n");
+ }
+ }
+ }
+}
+```
+
+!> It is recommended that any data sync between halves happens during the master side's _housekeeping task_. This ensures timely retries should failures occur.
+
+If only one-way data transfer is needed, helper methods are provided:
+
+```c
+bool transaction_rpc_exec(int8_t transaction_id, uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer);
+bool transaction_rpc_send(int8_t transaction_id, uint8_t initiator2target_buffer_size, const void *initiator2target_buffer);
+bool transaction_rpc_recv(int8_t transaction_id, uint8_t target2initiator_buffer_size, void *target2initiator_buffer);
+```
+
+By default, the inbound and outbound data is limited to a maximum of 32 bytes each. The sizes can be altered if required:
+
+```c
+// Master to slave:
+#define RPC_M2S_BUFFER_SIZE 48
+// Slave to master:
+#define RPC_S2M_BUFFER_SIZE 48
+```
### Hardware Configuration Options
diff --git a/drivers/avr/i2c_master.c b/drivers/avr/i2c_master.c
index b1e4885298..2773e00778 100644
--- a/drivers/avr/i2c_master.c
+++ b/drivers/avr/i2c_master.c
@@ -28,8 +28,14 @@
# define F_SCL 400000UL // SCL frequency
#endif
+#ifndef I2C_START_RETRY_COUNT
+# define I2C_START_RETRY_COUNT 20
+#endif // I2C_START_RETRY_COUNT
+
#define TWBR_val (((F_CPU / F_SCL) - 16) / 2)
+#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+
void i2c_init(void) {
TWSR = 0; /* no prescaler */
TWBR = (uint8_t)TWBR_val;
@@ -47,7 +53,7 @@ void i2c_init(void) {
#endif
}
-i2c_status_t i2c_start(uint8_t address, uint16_t timeout) {
+static i2c_status_t i2c_start_impl(uint8_t address, uint16_t timeout) {
// reset TWI control register
TWCR = 0;
// transmit START condition
@@ -86,6 +92,17 @@ i2c_status_t i2c_start(uint8_t address, uint16_t timeout) {
return I2C_STATUS_SUCCESS;
}
+i2c_status_t i2c_start(uint8_t address, uint16_t timeout) {
+ // Retry i2c_start_impl a bunch times in case the remote side has interrupts disabled.
+ uint16_t timeout_timer = timer_read();
+ uint16_t time_slice = MAX(1, (timeout == (I2C_TIMEOUT_INFINITE)) ? 5 : (timeout / (I2C_START_RETRY_COUNT))); // if it's infinite, wait 1ms between attempts, otherwise split up the entire timeout into the number of retries
+ i2c_status_t status;
+ do {
+ status = i2c_start_impl(address, time_slice);
+ } while ((status < 0) && ((timeout == I2C_TIMEOUT_INFINITE) || (timer_elapsed(timeout_timer) < timeout)));
+ return status;
+}
+
i2c_status_t i2c_write(uint8_t data, uint16_t timeout) {
// load data into data register
TWDR = data;
diff --git a/drivers/avr/i2c_slave.c b/drivers/avr/i2c_slave.c
index 62a378165a..2907f164c0 100644
--- a/drivers/avr/i2c_slave.c
+++ b/drivers/avr/i2c_slave.c
@@ -17,6 +17,7 @@
* GitHub repository: https://github.com/g4lvanix/I2C-slave-lib
*/
+#include
#include
#include
#include
@@ -24,6 +25,12 @@
#include "i2c_slave.h"
+#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+# include "transactions.h"
+
+static volatile bool is_callback_executor = false;
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+
volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
static volatile uint8_t buffer_address;
@@ -48,11 +55,14 @@ ISR(TWI_vect) {
case TW_SR_SLA_ACK:
// The device is now a slave receiver
slave_has_register_set = false;
+#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ is_callback_executor = false;
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
break;
case TW_SR_DATA_ACK:
// This device is a slave receiver and has received data
- // First byte is the location then the bytes will be writen in buffer with auto-incriment
+ // First byte is the location then the bytes will be writen in buffer with auto-increment
if (!slave_has_register_set) {
buffer_address = TWDR;
@@ -60,10 +70,25 @@ ISR(TWI_vect) {
ack = 0;
buffer_address = 0;
}
- slave_has_register_set = true; // address has been receaved now fill in buffer
+ slave_has_register_set = true; // address has been received now fill in buffer
+
+#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ // Work out if we're attempting to execute a callback
+ is_callback_executor = buffer_address == split_transaction_table[I2C_EXECUTE_CALLBACK].initiator2target_offset;
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
} else {
i2c_slave_reg[buffer_address] = TWDR;
buffer_address++;
+
+#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ // If we're intending to execute a transaction callback, do so, as we've just received the transaction ID
+ if (is_callback_executor) {
+ split_transaction_desc_t *trans = &split_transaction_table[split_shmem->transaction_id];
+ if (trans->slave_callback) {
+ trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
+ }
+ }
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
}
break;
diff --git a/drivers/avr/i2c_slave.h b/drivers/avr/i2c_slave.h
index 1cd0625ef4..a8647c9da3 100644
--- a/drivers/avr/i2c_slave.h
+++ b/drivers/avr/i2c_slave.h
@@ -22,7 +22,18 @@
#pragma once
-#define I2C_SLAVE_REG_COUNT 30
+#ifndef I2C_SLAVE_REG_COUNT
+
+# if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+# include "transport.h"
+# define I2C_SLAVE_REG_COUNT sizeof(split_shared_memory_t)
+# else // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+# define I2C_SLAVE_REG_COUNT 30
+# endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+
+#endif // I2C_SLAVE_REG_COUNT
+
+_Static_assert(I2C_SLAVE_REG_COUNT < 256, "I2C target registers must be single byte");
extern volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
diff --git a/drivers/avr/serial.c b/drivers/avr/serial.c
index 3647bee0d3..9a7345a53d 100644
--- a/drivers/avr/serial.c
+++ b/drivers/avr/serial.c
@@ -224,15 +224,8 @@
# define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY / 2)
# define SLAVE_INT_WIDTH_US 1
-# ifndef SERIAL_USE_MULTI_TRANSACTION
-# define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
-# else
-# define SLAVE_INT_ACK_WIDTH_UNIT 2
-# define SLAVE_INT_ACK_WIDTH 4
-# endif
-
-static SSTD_t *Transaction_table = NULL;
-static uint8_t Transaction_table_size = 0;
+# define SLAVE_INT_ACK_WIDTH_UNIT 2
+# define SLAVE_INT_ACK_WIDTH 4
inline static void serial_delay(void) ALWAYS_INLINE;
inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
@@ -259,16 +252,12 @@ inline static void serial_low(void) { writePinLow(SOFT_SERIAL_PIN); }
inline static void serial_high(void) ALWAYS_INLINE;
inline static void serial_high(void) { writePinHigh(SOFT_SERIAL_PIN); }
-void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
+void soft_serial_initiator_init(void) {
serial_output();
serial_high();
}
-void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
+void soft_serial_target_init(void) {
serial_input_with_pullup();
// Enable INT0-INT7
@@ -395,19 +384,14 @@ static inline uint8_t nibble_bits_count(uint8_t bits) {
// interrupt handle to be used by the target device
ISR(SERIAL_PIN_INTERRUPT) {
-# ifndef SERIAL_USE_MULTI_TRANSACTION
- serial_low();
- serial_output();
- SSTD_t *trans = Transaction_table;
-# else
// recive transaction table index
uint8_t tid, bits;
uint8_t pecount = 0;
sync_recv();
- bits = serial_read_chunk(&pecount, 7);
+ bits = serial_read_chunk(&pecount, 8);
tid = bits >> 3;
- bits = (bits & 7) != nibble_bits_count(tid);
- if (bits || pecount > 0 || tid > Transaction_table_size) {
+ bits = (bits & 7) != (nibble_bits_count(tid) & 7);
+ if (bits || pecount > 0 || tid > NUM_TOTAL_TRANSACTIONS) {
return;
}
serial_delay_half1();
@@ -415,18 +399,22 @@ ISR(SERIAL_PIN_INTERRUPT) {
serial_high(); // response step1 low->high
serial_output();
_delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT * SLAVE_INT_ACK_WIDTH);
- SSTD_t *trans = &Transaction_table[tid];
+ split_transaction_desc_t *trans = &split_transaction_table[tid];
serial_low(); // response step2 ack high->low
-# endif
+
+ // If the transaction has a callback, we can execute it now
+ if (trans->slave_callback) {
+ trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
+ }
// target send phase
- if (trans->target2initiator_buffer_size > 0) serial_send_packet((uint8_t *)trans->target2initiator_buffer, trans->target2initiator_buffer_size);
+ if (trans->target2initiator_buffer_size > 0) serial_send_packet((uint8_t *)split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size);
// target switch to input
change_sender2reciver();
// target recive phase
if (trans->initiator2target_buffer_size > 0) {
- if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer, trans->initiator2target_buffer_size)) {
+ if (serial_recive_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
*trans->status = TRANSACTION_ACCEPTED;
} else {
*trans->status = TRANSACTION_DATA_ERROR;
@@ -448,14 +436,12 @@ ISR(SERIAL_PIN_INTERRUPT) {
// TRANSACTION_NO_RESPONSE
// TRANSACTION_DATA_ERROR
// this code is very time dependent, so we need to disable interrupts
-# ifndef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_transaction(void) {
- SSTD_t *trans = Transaction_table;
-# else
int soft_serial_transaction(int sstd_index) {
- if (sstd_index > Transaction_table_size) return TRANSACTION_TYPE_ERROR;
- SSTD_t *trans = &Transaction_table[sstd_index];
-# endif
+ if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
+ split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
+
+ if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
+
cli();
// signal to the target that we want to start a transaction
@@ -463,27 +449,11 @@ int soft_serial_transaction(int sstd_index) {
serial_low();
_delay_us(SLAVE_INT_WIDTH_US);
-# ifndef SERIAL_USE_MULTI_TRANSACTION
- // wait for the target response
- serial_input_with_pullup();
- _delay_us(SLAVE_INT_RESPONSE_TIME);
-
- // check if the target is present
- if (serial_read_pin()) {
- // target failed to pull the line low, assume not present
- serial_output();
- serial_high();
- *trans->status = TRANSACTION_NO_RESPONSE;
- sei();
- return TRANSACTION_NO_RESPONSE;
- }
-
-# else
// send transaction table index
int tid = (sstd_index << 3) | (7 & nibble_bits_count(sstd_index));
sync_send();
_delay_sub_us(TID_SEND_ADJUST);
- serial_write_chunk(tid, 7);
+ serial_write_chunk(tid, 8);
serial_delay_half1();
// wait for the target response (step1 low->high)
@@ -504,12 +474,11 @@ int soft_serial_transaction(int sstd_index) {
}
_delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
}
-# endif
// initiator recive phase
// if the target is present syncronize with it
if (trans->target2initiator_buffer_size > 0) {
- if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer, trans->target2initiator_buffer_size)) {
+ if (!serial_recive_packet((uint8_t *)split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
serial_output();
serial_high();
*trans->status = TRANSACTION_DATA_ERROR;
@@ -523,7 +492,7 @@ int soft_serial_transaction(int sstd_index) {
// initiator send phase
if (trans->initiator2target_buffer_size > 0) {
- serial_send_packet((uint8_t *)trans->initiator2target_buffer, trans->initiator2target_buffer_size);
+ serial_send_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size);
}
// always, release the line when not in use
@@ -534,9 +503,8 @@ int soft_serial_transaction(int sstd_index) {
return TRANSACTION_END;
}
-# ifdef SERIAL_USE_MULTI_TRANSACTION
int soft_serial_get_and_clean_status(int sstd_index) {
- SSTD_t *trans = &Transaction_table[sstd_index];
+ split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
cli();
int retval = *trans->status;
*trans->status = 0;
@@ -544,8 +512,6 @@ int soft_serial_get_and_clean_status(int sstd_index) {
sei();
return retval;
}
-# endif
-
#endif
// Helix serial.c history
diff --git a/drivers/avr/serial.h b/drivers/avr/serial.h
deleted file mode 100644
index 53e66cf905..0000000000
--- a/drivers/avr/serial.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#pragma once
-
-#include
-
-// /////////////////////////////////////////////////////////////////
-// Need Soft Serial defines in config.h
-// /////////////////////////////////////////////////////////////////
-// ex.
-// #define SOFT_SERIAL_PIN ?? // ?? = D0,D1,D2,D3,E6
-// OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5
-// // 1: about 137kbps (default)
-// // 2: about 75kbps
-// // 3: about 39kbps
-// // 4: about 26kbps
-// // 5: about 20kbps
-//
-// //// USE simple API (using signle-type transaction function)
-// /* nothing */
-// //// USE flexible API (using multi-type transaction function)
-// #define SERIAL_USE_MULTI_TRANSACTION
-//
-// /////////////////////////////////////////////////////////////////
-
-// Soft Serial Transaction Descriptor
-typedef struct _SSTD_t {
- uint8_t *status;
- uint8_t initiator2target_buffer_size;
- uint8_t *initiator2target_buffer;
- uint8_t target2initiator_buffer_size;
- uint8_t *target2initiator_buffer;
-} SSTD_t;
-#define TID_LIMIT(table) (sizeof(table) / sizeof(SSTD_t))
-
-// initiator is transaction start side
-void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size);
-// target is interrupt accept side
-void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size);
-
-// initiator resullt
-#define TRANSACTION_END 0
-#define TRANSACTION_NO_RESPONSE 0x1
-#define TRANSACTION_DATA_ERROR 0x2
-#define TRANSACTION_TYPE_ERROR 0x4
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_transaction(void);
-#else
-int soft_serial_transaction(int sstd_index);
-#endif
-
-// target status
-// *SSTD_t.status has
-// initiator:
-// TRANSACTION_END
-// or TRANSACTION_NO_RESPONSE
-// or TRANSACTION_DATA_ERROR
-// target:
-// TRANSACTION_DATA_ERROR
-// or TRANSACTION_ACCEPTED
-#define TRANSACTION_ACCEPTED 0x8
-#ifdef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_get_and_clean_status(int sstd_index);
-#endif
diff --git a/drivers/chibios/serial.c b/drivers/chibios/serial.c
index 54f7e1321f..f54fbcee4e 100644
--- a/drivers/chibios/serial.c
+++ b/drivers/chibios/serial.c
@@ -74,21 +74,12 @@ static THD_FUNCTION(Thread1, arg) {
}
}
-static SSTD_t *Transaction_table = NULL;
-static uint8_t Transaction_table_size = 0;
-
-void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
-
+void soft_serial_initiator_init(void) {
serial_output();
serial_high();
}
-void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
-
+void soft_serial_target_init(void) {
serial_input();
palEnablePadEvent(PAL_PORT(SOFT_SERIAL_PIN), PAL_PAD(SOFT_SERIAL_PIN), PAL_EVENT_MODE_FALLING_EDGE);
@@ -154,16 +145,14 @@ void interrupt_handler(void *arg) {
uint8_t checksum_computed = 0;
int sstd_index = 0;
-#ifdef SERIAL_USE_MULTI_TRANSACTION
sstd_index = serial_read_byte();
sync_send();
-#endif
- SSTD_t *trans = &Transaction_table[sstd_index];
+ split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
for (int i = 0; i < trans->initiator2target_buffer_size; ++i) {
- trans->initiator2target_buffer[i] = serial_read_byte();
+ split_trans_initiator2target_buffer(trans)[i] = serial_read_byte();
sync_send();
- checksum_computed += trans->initiator2target_buffer[i];
+ checksum_computed += split_trans_initiator2target_buffer(trans)[i];
}
checksum_computed ^= 7;
uint8_t checksum_received = serial_read_byte();
@@ -172,12 +161,17 @@ void interrupt_handler(void *arg) {
// wait for the sync to finish sending
serial_delay();
+ // Allow any slave processing to occur
+ if (trans->slave_callback) {
+ trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
+ }
+
uint8_t checksum = 0;
for (int i = 0; i < trans->target2initiator_buffer_size; ++i) {
- serial_write_byte(trans->target2initiator_buffer[i]);
+ serial_write_byte(split_trans_target2initiator_buffer(trans)[i]);
sync_send();
serial_delay_half();
- checksum += trans->target2initiator_buffer[i];
+ checksum += split_trans_target2initiator_buffer(trans)[i];
}
serial_write_byte(checksum ^ 7);
sync_send();
@@ -206,15 +200,10 @@ void interrupt_handler(void *arg) {
// TRANSACTION_NO_RESPONSE
// TRANSACTION_DATA_ERROR
// this code is very time dependent, so we need to disable interrupts
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_transaction(void) {
- int sstd_index = 0;
-#else
int soft_serial_transaction(int sstd_index) {
-#endif
-
- if (sstd_index > Transaction_table_size) return TRANSACTION_TYPE_ERROR;
- SSTD_t *trans = &Transaction_table[sstd_index];
+ if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
+ split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
+ if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
// TODO: remove extra delay between transactions
serial_delay();
@@ -244,14 +233,13 @@ int soft_serial_transaction(int sstd_index) {
uint8_t checksum = 0;
// send data to the slave
-#ifdef SERIAL_USE_MULTI_TRANSACTION
serial_write_byte(sstd_index); // first chunk is transaction id
sync_recv();
-#endif
+
for (int i = 0; i < trans->initiator2target_buffer_size; ++i) {
- serial_write_byte(trans->initiator2target_buffer[i]);
+ serial_write_byte(split_trans_initiator2target_buffer(trans)[i]);
sync_recv();
- checksum += trans->initiator2target_buffer[i];
+ checksum += split_trans_initiator2target_buffer(trans)[i];
}
serial_write_byte(checksum ^ 7);
sync_recv();
@@ -262,9 +250,9 @@ int soft_serial_transaction(int sstd_index) {
// receive data from the slave
uint8_t checksum_computed = 0;
for (int i = 0; i < trans->target2initiator_buffer_size; ++i) {
- trans->target2initiator_buffer[i] = serial_read_byte();
+ split_trans_target2initiator_buffer(trans)[i] = serial_read_byte();
sync_recv();
- checksum_computed += trans->target2initiator_buffer[i];
+ checksum_computed += split_trans_target2initiator_buffer(trans)[i];
}
checksum_computed ^= 7;
uint8_t checksum_received = serial_read_byte();
diff --git a/drivers/chibios/serial.h b/drivers/chibios/serial.h
deleted file mode 100644
index 0c1857d52e..0000000000
--- a/drivers/chibios/serial.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#pragma once
-
-#include
-
-// /////////////////////////////////////////////////////////////////
-// Need Soft Serial defines in config.h
-// /////////////////////////////////////////////////////////////////
-// ex.
-// #define SOFT_SERIAL_PIN ?? // ?? = D0,D1,D2,D3,E6
-// OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5
-// // 1: about 137kbps (default)
-// // 2: about 75kbps
-// // 3: about 39kbps
-// // 4: about 26kbps
-// // 5: about 20kbps
-//
-// //// USE simple API (using signle-type transaction function)
-// /* nothing */
-// //// USE flexible API (using multi-type transaction function)
-// #define SERIAL_USE_MULTI_TRANSACTION
-//
-// /////////////////////////////////////////////////////////////////
-
-// Soft Serial Transaction Descriptor
-typedef struct _SSTD_t {
- uint8_t *status;
- uint8_t initiator2target_buffer_size;
- uint8_t *initiator2target_buffer;
- uint8_t target2initiator_buffer_size;
- uint8_t *target2initiator_buffer;
-} SSTD_t;
-#define TID_LIMIT(table) (sizeof(table) / sizeof(SSTD_t))
-
-// initiator is transaction start side
-void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size);
-// target is interrupt accept side
-void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size);
-
-// initiator result
-#define TRANSACTION_END 0
-#define TRANSACTION_NO_RESPONSE 0x1
-#define TRANSACTION_DATA_ERROR 0x2
-#define TRANSACTION_TYPE_ERROR 0x4
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_transaction(void);
-#else
-int soft_serial_transaction(int sstd_index);
-#endif
-
-// target status
-// *SSTD_t.status has
-// initiator:
-// TRANSACTION_END
-// or TRANSACTION_NO_RESPONSE
-// or TRANSACTION_DATA_ERROR
-// target:
-// TRANSACTION_DATA_ERROR
-// or TRANSACTION_ACCEPTED
-#define TRANSACTION_ACCEPTED 0x8
-#ifdef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_get_and_clean_status(int sstd_index);
-#endif
diff --git a/drivers/chibios/serial_usart.c b/drivers/chibios/serial_usart.c
index cae29388c3..9f180d2d74 100644
--- a/drivers/chibios/serial_usart.c
+++ b/drivers/chibios/serial_usart.c
@@ -113,37 +113,29 @@ void usart_slave_init(void) {
chThdCreateStatic(waSlaveThread, sizeof(waSlaveThread), HIGHPRIO, SlaveThread, NULL);
}
-static SSTD_t* Transaction_table = NULL;
-static uint8_t Transaction_table_size = 0;
+void soft_serial_initiator_init(void) { usart_master_init(); }
-void soft_serial_initiator_init(SSTD_t* sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
-
- usart_master_init();
-}
-
-void soft_serial_target_init(SSTD_t* sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
-
- usart_slave_init();
-}
+void soft_serial_target_init(void) { usart_slave_init(); }
void handle_soft_serial_slave(void) {
- uint8_t sstd_index = sdGet(&SERIAL_USART_DRIVER); // first chunk is always transaction id
- SSTD_t* trans = &Transaction_table[sstd_index];
+ uint8_t sstd_index = sdGet(&SERIAL_USART_DRIVER); // first chunk is always transaction id
+ split_transaction_desc_t* trans = &split_transaction_table[sstd_index];
// Always write back the sstd_index as part of a basic handshake
sstd_index ^= HANDSHAKE_MAGIC;
sdWrite(&SERIAL_USART_DRIVER, &sstd_index, sizeof(sstd_index));
if (trans->initiator2target_buffer_size) {
- sdRead(&SERIAL_USART_DRIVER, trans->initiator2target_buffer, trans->initiator2target_buffer_size);
+ sdRead(&SERIAL_USART_DRIVER, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size);
+ }
+
+ // Allow any slave processing to occur
+ if (trans->slave_callback) {
+ trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
}
if (trans->target2initiator_buffer_size) {
- sdWrite(&SERIAL_USART_DRIVER, trans->target2initiator_buffer, trans->target2initiator_buffer_size);
+ sdWrite(&SERIAL_USART_DRIVER, split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size);
}
if (trans->status) {
@@ -160,17 +152,14 @@ void handle_soft_serial_slave(void) {
// TRANSACTION_END
// TRANSACTION_NO_RESPONSE
// TRANSACTION_DATA_ERROR
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_transaction(void) {
- uint8_t sstd_index = 0;
-#else
int soft_serial_transaction(int index) {
uint8_t sstd_index = index;
-#endif
- if (sstd_index > Transaction_table_size) return TRANSACTION_TYPE_ERROR;
- SSTD_t* trans = &Transaction_table[sstd_index];
- msg_t res = 0;
+ if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
+ split_transaction_desc_t* trans = &split_transaction_table[sstd_index];
+ msg_t res = 0;
+
+ if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
sdClear(&SERIAL_USART_DRIVER);
@@ -189,7 +178,7 @@ int soft_serial_transaction(int index) {
}
if (trans->initiator2target_buffer_size) {
- res = sdWriteTimeout(&SERIAL_USART_DRIVER, trans->initiator2target_buffer, trans->initiator2target_buffer_size, TIME_MS2I(SERIAL_USART_TIMEOUT));
+ res = sdWriteTimeout(&SERIAL_USART_DRIVER, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, TIME_MS2I(SERIAL_USART_TIMEOUT));
if (res < 0) {
dprintf("serial::usart_transmit NO_RESPONSE\n");
return TRANSACTION_NO_RESPONSE;
@@ -197,7 +186,7 @@ int soft_serial_transaction(int index) {
}
if (trans->target2initiator_buffer_size) {
- res = sdReadTimeout(&SERIAL_USART_DRIVER, trans->target2initiator_buffer, trans->target2initiator_buffer_size, TIME_MS2I(SERIAL_USART_TIMEOUT));
+ res = sdReadTimeout(&SERIAL_USART_DRIVER, split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size, TIME_MS2I(SERIAL_USART_TIMEOUT));
if (res < 0) {
dprintf("serial::usart_receive NO_RESPONSE\n");
return TRANSACTION_NO_RESPONSE;
diff --git a/drivers/serial.h b/drivers/serial.h
new file mode 100644
index 0000000000..d9c2a69e96
--- /dev/null
+++ b/drivers/serial.h
@@ -0,0 +1,46 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+#include
+
+// initiator is transaction start side
+void soft_serial_initiator_init(void);
+// target is interrupt accept side
+void soft_serial_target_init(void);
+
+// initiator result
+#define TRANSACTION_END 0
+#define TRANSACTION_NO_RESPONSE 0x1
+#define TRANSACTION_DATA_ERROR 0x2
+#define TRANSACTION_TYPE_ERROR 0x4
+int soft_serial_transaction(int sstd_index);
+
+// target status
+// *SSTD_t.status has
+// initiator:
+// TRANSACTION_END
+// or TRANSACTION_NO_RESPONSE
+// or TRANSACTION_DATA_ERROR
+// target:
+// TRANSACTION_DATA_ERROR
+// or TRANSACTION_ACCEPTED
+#define TRANSACTION_ACCEPTED 0x8
+int soft_serial_get_and_clean_status(int sstd_index);
diff --git a/keyboards/draculad/config.h b/keyboards/draculad/config.h
index 8a27fdea4d..d8a9fbd37c 100644
--- a/keyboards/draculad/config.h
+++ b/keyboards/draculad/config.h
@@ -65,3 +65,5 @@ along with this program. If not, see .
#define UNUSED_PINS
#define EE_HANDS
+
+#define LAYER_STATE_8BIT
\ No newline at end of file
diff --git a/keyboards/handwired/freoduo/rules.mk b/keyboards/handwired/freoduo/rules.mk
index e3da3753e4..d8923557d6 100644
--- a/keyboards/handwired/freoduo/rules.mk
+++ b/keyboards/handwired/freoduo/rules.mk
@@ -11,7 +11,7 @@ BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration
MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control
CONSOLE_ENABLE = no # Console for debug
-COMMAND_ENABLE = yes # Commands for debug and configuration
+COMMAND_ENABLE = no # Commands for debug and configuration
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
@@ -21,4 +21,4 @@ RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
BLUETOOTH_ENABLE = no # Enable Bluetooth
AUDIO_ENABLE = no # Audio output
VELOCIKEY_ENABLE = yes
-SPLIT_KEYBOARD = yes
\ No newline at end of file
+SPLIT_KEYBOARD = yes
diff --git a/keyboards/helix/rev2/keymaps/default/rules.mk b/keyboards/helix/rev2/keymaps/default/rules.mk
index 206e836ec0..c16f3e2b87 100644
--- a/keyboards/helix/rev2/keymaps/default/rules.mk
+++ b/keyboards/helix/rev2/keymaps/default/rules.mk
@@ -5,7 +5,7 @@
# See TOP/keyboards/helix/rules.mk for a list of options that can be set.
# See TOP/docs/config_options.md for more information.
#
-LTO_ENABLE = no # if firmware size over limit, try this option
+LTO_ENABLE = yes # if firmware size over limit, try this option
# Helix Spacific Build Options
# you can uncomment and edit follows 7 Variables
diff --git a/keyboards/keebio/iris/rev2/rules.mk b/keyboards/keebio/iris/rev2/rules.mk
index 765fa7f07a..197bad4764 100644
--- a/keyboards/keebio/iris/rev2/rules.mk
+++ b/keyboards/keebio/iris/rev2/rules.mk
@@ -32,3 +32,5 @@ RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight.
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
SPLIT_KEYBOARD = yes
+
+LTO_ENABLE = yes
\ No newline at end of file
diff --git a/keyboards/keebio/iris/rev3/rules.mk b/keyboards/keebio/iris/rev3/rules.mk
index ea92bc98f5..b64eab5a4b 100644
--- a/keyboards/keebio/iris/rev3/rules.mk
+++ b/keyboards/keebio/iris/rev3/rules.mk
@@ -33,3 +33,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
SPLIT_KEYBOARD = yes
ENCODER_ENABLE = yes
+LTO_ENABLE = yes
\ No newline at end of file
diff --git a/keyboards/keebio/iris/rev4/rules.mk b/keyboards/keebio/iris/rev4/rules.mk
index ea92bc98f5..9bf5688da0 100644
--- a/keyboards/keebio/iris/rev4/rules.mk
+++ b/keyboards/keebio/iris/rev4/rules.mk
@@ -33,3 +33,5 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
SPLIT_KEYBOARD = yes
ENCODER_ENABLE = yes
+
+LTO_ENABLE = yes
\ No newline at end of file
diff --git a/keyboards/keebio/quefrency/rules.mk b/keyboards/keebio/quefrency/rules.mk
index 2c5ad0c36b..c674e10162 100644
--- a/keyboards/keebio/quefrency/rules.mk
+++ b/keyboards/keebio/quefrency/rules.mk
@@ -19,3 +19,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
SPLIT_KEYBOARD = yes
DEFAULT_FOLDER = keebio/quefrency/rev1
+LTO_ENABLE = yes
diff --git a/keyboards/keebio/viterbi/rev2/rules.mk b/keyboards/keebio/viterbi/rev2/rules.mk
index f95e7ae6a4..829d6a56e0 100644
--- a/keyboards/keebio/viterbi/rev2/rules.mk
+++ b/keyboards/keebio/viterbi/rev2/rules.mk
@@ -1,3 +1,5 @@
BACKLIGHT_ENABLE = yes
LAYOUTS = ortho_5x14
+
+LTO_ENABLE = yes
\ No newline at end of file
diff --git a/keyboards/keebio/viterbi/rules.mk b/keyboards/keebio/viterbi/rules.mk
index 0b746d1720..92576d33e8 100644
--- a/keyboards/keebio/viterbi/rules.mk
+++ b/keyboards/keebio/viterbi/rules.mk
@@ -19,16 +19,16 @@ BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration
MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control
CONSOLE_ENABLE = no # Console for debug
-COMMAND_ENABLE = yes # Commands for debug and configuration
+COMMAND_ENABLE = no # Commands for debug and configuration
NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
-BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
+BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = no # Audio output on port C6
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
-RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight.
+RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight.
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
-SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
+SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
SPLIT_KEYBOARD = yes
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index 2cf7b70582..56d91b07fe 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -23,9 +23,11 @@ along with this program. If not, see .
#include "quantum.h"
#include "split_util.h"
#include "config.h"
-#include "transport.h"
+#include "transactions.h"
-#define ERROR_DISCONNECT_COUNT 5
+#ifndef ERROR_DISCONNECT_COUNT
+# define ERROR_DISCONNECT_COUNT 5
+#endif // ERROR_DISCONNECT_COUNT
#define ROWS_PER_HAND (MATRIX_ROWS / 2)
diff --git a/quantum/split_common/post_config.h b/quantum/split_common/post_config.h
index 4ae1d52732..a4c0a1956b 100644
--- a/quantum/split_common/post_config.h
+++ b/quantum/split_common/post_config.h
@@ -7,13 +7,4 @@
# ifndef F_SCL
# define F_SCL 100000UL // SCL frequency
# endif
-
-#else // use serial
-// When using serial, the user must define RGBLIGHT_SPLIT explicitly
-// in config.h as needed.
-// see quantum/rgblight_post_config.h
-# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
-// When using serial and RGBLIGHT_SPLIT need separate transaction
-# define SERIAL_USE_MULTI_TRANSACTION
-# endif
#endif
diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h
new file mode 100644
index 0000000000..464c73478a
--- /dev/null
+++ b/quantum/split_common/transaction_id_define.h
@@ -0,0 +1,94 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+enum serial_transaction_id {
+#ifdef USE_I2C
+ I2C_EXECUTE_CALLBACK,
+#endif // USE_I2C
+
+ GET_SLAVE_MATRIX_CHECKSUM,
+ GET_SLAVE_MATRIX_DATA,
+
+#ifdef SPLIT_TRANSPORT_MIRROR
+ PUT_MASTER_MATRIX,
+#endif // SPLIT_TRANSPORT_MIRROR
+
+#ifdef ENCODER_ENABLE
+ GET_ENCODERS_CHECKSUM,
+ GET_ENCODERS_DATA,
+#endif // ENCODER_ENABLE
+
+#ifndef DISABLE_SYNC_TIMER
+ PUT_SYNC_TIMER,
+#endif // DISABLE_SYNC_TIMER
+
+#if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+ PUT_LAYER_STATE,
+ PUT_DEFAULT_LAYER_STATE,
+#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+
+#ifdef SPLIT_LED_STATE_ENABLE
+ PUT_LED_STATE,
+#endif // SPLIT_LED_STATE_ENABLE
+
+#ifdef SPLIT_MODS_ENABLE
+ PUT_MODS,
+#endif // SPLIT_MODS_ENABLE
+
+#ifdef BACKLIGHT_ENABLE
+ PUT_BACKLIGHT,
+#endif // BACKLIGHT_ENABLE
+
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+ PUT_RGBLIGHT,
+#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+
+#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+ PUT_LED_MATRIX,
+#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+
+#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
+ PUT_RGB_MATRIX,
+#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+
+#if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
+ PUT_WPM,
+#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
+
+#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+ PUT_RPC_INFO,
+ PUT_RPC_REQ_DATA,
+ EXECUTE_RPC,
+ GET_RPC_RESP_DATA,
+#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+
+// keyboard-specific
+#ifdef SPLIT_TRANSACTION_IDS_KB
+ SPLIT_TRANSACTION_IDS_KB,
+#endif // SPLIT_TRANSACTION_IDS_KB
+
+// user/keymap-specific
+#ifdef SPLIT_TRANSACTION_IDS_USER
+ SPLIT_TRANSACTION_IDS_USER,
+#endif // SPLIT_TRANSACTION_IDS_USER
+
+ NUM_TOTAL_TRANSACTIONS
+};
+
+// Ensure we only use 5 bits for transaction
+_Static_assert(NUM_TOTAL_TRANSACTIONS <= (1 << 5), "Max number of usable transactions exceeded");
diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c
new file mode 100644
index 0000000000..99a8623b3c
--- /dev/null
+++ b/quantum/split_common/transactions.c
@@ -0,0 +1,670 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+
+#include "debug.h"
+#include "matrix.h"
+#include "quantum.h"
+#include "transactions.h"
+#include "transport.h"
+#include "transaction_id_define.h"
+
+#define SYNC_TIMER_OFFSET 2
+
+#ifndef FORCED_SYNC_THROTTLE_MS
+# define FORCED_SYNC_THROTTLE_MS 100
+#endif // FORCED_SYNC_THROTTLE_MS
+
+#define sizeof_member(type, member) sizeof(((type *)NULL)->member)
+
+#define trans_initiator2target_initializer_cb(member, cb) \
+ { &dummy, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), 0, 0, cb }
+#define trans_initiator2target_initializer(member) trans_initiator2target_initializer_cb(member, NULL)
+
+#define trans_target2initiator_initializer_cb(member, cb) \
+ { &dummy, 0, 0, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), cb }
+#define trans_target2initiator_initializer(member) trans_target2initiator_initializer_cb(member, NULL)
+
+#define transport_write(id, data, length) transport_execute_transaction(id, data, length, NULL, 0)
+#define transport_read(id, data, length) transport_execute_transaction(id, NULL, 0, data, length)
+
+static uint8_t crc8(const void *data, size_t len) {
+ const uint8_t *p = (const uint8_t *)data;
+ uint8_t crc = 0xff;
+ size_t i, j;
+ for (i = 0; i < len; i++) {
+ crc ^= p[i];
+ for (j = 0; j < 8; j++) {
+ if ((crc & 0x80) != 0)
+ crc = (uint8_t)((crc << 1) ^ 0x31);
+ else
+ crc <<= 1;
+ }
+ }
+ return crc;
+}
+
+#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+// Forward-declare the RPC callback handlers
+void slave_rpc_info_callback(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer);
+void slave_rpc_exec_callback(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer);
+#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+
+////////////////////////////////////////////////////
+// Helpers
+
+bool transaction_handler_master(bool okay, matrix_row_t master_matrix[], matrix_row_t slave_matrix[], const char *prefix, bool (*handler)(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])) {
+ if (okay) {
+ bool this_okay = true;
+ for (int iter = 1; iter <= 10; ++iter) {
+ if (!this_okay) {
+ for (int i = 0; i < iter * iter; ++i) {
+ wait_us(10);
+ }
+ }
+ ATOMIC_BLOCK_FORCEON { this_okay = handler(master_matrix, slave_matrix); };
+ if (this_okay) break;
+ }
+ okay &= this_okay;
+ if (!okay) {
+ dprintf("Failed to execute %s\n", prefix);
+ }
+ }
+ return okay;
+}
+
+#define TRANSACTION_HANDLER_MASTER(prefix) \
+ do { \
+ okay &= transaction_handler_master(okay, master_matrix, slave_matrix, #prefix, &prefix##_master); \
+ } while (0)
+
+#define TRANSACTION_HANDLER_SLAVE(prefix) \
+ do { \
+ ATOMIC_BLOCK_FORCEON { prefix##_slave(master_matrix, slave_matrix); }; \
+ } while (0)
+
+inline static bool read_if_checksum_mismatch(int8_t trans_id_checksum, int8_t trans_id_retrieve, uint32_t *last_update, void *destination, const void *equiv_shmem, size_t length) {
+ uint8_t curr_checksum;
+ bool okay = transport_read(trans_id_checksum, &curr_checksum, sizeof(curr_checksum));
+ if (okay && (timer_elapsed32(*last_update) >= FORCED_SYNC_THROTTLE_MS || curr_checksum != crc8(equiv_shmem, length))) {
+ okay &= transport_read(trans_id_retrieve, destination, length);
+ okay &= curr_checksum == crc8(equiv_shmem, length);
+ if (okay) {
+ *last_update = timer_read32();
+ }
+ } else {
+ memcpy(destination, equiv_shmem, length);
+ }
+ return okay;
+}
+
+inline static bool send_if_condition(int8_t trans_id, uint32_t *last_update, bool condition, void *source, size_t length) {
+ bool okay = true;
+ if (timer_elapsed32(*last_update) >= FORCED_SYNC_THROTTLE_MS || condition) {
+ okay &= transport_write(trans_id, source, length);
+ if (okay) {
+ *last_update = timer_read32();
+ }
+ }
+ return okay;
+}
+
+inline static bool send_if_data_mismatch(int8_t trans_id, uint32_t *last_update, void *source, const void *equiv_shmem, size_t length) {
+ // Just run a memcmp to compare the source and equivalent shmem location
+ return send_if_condition(trans_id, last_update, (memcmp(source, equiv_shmem, length) != 0), source, length);
+}
+
+////////////////////////////////////////////////////
+// Slave matrix
+
+static bool slave_matrix_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ static matrix_row_t last_matrix[(MATRIX_ROWS) / 2] = {0}; // last successfully-read matrix, so we can replicate if there are checksum errors
+ matrix_row_t temp_matrix[(MATRIX_ROWS) / 2]; // holding area while we test whether or not checksum is correct
+
+ bool okay = read_if_checksum_mismatch(GET_SLAVE_MATRIX_CHECKSUM, GET_SLAVE_MATRIX_DATA, &last_update, temp_matrix, split_shmem->smatrix.matrix, sizeof(split_shmem->smatrix.matrix));
+ if (okay) {
+ // Checksum matches the received data, save as the last matrix state
+ memcpy(last_matrix, temp_matrix, sizeof(temp_matrix));
+ }
+ // Copy out the last-known-good matrix state to the slave matrix
+ memcpy(slave_matrix, last_matrix, sizeof(last_matrix));
+ return okay;
+}
+
+static void slave_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ memcpy(split_shmem->smatrix.matrix, slave_matrix, sizeof(split_shmem->smatrix.matrix));
+ split_shmem->smatrix.checksum = crc8(split_shmem->smatrix.matrix, sizeof(split_shmem->smatrix.matrix));
+}
+
+// clang-format off
+#define TRANSACTIONS_SLAVE_MATRIX_MASTER() TRANSACTION_HANDLER_MASTER(slave_matrix_handlers)
+#define TRANSACTIONS_SLAVE_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(slave_matrix_handlers)
+#define TRANSACTIONS_SLAVE_MATRIX_REGISTRATIONS \
+ [GET_SLAVE_MATRIX_CHECKSUM] = trans_target2initiator_initializer(smatrix.checksum), \
+ [GET_SLAVE_MATRIX_DATA] = trans_target2initiator_initializer(smatrix.matrix),
+// clang-format on
+
+////////////////////////////////////////////////////
+// Master matrix
+
+#ifdef SPLIT_TRANSPORT_MIRROR
+
+static bool master_matrix_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ return send_if_data_mismatch(PUT_MASTER_MATRIX, &last_update, master_matrix, split_shmem->mmatrix.matrix, sizeof(split_shmem->mmatrix.matrix));
+}
+
+static void master_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ // Always copy to the master matrix
+ memcpy(master_matrix, split_shmem->mmatrix.matrix, sizeof(split_shmem->mmatrix.matrix));
+}
+
+# define TRANSACTIONS_MASTER_MATRIX_MASTER() TRANSACTION_HANDLER_MASTER(master_matrix_handlers)
+# define TRANSACTIONS_MASTER_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(master_matrix_handlers)
+# define TRANSACTIONS_MASTER_MATRIX_REGISTRATIONS [PUT_MASTER_MATRIX] = trans_initiator2target_initializer(mmatrix.matrix),
+
+#else // SPLIT_TRANSPORT_MIRROR
+
+# define TRANSACTIONS_MASTER_MATRIX_MASTER()
+# define TRANSACTIONS_MASTER_MATRIX_SLAVE()
+# define TRANSACTIONS_MASTER_MATRIX_REGISTRATIONS
+
+#endif // SPLIT_TRANSPORT_MIRROR
+
+////////////////////////////////////////////////////
+// Encoders
+
+#ifdef ENCODER_ENABLE
+
+static bool encoder_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ uint8_t temp_state[NUMBER_OF_ENCODERS];
+
+ bool okay = read_if_checksum_mismatch(GET_ENCODERS_CHECKSUM, GET_ENCODERS_DATA, &last_update, temp_state, split_shmem->encoders.state, sizeof(temp_state));
+ if (okay) encoder_update_raw(temp_state);
+ return okay;
+}
+
+static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ uint8_t encoder_state[NUMBER_OF_ENCODERS];
+ encoder_state_raw(encoder_state);
+ // Always prepare the encoder state for read.
+ memcpy(split_shmem->encoders.state, encoder_state, sizeof(encoder_state));
+ // Now update the checksum given that the encoders has been written to
+ split_shmem->encoders.checksum = crc8(encoder_state, sizeof(encoder_state));
+}
+
+// clang-format off
+# define TRANSACTIONS_ENCODERS_MASTER() TRANSACTION_HANDLER_MASTER(encoder_handlers)
+# define TRANSACTIONS_ENCODERS_SLAVE() TRANSACTION_HANDLER_SLAVE(encoder_handlers)
+# define TRANSACTIONS_ENCODERS_REGISTRATIONS \
+ [GET_ENCODERS_CHECKSUM] = trans_target2initiator_initializer(encoders.checksum), \
+ [GET_ENCODERS_DATA] = trans_target2initiator_initializer(encoders.state),
+// clang-format on
+
+#else // ENCODER_ENABLE
+
+# define TRANSACTIONS_ENCODERS_MASTER()
+# define TRANSACTIONS_ENCODERS_SLAVE()
+# define TRANSACTIONS_ENCODERS_REGISTRATIONS
+
+#endif // ENCODER_ENABLE
+
+////////////////////////////////////////////////////
+// Sync timer
+
+#ifndef DISABLE_SYNC_TIMER
+
+static bool sync_timer_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+
+ bool okay = true;
+ if (timer_elapsed32(last_update) >= FORCED_SYNC_THROTTLE_MS) {
+ uint32_t sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
+ okay &= transport_write(PUT_SYNC_TIMER, &sync_timer, sizeof(sync_timer));
+ if (okay) {
+ last_update = timer_read32();
+ }
+ }
+ return okay;
+}
+
+static void sync_timer_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_sync_timer = 0;
+ if (last_sync_timer != split_shmem->sync_timer) {
+ last_sync_timer = split_shmem->sync_timer;
+ sync_timer_update(last_sync_timer);
+ }
+}
+
+# define TRANSACTIONS_SYNC_TIMER_MASTER() TRANSACTION_HANDLER_MASTER(sync_timer_handlers)
+# define TRANSACTIONS_SYNC_TIMER_SLAVE() TRANSACTION_HANDLER_SLAVE(sync_timer_handlers)
+# define TRANSACTIONS_SYNC_TIMER_REGISTRATIONS [PUT_SYNC_TIMER] = trans_initiator2target_initializer(sync_timer),
+
+#else // DISABLE_SYNC_TIMER
+
+# define TRANSACTIONS_SYNC_TIMER_MASTER()
+# define TRANSACTIONS_SYNC_TIMER_SLAVE()
+# define TRANSACTIONS_SYNC_TIMER_REGISTRATIONS
+
+#endif // DISABLE_SYNC_TIMER
+
+////////////////////////////////////////////////////
+// Layer state
+
+#if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+
+static bool layer_state_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_layer_state_update = 0;
+ static uint32_t last_default_layer_state_update = 0;
+
+ bool okay = send_if_condition(PUT_LAYER_STATE, &last_layer_state_update, (layer_state != split_shmem->layers.layer_state), &layer_state, sizeof(layer_state));
+ if (okay) {
+ okay &= send_if_condition(PUT_DEFAULT_LAYER_STATE, &last_default_layer_state_update, (default_layer_state != split_shmem->layers.default_layer_state), &default_layer_state, sizeof(default_layer_state));
+ }
+ return okay;
+}
+
+static void layer_state_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ layer_state = split_shmem->layers.layer_state;
+ default_layer_state = split_shmem->layers.default_layer_state;
+}
+
+// clang-format off
+# define TRANSACTIONS_LAYER_STATE_MASTER() TRANSACTION_HANDLER_MASTER(layer_state_handlers)
+# define TRANSACTIONS_LAYER_STATE_SLAVE() TRANSACTION_HANDLER_SLAVE(layer_state_handlers)
+# define TRANSACTIONS_LAYER_STATE_REGISTRATIONS \
+ [PUT_LAYER_STATE] = trans_initiator2target_initializer(layers.layer_state), \
+ [PUT_DEFAULT_LAYER_STATE] = trans_initiator2target_initializer(layers.default_layer_state),
+// clang-format on
+
+#else // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+
+# define TRANSACTIONS_LAYER_STATE_MASTER()
+# define TRANSACTIONS_LAYER_STATE_SLAVE()
+# define TRANSACTIONS_LAYER_STATE_REGISTRATIONS
+
+#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+
+////////////////////////////////////////////////////
+// LED state
+
+#ifdef SPLIT_LED_STATE_ENABLE
+
+static bool led_state_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ uint8_t led_state = host_keyboard_leds();
+ return send_if_data_mismatch(PUT_LED_STATE, &last_update, &led_state, &split_shmem->led_state, sizeof(led_state));
+}
+
+static void led_state_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ void set_split_host_keyboard_leds(uint8_t led_state);
+ set_split_host_keyboard_leds(split_shmem->led_state);
+}
+
+# define TRANSACTIONS_LED_STATE_MASTER() TRANSACTION_HANDLER_MASTER(led_state_handlers)
+# define TRANSACTIONS_LED_STATE_SLAVE() TRANSACTION_HANDLER_SLAVE(led_state_handlers)
+# define TRANSACTIONS_LED_STATE_REGISTRATIONS [PUT_LED_STATE] = trans_initiator2target_initializer(led_state),
+
+#else // SPLIT_LED_STATE_ENABLE
+
+# define TRANSACTIONS_LED_STATE_MASTER()
+# define TRANSACTIONS_LED_STATE_SLAVE()
+# define TRANSACTIONS_LED_STATE_REGISTRATIONS
+
+#endif // SPLIT_LED_STATE_ENABLE
+
+////////////////////////////////////////////////////
+// Mods
+
+#ifdef SPLIT_MODS_ENABLE
+
+static bool mods_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ bool mods_need_sync = timer_elapsed32(last_update) >= FORCED_SYNC_THROTTLE_MS;
+ split_mods_sync_t new_mods;
+ new_mods.real_mods = get_mods();
+ if (!mods_need_sync && new_mods.real_mods != split_shmem->mods.real_mods) {
+ mods_need_sync = true;
+ }
+
+ new_mods.weak_mods = get_weak_mods();
+ if (!mods_need_sync && new_mods.weak_mods != split_shmem->mods.weak_mods) {
+ mods_need_sync = true;
+ }
+
+# ifndef NO_ACTION_ONESHOT
+ new_mods.oneshot_mods = get_oneshot_mods();
+ if (!mods_need_sync && new_mods.oneshot_mods != split_shmem->mods.oneshot_mods) {
+ mods_need_sync = true;
+ }
+# endif // NO_ACTION_ONESHOT
+
+ bool okay = true;
+ if (mods_need_sync) {
+ okay &= transport_write(PUT_MODS, &new_mods, sizeof(new_mods));
+ if (okay) {
+ last_update = timer_read32();
+ }
+ }
+
+ return okay;
+}
+
+static void mods_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ set_mods(split_shmem->mods.real_mods);
+ set_weak_mods(split_shmem->mods.weak_mods);
+# ifndef NO_ACTION_ONESHOT
+ set_oneshot_mods(split_shmem->mods.oneshot_mods);
+# endif
+}
+
+# define TRANSACTIONS_MODS_MASTER() TRANSACTION_HANDLER_MASTER(mods_handlers)
+# define TRANSACTIONS_MODS_SLAVE() TRANSACTION_HANDLER_SLAVE(mods_handlers)
+# define TRANSACTIONS_MODS_REGISTRATIONS [PUT_MODS] = trans_initiator2target_initializer(mods),
+
+#else // SPLIT_MODS_ENABLE
+
+# define TRANSACTIONS_MODS_MASTER()
+# define TRANSACTIONS_MODS_SLAVE()
+# define TRANSACTIONS_MODS_REGISTRATIONS
+
+#endif // SPLIT_MODS_ENABLE
+
+////////////////////////////////////////////////////
+// Backlight
+
+#ifdef BACKLIGHT_ENABLE
+
+static bool backlight_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ uint8_t level = is_backlight_enabled() ? get_backlight_level() : 0;
+ return send_if_condition(PUT_BACKLIGHT, &last_update, (level != split_shmem->backlight_level), &level, sizeof(level));
+}
+
+static void backlight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { backlight_set(split_shmem->backlight_level); }
+
+# define TRANSACTIONS_BACKLIGHT_MASTER() TRANSACTION_HANDLER_MASTER(backlight_handlers)
+# define TRANSACTIONS_BACKLIGHT_SLAVE() TRANSACTION_HANDLER_SLAVE(backlight_handlers)
+# define TRANSACTIONS_BACKLIGHT_REGISTRATIONS [PUT_BACKLIGHT] = trans_initiator2target_initializer(backlight_level),
+
+#else // BACKLIGHT_ENABLE
+
+# define TRANSACTIONS_BACKLIGHT_MASTER()
+# define TRANSACTIONS_BACKLIGHT_SLAVE()
+# define TRANSACTIONS_BACKLIGHT_REGISTRATIONS
+
+#endif // BACKLIGHT_ENABLE
+
+////////////////////////////////////////////////////
+// RGBLIGHT
+
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+
+static bool rgblight_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ rgblight_syncinfo_t rgblight_sync;
+ rgblight_get_syncinfo(&rgblight_sync);
+ if (send_if_condition(PUT_RGBLIGHT, &last_update, (rgblight_sync.status.change_flags != 0), &rgblight_sync, sizeof(rgblight_sync))) {
+ rgblight_clear_change_flags();
+ } else {
+ return false;
+ }
+ return true;
+}
+
+static void rgblight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ // Update the RGB with the new data
+ if (split_shmem->rgblight_sync.status.change_flags != 0) {
+ rgblight_update_sync(&split_shmem->rgblight_sync, false);
+ split_shmem->rgblight_sync.status.change_flags = 0;
+ }
+}
+
+# define TRANSACTIONS_RGBLIGHT_MASTER() TRANSACTION_HANDLER_MASTER(rgblight_handlers)
+# define TRANSACTIONS_RGBLIGHT_SLAVE() TRANSACTION_HANDLER_SLAVE(rgblight_handlers)
+# define TRANSACTIONS_RGBLIGHT_REGISTRATIONS [PUT_RGBLIGHT] = trans_initiator2target_initializer(rgblight_sync),
+
+#else // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+
+# define TRANSACTIONS_RGBLIGHT_MASTER()
+# define TRANSACTIONS_RGBLIGHT_SLAVE()
+# define TRANSACTIONS_RGBLIGHT_REGISTRATIONS
+
+#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+
+////////////////////////////////////////////////////
+// LED Matrix
+
+#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+
+static bool led_matrix_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ led_matrix_sync_t led_matrix_sync;
+ memcpy(&led_matrix_sync.led_matrix, &led_matrix_eeconfig, sizeof(led_eeconfig_t));
+ led_matrix_sync.led_suspend_state = led_matrix_get_suspend_state();
+ return send_if_data_mismatch(PUT_LED_MATRIX, &last_update, &led_matrix_sync, &split_shmem->led_matrix_sync, sizeof(led_matrix_sync));
+}
+
+static void led_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ memcpy(&led_matrix_eeconfig, &split_shmem->led_matrix_sync.led_matrix, sizeof(led_eeconfig_t));
+ led_matrix_set_suspend_state(split_shmem->led_matrix_sync.led_suspend_state);
+}
+
+# define TRANSACTIONS_LED_MATRIX_MASTER() TRANSACTION_HANDLER_MASTER(led_matrix_handlers)
+# define TRANSACTIONS_LED_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(led_matrix_handlers)
+# define TRANSACTIONS_LED_MATRIX_REGISTRATIONS [PUT_LED_MATRIX] = trans_initiator2target_initializer(led_matrix_sync),
+
+#else // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+
+# define TRANSACTIONS_LED_MATRIX_MASTER()
+# define TRANSACTIONS_LED_MATRIX_SLAVE()
+# define TRANSACTIONS_LED_MATRIX_REGISTRATIONS
+
+#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+
+////////////////////////////////////////////////////
+// RGB Matrix
+
+#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
+
+static bool rgb_matrix_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ rgb_matrix_sync_t rgb_matrix_sync;
+ memcpy(&rgb_matrix_sync.rgb_matrix, &rgb_matrix_config, sizeof(rgb_config_t));
+ rgb_matrix_sync.rgb_suspend_state = rgb_matrix_get_suspend_state();
+ return send_if_data_mismatch(PUT_RGB_MATRIX, &last_update, &rgb_matrix_sync, &split_shmem->rgb_matrix_sync, sizeof(rgb_matrix_sync));
+}
+
+static void rgb_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ memcpy(&rgb_matrix_config, &split_shmem->rgb_matrix_sync.rgb_matrix, sizeof(rgb_config_t));
+ rgb_matrix_set_suspend_state(split_shmem->rgb_matrix_sync.rgb_suspend_state);
+}
+
+# define TRANSACTIONS_RGB_MATRIX_MASTER() TRANSACTION_HANDLER_MASTER(rgb_matrix_handlers)
+# define TRANSACTIONS_RGB_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(rgb_matrix_handlers)
+# define TRANSACTIONS_RGB_MATRIX_REGISTRATIONS [PUT_RGB_MATRIX] = trans_initiator2target_initializer(rgb_matrix_sync),
+
+#else // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
+
+# define TRANSACTIONS_RGB_MATRIX_MASTER()
+# define TRANSACTIONS_RGB_MATRIX_SLAVE()
+# define TRANSACTIONS_RGB_MATRIX_REGISTRATIONS
+
+#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
+
+////////////////////////////////////////////////////
+// WPM
+
+#if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
+
+static bool wpm_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ static uint32_t last_update = 0;
+ uint8_t current_wpm = get_current_wpm();
+ return send_if_condition(PUT_WPM, &last_update, (current_wpm != split_shmem->current_wpm), ¤t_wpm, sizeof(current_wpm));
+}
+
+static void wpm_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { set_current_wpm(split_shmem->current_wpm); }
+
+# define TRANSACTIONS_WPM_MASTER() TRANSACTION_HANDLER_MASTER(wpm_handlers)
+# define TRANSACTIONS_WPM_SLAVE() TRANSACTION_HANDLER_SLAVE(wpm_handlers)
+# define TRANSACTIONS_WPM_REGISTRATIONS [PUT_WPM] = trans_initiator2target_initializer(current_wpm),
+
+#else // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
+
+# define TRANSACTIONS_WPM_MASTER()
+# define TRANSACTIONS_WPM_SLAVE()
+# define TRANSACTIONS_WPM_REGISTRATIONS
+
+#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
+
+////////////////////////////////////////////////////
+
+uint8_t dummy;
+split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = {
+ // Set defaults
+ [0 ...(NUM_TOTAL_TRANSACTIONS - 1)] = {NULL, 0, 0, 0, 0, 0},
+
+#ifdef USE_I2C
+ [I2C_EXECUTE_CALLBACK] = trans_initiator2target_initializer(transaction_id),
+#endif // USE_I2C
+
+ // clang-format off
+ TRANSACTIONS_SLAVE_MATRIX_REGISTRATIONS
+ TRANSACTIONS_MASTER_MATRIX_REGISTRATIONS
+ TRANSACTIONS_ENCODERS_REGISTRATIONS
+ TRANSACTIONS_SYNC_TIMER_REGISTRATIONS
+ TRANSACTIONS_LAYER_STATE_REGISTRATIONS
+ TRANSACTIONS_LED_STATE_REGISTRATIONS
+ TRANSACTIONS_MODS_REGISTRATIONS
+ TRANSACTIONS_BACKLIGHT_REGISTRATIONS
+ TRANSACTIONS_RGBLIGHT_REGISTRATIONS
+ TRANSACTIONS_LED_MATRIX_REGISTRATIONS
+ TRANSACTIONS_RGB_MATRIX_REGISTRATIONS
+ TRANSACTIONS_WPM_REGISTRATIONS
+// clang-format on
+
+#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+ [PUT_RPC_INFO] = trans_initiator2target_initializer_cb(rpc_info, slave_rpc_info_callback),
+ [PUT_RPC_REQ_DATA] = trans_initiator2target_initializer(rpc_m2s_buffer),
+ [EXECUTE_RPC] = trans_initiator2target_initializer_cb(rpc_info.transaction_id, slave_rpc_exec_callback),
+ [GET_RPC_RESP_DATA] = trans_target2initiator_initializer(rpc_s2m_buffer),
+#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+};
+
+bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ bool okay = true;
+ TRANSACTIONS_SLAVE_MATRIX_MASTER();
+ TRANSACTIONS_MASTER_MATRIX_MASTER();
+ TRANSACTIONS_ENCODERS_MASTER();
+ TRANSACTIONS_SYNC_TIMER_MASTER();
+ TRANSACTIONS_LAYER_STATE_MASTER();
+ TRANSACTIONS_LED_STATE_MASTER();
+ TRANSACTIONS_MODS_MASTER();
+ TRANSACTIONS_BACKLIGHT_MASTER();
+ TRANSACTIONS_RGBLIGHT_MASTER();
+ TRANSACTIONS_LED_MATRIX_MASTER();
+ TRANSACTIONS_RGB_MATRIX_MASTER();
+ TRANSACTIONS_WPM_MASTER();
+ return okay;
+}
+
+void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ TRANSACTIONS_SLAVE_MATRIX_SLAVE();
+ TRANSACTIONS_MASTER_MATRIX_SLAVE();
+ TRANSACTIONS_ENCODERS_SLAVE();
+ TRANSACTIONS_SYNC_TIMER_SLAVE();
+ TRANSACTIONS_LAYER_STATE_SLAVE();
+ TRANSACTIONS_LED_STATE_SLAVE();
+ TRANSACTIONS_MODS_SLAVE();
+ TRANSACTIONS_BACKLIGHT_SLAVE();
+ TRANSACTIONS_RGBLIGHT_SLAVE();
+ TRANSACTIONS_LED_MATRIX_SLAVE();
+ TRANSACTIONS_RGB_MATRIX_SLAVE();
+ TRANSACTIONS_WPM_SLAVE();
+}
+
+#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+
+void transaction_register_rpc(int8_t transaction_id, slave_callback_t callback) {
+ // Prevent invoking RPC on QMK core sync data
+ if (transaction_id <= GET_RPC_RESP_DATA) return;
+
+ // Set the callback
+ split_transaction_table[transaction_id].slave_callback = callback;
+ split_transaction_table[transaction_id].initiator2target_offset = offsetof(split_shared_memory_t, rpc_m2s_buffer);
+ split_transaction_table[transaction_id].target2initiator_offset = offsetof(split_shared_memory_t, rpc_s2m_buffer);
+}
+
+bool transaction_rpc_exec(int8_t transaction_id, uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) {
+ // Prevent invoking RPC on QMK core sync data
+ if (transaction_id <= GET_RPC_RESP_DATA) return false;
+ // Prevent sizing issues
+ if (initiator2target_buffer_size > RPC_M2S_BUFFER_SIZE) return false;
+ if (target2initiator_buffer_size > RPC_S2M_BUFFER_SIZE) return false;
+
+ // Prepare the metadata block
+ rpc_sync_info_t info = {.transaction_id = transaction_id, .m2s_length = initiator2target_buffer_size, .s2m_length = target2initiator_buffer_size};
+
+ // Make sure the local side knows that we're not sending the full block of data
+ split_transaction_table[PUT_RPC_REQ_DATA].initiator2target_buffer_size = initiator2target_buffer_size;
+ split_transaction_table[GET_RPC_RESP_DATA].target2initiator_buffer_size = target2initiator_buffer_size;
+
+ // Run through the sequence:
+ // * set the transaction ID and lengths
+ // * send the request data
+ // * execute RPC callback
+ // * retrieve the response data
+ if (!transport_write(PUT_RPC_INFO, &info, sizeof(info))) {
+ return false;
+ }
+ if (!transport_write(PUT_RPC_REQ_DATA, initiator2target_buffer, initiator2target_buffer_size)) {
+ return false;
+ }
+ if (!transport_write(EXECUTE_RPC, &transaction_id, sizeof(transaction_id))) {
+ return false;
+ }
+ if (!transport_read(GET_RPC_RESP_DATA, target2initiator_buffer, target2initiator_buffer_size)) {
+ return false;
+ }
+ return true;
+}
+
+void slave_rpc_info_callback(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) {
+ // The RPC info block contains the intended transaction ID, as well as the sizes for both inbound and outbound data.
+ // Ignore the args -- the `split_shmem` already has the info, we just need to act upon it.
+ // We must keep the `split_transaction_table` non-const, so that it is able to be modified at runtime.
+
+ split_transaction_table[PUT_RPC_REQ_DATA].initiator2target_buffer_size = split_shmem->rpc_info.m2s_length;
+ split_transaction_table[GET_RPC_RESP_DATA].target2initiator_buffer_size = split_shmem->rpc_info.s2m_length;
+}
+
+void slave_rpc_exec_callback(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) {
+ // We can assume that the buffer lengths are correctly set, now, given that sequentially the rpc_info callback was already executed.
+ // Go through the rpc_info and execute _that_ transaction's callback, with the scratch buffers as inputs.
+ int8_t transaction_id = split_shmem->rpc_info.transaction_id;
+ if (transaction_id < NUM_TOTAL_TRANSACTIONS) {
+ split_transaction_desc_t *trans = &split_transaction_table[transaction_id];
+ if (trans->slave_callback) {
+ trans->slave_callback(split_shmem->rpc_info.m2s_length, split_shmem->rpc_m2s_buffer, split_shmem->rpc_info.s2m_length, split_shmem->rpc_s2m_buffer);
+ }
+ }
+}
+
+#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
diff --git a/quantum/split_common/transactions.h b/quantum/split_common/transactions.h
new file mode 100644
index 0000000000..4306ba1d87
--- /dev/null
+++ b/quantum/split_common/transactions.h
@@ -0,0 +1,54 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include "stdint.h"
+#include "stdbool.h"
+
+#include "matrix.h"
+#include "transaction_id_define.h"
+#include "transport.h"
+
+typedef void (*slave_callback_t)(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer);
+
+// Split transaction Descriptor
+typedef struct _split_transaction_desc_t {
+ uint8_t * status;
+ uint8_t initiator2target_buffer_size;
+ uint16_t initiator2target_offset;
+ uint8_t target2initiator_buffer_size;
+ uint16_t target2initiator_offset;
+ slave_callback_t slave_callback;
+} split_transaction_desc_t;
+
+// Forward declaration for the split transactions
+extern split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS];
+
+#define split_shmem_offset_ptr(offset) ((void *)(((uint8_t *)split_shmem) + (offset)))
+#define split_trans_initiator2target_buffer(trans) (split_shmem_offset_ptr((trans)->initiator2target_offset))
+#define split_trans_target2initiator_buffer(trans) (split_shmem_offset_ptr((trans)->target2initiator_offset))
+
+// returns false if valid data not received from slave
+bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]);
+void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]);
+
+void transaction_register_rpc(int8_t transaction_id, slave_callback_t callback);
+
+bool transaction_rpc_exec(int8_t transaction_id, uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer);
+
+#define transaction_rpc_send(transaction_id, initiator2target_buffer_size, initiator2target_buffer) transaction_rpc_exec(transaction_id, initiator2target_buffer_size, initiator2target_buffer, 0, NULL)
+#define transaction_rpc_recv(transaction_id, target2initiator_buffer_size, target2initiator_buffer) transaction_rpc_exec(transaction_id, 0, NULL, target2initiator_buffer_size, target2initiator_buffer)
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c
index 9ed0f7591b..a711ef85f0 100644
--- a/quantum/split_common/transport.c
+++ b/quantum/split_common/transport.c
@@ -1,452 +1,118 @@
-#include
-#include
-
-#include "config.h"
-#include "matrix.h"
-#include "quantum.h"
-
-#define ROWS_PER_HAND (MATRIX_ROWS / 2)
-#define SYNC_TIMER_OFFSET 2
-
-#ifdef RGBLIGHT_ENABLE
-# include "rgblight.h"
-#endif
-
-#ifdef BACKLIGHT_ENABLE
-# include "backlight.h"
-#endif
-
-#ifdef ENCODER_ENABLE
-# include "encoder.h"
-static pin_t encoders_pad[] = ENCODERS_PAD_A;
-# define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t))
-#endif
-
-#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
-# include "led_matrix.h"
-#endif
-#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
-# include "rgb_matrix.h"
-#endif
-
-#if defined(USE_I2C)
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
-# include "i2c_master.h"
-# include "i2c_slave.h"
-
-typedef struct _I2C_slave_buffer_t {
-# ifndef DISABLE_SYNC_TIMER
- uint32_t sync_timer;
-# endif
-# ifdef SPLIT_TRANSPORT_MIRROR
- matrix_row_t mmatrix[ROWS_PER_HAND];
-# endif
- matrix_row_t smatrix[ROWS_PER_HAND];
-# ifdef SPLIT_MODS_ENABLE
- uint8_t real_mods;
- uint8_t weak_mods;
-# ifndef NO_ACTION_ONESHOT
- uint8_t oneshot_mods;
-# endif
-# endif
-# ifdef BACKLIGHT_ENABLE
- uint8_t backlight_level;
-# endif
-# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
- rgblight_syncinfo_t rgblight_sync;
-# endif
-# ifdef ENCODER_ENABLE
- uint8_t encoder_state[NUMBER_OF_ENCODERS];
-# endif
-# ifdef WPM_ENABLE
- uint8_t current_wpm;
-# endif
-# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
- led_eeconfig_t led_matrix;
- bool led_suspend_state;
-# endif
-# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- rgb_config_t rgb_matrix;
- bool rgb_suspend_state;
-# endif
-} I2C_slave_buffer_t;
+#include
+#include
-static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg;
+#include "transactions.h"
+#include "transport.h"
+#include "transaction_id_define.h"
+#include "atomic_util.h"
-# define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer)
-# define I2C_KEYMAP_MASTER_START offsetof(I2C_slave_buffer_t, mmatrix)
-# define I2C_KEYMAP_SLAVE_START offsetof(I2C_slave_buffer_t, smatrix)
-# define I2C_REAL_MODS_START offsetof(I2C_slave_buffer_t, real_mods)
-# define I2C_WEAK_MODS_START offsetof(I2C_slave_buffer_t, weak_mods)
-# define I2C_ONESHOT_MODS_START offsetof(I2C_slave_buffer_t, oneshot_mods)
-# define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level)
-# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
-# define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state)
-# define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm)
-# define I2C_LED_MATRIX_START offsetof(I2C_slave_buffer_t, led_matrix)
-# define I2C_LED_SUSPEND_START offsetof(I2C_slave_buffer_t, led_suspend_state)
-# define I2C_RGB_MATRIX_START offsetof(I2C_slave_buffer_t, rgb_matrix)
-# define I2C_RGB_SUSPEND_START offsetof(I2C_slave_buffer_t, rgb_suspend_state)
+#ifdef USE_I2C
-# define TIMEOUT 100
+# ifndef SLAVE_I2C_TIMEOUT
+# define SLAVE_I2C_TIMEOUT 100
+# endif // SLAVE_I2C_TIMEOUT
# ifndef SLAVE_I2C_ADDRESS
# define SLAVE_I2C_ADDRESS 0x32
# endif
-// Get rows from other half over i2c
-bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
- i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_SLAVE_START, (void *)slave_matrix, sizeof(i2c_buffer->smatrix), TIMEOUT);
-# ifdef SPLIT_TRANSPORT_MIRROR
- i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_MASTER_START, (void *)master_matrix, sizeof(i2c_buffer->mmatrix), TIMEOUT);
-# endif
+# include "i2c_master.h"
+# include "i2c_slave.h"
- // write backlight info
-# ifdef BACKLIGHT_ENABLE
- uint8_t level = is_backlight_enabled() ? get_backlight_level() : 0;
- if (level != i2c_buffer->backlight_level) {
- if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIGHT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) {
- i2c_buffer->backlight_level = level;
- }
- }
-# endif
+// Ensure the I2C buffer has enough space
+_Static_assert(sizeof(split_shared_memory_t) <= I2C_SLAVE_REG_COUNT, "split_shared_memory_t too large for I2C_SLAVE_REG_COUNT");
-# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
- if (rgblight_get_change_flags()) {
- rgblight_syncinfo_t rgblight_sync;
- rgblight_get_syncinfo(&rgblight_sync);
- if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START, (void *)&rgblight_sync, sizeof(rgblight_sync), TIMEOUT) >= 0) {
- rgblight_clear_change_flags();
- }
- }
-# endif
+split_shared_memory_t *const split_shmem = (split_shared_memory_t *)i2c_slave_reg;
-# ifdef ENCODER_ENABLE
- i2c_readReg(SLAVE_I2C_ADDRESS, I2C_ENCODER_START, (void *)i2c_buffer->encoder_state, sizeof(i2c_buffer->encoder_state), TIMEOUT);
- encoder_update_raw(i2c_buffer->encoder_state);
-# endif
+void transport_master_init(void) { i2c_init(); }
+void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); }
-# ifdef WPM_ENABLE
- uint8_t current_wpm = get_current_wpm();
- if (current_wpm != i2c_buffer->current_wpm) {
- if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_WPM_START, (void *)¤t_wpm, sizeof(current_wpm), TIMEOUT) >= 0) {
- i2c_buffer->current_wpm = current_wpm;
- }
+i2c_status_t transport_trigger_callback(int8_t id) {
+ // If there's no callback, indicate that we were successful
+ if (!split_transaction_table[id].slave_callback) {
+ return I2C_STATUS_SUCCESS;
}
-# endif
-# ifdef SPLIT_MODS_ENABLE
- uint8_t real_mods = get_mods();
- if (real_mods != i2c_buffer->real_mods) {
- if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_REAL_MODS_START, (void *)&real_mods, sizeof(real_mods), TIMEOUT) >= 0) {
- i2c_buffer->real_mods = real_mods;
+ // Kick off the "callback executor", now that data has been written to the slave
+ split_shmem->transaction_id = id;
+ split_transaction_desc_t *trans = &split_transaction_table[I2C_EXECUTE_CALLBACK];
+ return i2c_writeReg(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, SLAVE_I2C_TIMEOUT);
+}
+
+bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length) {
+ i2c_status_t status;
+ split_transaction_desc_t *trans = &split_transaction_table[id];
+ if (initiator2target_length > 0) {
+ size_t len = trans->initiator2target_buffer_size < initiator2target_length ? trans->initiator2target_buffer_size : initiator2target_length;
+ memcpy(split_trans_initiator2target_buffer(trans), initiator2target_buf, len);
+ if ((status = i2c_writeReg(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
+ return false;
}
}
- uint8_t weak_mods = get_weak_mods();
- if (weak_mods != i2c_buffer->weak_mods) {
- if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_WEAK_MODS_START, (void *)&weak_mods, sizeof(weak_mods), TIMEOUT) >= 0) {
- i2c_buffer->weak_mods = weak_mods;
- }
+ // If we need to execute a callback on the slave, do so
+ if ((status = transport_trigger_callback(id)) < 0) {
+ return false;
}
-# ifndef NO_ACTION_ONESHOT
- uint8_t oneshot_mods = get_oneshot_mods();
- if (oneshot_mods != i2c_buffer->oneshot_mods) {
- if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_ONESHOT_MODS_START, (void *)&oneshot_mods, sizeof(oneshot_mods), TIMEOUT) >= 0) {
- i2c_buffer->oneshot_mods = oneshot_mods;
+ if (target2initiator_length > 0) {
+ size_t len = trans->target2initiator_buffer_size < target2initiator_length ? trans->target2initiator_buffer_size : target2initiator_length;
+ if ((status = i2c_readReg(SLAVE_I2C_ADDRESS, trans->target2initiator_offset, split_trans_target2initiator_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
+ return false;
}
+ memcpy(target2initiator_buf, split_trans_target2initiator_buffer(trans), len);
}
-# endif
-# endif
-# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
- i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_LED_MATRIX_START, (void *)led_matrix_eeconfig, sizeof(i2c_buffer->led_matrix), TIMEOUT);
- bool suspend_state = led_matrix_get_suspend_state();
- i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_LED_SUSPEND_START, (void *)suspend_state, sizeof(i2c_buffer->led_suspend_state), TIMEOUT);
-# endif
-# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_MATRIX_START, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix), TIMEOUT);
- bool suspend_state = rgb_matrix_get_suspend_state();
- i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_SUSPEND_START, (void *)suspend_state, sizeof(i2c_buffer->rgb_suspend_state), TIMEOUT);
-# endif
-
-# ifndef DISABLE_SYNC_TIMER
- i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
- i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT);
-# endif
return true;
}
-void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
-# ifndef DISABLE_SYNC_TIMER
- sync_timer_update(i2c_buffer->sync_timer);
-# endif
- // Copy matrix to I2C buffer
- memcpy((void *)i2c_buffer->smatrix, (void *)slave_matrix, sizeof(i2c_buffer->smatrix));
-# ifdef SPLIT_TRANSPORT_MIRROR
- memcpy((void *)master_matrix, (void *)i2c_buffer->mmatrix, sizeof(i2c_buffer->mmatrix));
-# endif
-
-// Read Backlight Info
-# ifdef BACKLIGHT_ENABLE
- backlight_set(i2c_buffer->backlight_level);
-# endif
-
-# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
- // Update the RGB with the new data
- if (i2c_buffer->rgblight_sync.status.change_flags != 0) {
- rgblight_update_sync(&i2c_buffer->rgblight_sync, false);
- i2c_buffer->rgblight_sync.status.change_flags = 0;
- }
-# endif
-
-# ifdef ENCODER_ENABLE
- encoder_state_raw(i2c_buffer->encoder_state);
-# endif
-
-# ifdef WPM_ENABLE
- set_current_wpm(i2c_buffer->current_wpm);
-# endif
-
-# ifdef SPLIT_MODS_ENABLE
- set_mods(i2c_buffer->real_mods);
- set_weak_mods(i2c_buffer->weak_mods);
-# ifndef NO_ACTION_ONESHOT
- set_oneshot_mods(i2c_buffer->oneshot_mods);
-# endif
-# endif
-
-# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
- memcpy((void *)i2c_buffer->led_matrix, (void *)led_matrix_eeconfig, sizeof(i2c_buffer->led_matrix));
- led_matrix_set_suspend_state(i2c_buffer->led_suspend_state);
-# endif
-# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- memcpy((void *)i2c_buffer->rgb_matrix, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix));
- rgb_matrix_set_suspend_state(i2c_buffer->rgb_suspend_state);
-# endif
-}
-
-void transport_master_init(void) { i2c_init(); }
-
-void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); }
-
-#else // USE_SERIAL
+#else // USE_I2C
# include "serial.h"
-typedef struct _Serial_s2m_buffer_t {
- // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
- matrix_row_t smatrix[ROWS_PER_HAND];
-
-# ifdef ENCODER_ENABLE
- uint8_t encoder_state[NUMBER_OF_ENCODERS];
-# endif
-
-} Serial_s2m_buffer_t;
-
-typedef struct _Serial_m2s_buffer_t {
-# ifdef SPLIT_MODS_ENABLE
- uint8_t real_mods;
- uint8_t weak_mods;
-# ifndef NO_ACTION_ONESHOT
- uint8_t oneshot_mods;
-# endif
-# endif
-# ifndef DISABLE_SYNC_TIMER
- uint32_t sync_timer;
-# endif
-# ifdef SPLIT_TRANSPORT_MIRROR
- matrix_row_t mmatrix[ROWS_PER_HAND];
-# endif
-# ifdef BACKLIGHT_ENABLE
- uint8_t backlight_level;
-# endif
-# ifdef WPM_ENABLE
- uint8_t current_wpm;
-# endif
-# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
- led_eeconfig_t led_matrix;
- bool led_suspend_state;
-# endif
-# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- rgb_config_t rgb_matrix;
- bool rgb_suspend_state;
-# endif
-} Serial_m2s_buffer_t;
-
-# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
-// When MCUs on both sides drive their respective RGB LED chains,
-// it is necessary to synchronize, so it is necessary to communicate RGB
-// information. In that case, define RGBLIGHT_SPLIT with info on the number
-// of LEDs on each half.
-//
-// Otherwise, if the master side MCU drives both sides RGB LED chains,
-// there is no need to communicate.
-
-typedef struct _Serial_rgblight_t {
- rgblight_syncinfo_t rgblight_sync;
-} Serial_rgblight_t;
+static split_shared_memory_t shared_memory;
+split_shared_memory_t *const split_shmem = &shared_memory;
-volatile Serial_rgblight_t serial_rgblight = {};
-uint8_t volatile status_rgblight = 0;
-# endif
-
-volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
-volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
-uint8_t volatile status0 = 0;
-
-enum serial_transaction_id {
- GET_SLAVE_MATRIX = 0,
-# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
- PUT_RGBLIGHT,
-# endif
-};
-
-SSTD_t transactions[] = {
- [GET_SLAVE_MATRIX] =
- {
- (uint8_t *)&status0,
- sizeof(serial_m2s_buffer),
- (uint8_t *)&serial_m2s_buffer,
- sizeof(serial_s2m_buffer),
- (uint8_t *)&serial_s2m_buffer,
- },
-# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
- [PUT_RGBLIGHT] =
- {
- (uint8_t *)&status_rgblight, sizeof(serial_rgblight), (uint8_t *)&serial_rgblight, 0, NULL // no slave to master transfer
- },
-# endif
-};
-
-void transport_master_init(void) { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }
-
-void transport_slave_init(void) { soft_serial_target_init(transactions, TID_LIMIT(transactions)); }
+void transport_master_init(void) { soft_serial_initiator_init(); }
+void transport_slave_init(void) { soft_serial_target_init(); }
-# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
-
-// rgblight synchronization information communication.
-
-void transport_rgblight_master(void) {
- if (rgblight_get_change_flags()) {
- rgblight_get_syncinfo((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync);
- if (soft_serial_transaction(PUT_RGBLIGHT) == TRANSACTION_END) {
- rgblight_clear_change_flags();
- }
- }
-}
-
-void transport_rgblight_slave(void) {
- if (status_rgblight == TRANSACTION_ACCEPTED) {
- rgblight_update_sync((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync, false);
- status_rgblight = TRANSACTION_END;
+bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length) {
+ split_transaction_desc_t *trans = &split_transaction_table[id];
+ if (initiator2target_length > 0) {
+ size_t len = trans->initiator2target_buffer_size < initiator2target_length ? trans->initiator2target_buffer_size : initiator2target_length;
+ memcpy(split_trans_initiator2target_buffer(trans), initiator2target_buf, len);
}
-}
-# else
-# define transport_rgblight_master()
-# define transport_rgblight_slave()
-# endif
-
-bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
-# ifndef SERIAL_USE_MULTI_TRANSACTION
- if (soft_serial_transaction() != TRANSACTION_END) {
- return false;
- }
-# else
- transport_rgblight_master();
- if (soft_serial_transaction(GET_SLAVE_MATRIX) != TRANSACTION_END) {
+ if (soft_serial_transaction(id) != TRANSACTION_END) {
return false;
}
-# endif
- // TODO: if MATRIX_COLS > 8 change to unpack()
- for (int i = 0; i < ROWS_PER_HAND; ++i) {
- slave_matrix[i] = serial_s2m_buffer.smatrix[i];
-# ifdef SPLIT_TRANSPORT_MIRROR
- serial_m2s_buffer.mmatrix[i] = master_matrix[i];
-# endif
+ if (target2initiator_length > 0) {
+ size_t len = trans->target2initiator_buffer_size < target2initiator_length ? trans->target2initiator_buffer_size : target2initiator_length;
+ memcpy(target2initiator_buf, split_trans_target2initiator_buffer(trans), len);
}
-# ifdef BACKLIGHT_ENABLE
- // Write backlight level for slave to read
- serial_m2s_buffer.backlight_level = is_backlight_enabled() ? get_backlight_level() : 0;
-# endif
-
-# ifdef ENCODER_ENABLE
- encoder_update_raw((uint8_t *)serial_s2m_buffer.encoder_state);
-# endif
-
-# ifdef WPM_ENABLE
- // Write wpm to slave
- serial_m2s_buffer.current_wpm = get_current_wpm();
-# endif
-
-# ifdef SPLIT_MODS_ENABLE
- serial_m2s_buffer.real_mods = get_mods();
- serial_m2s_buffer.weak_mods = get_weak_mods();
-# ifndef NO_ACTION_ONESHOT
- serial_m2s_buffer.oneshot_mods = get_oneshot_mods();
-# endif
-# endif
-
-# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
- serial_m2s_buffer.led_matrix = led_matrix_eeconfig;
- serial_m2s_buffer.led_suspend_state = led_matrix_get_suspend_state();
-# endif
-# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- serial_m2s_buffer.rgb_matrix = rgb_matrix_config;
- serial_m2s_buffer.rgb_suspend_state = rgb_matrix_get_suspend_state();
-# endif
-
-# ifndef DISABLE_SYNC_TIMER
- serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
-# endif
return true;
}
-void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
- transport_rgblight_slave();
-# ifndef DISABLE_SYNC_TIMER
- sync_timer_update(serial_m2s_buffer.sync_timer);
-# endif
-
- // TODO: if MATRIX_COLS > 8 change to pack()
- for (int i = 0; i < ROWS_PER_HAND; ++i) {
- serial_s2m_buffer.smatrix[i] = slave_matrix[i];
-# ifdef SPLIT_TRANSPORT_MIRROR
- master_matrix[i] = serial_m2s_buffer.mmatrix[i];
-# endif
- }
-# ifdef BACKLIGHT_ENABLE
- backlight_set(serial_m2s_buffer.backlight_level);
-# endif
-
-# ifdef ENCODER_ENABLE
- encoder_state_raw((uint8_t *)serial_s2m_buffer.encoder_state);
-# endif
+#endif // USE_I2C
-# ifdef WPM_ENABLE
- set_current_wpm(serial_m2s_buffer.current_wpm);
-# endif
-
-# ifdef SPLIT_MODS_ENABLE
- set_mods(serial_m2s_buffer.real_mods);
- set_weak_mods(serial_m2s_buffer.weak_mods);
-# ifndef NO_ACTION_ONESHOT
- set_oneshot_mods(serial_m2s_buffer.oneshot_mods);
-# endif
-# endif
-
-# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
- led_matrix_eeconfig = serial_m2s_buffer.led_matrix;
- led_matrix_set_suspend_state(serial_m2s_buffer.led_suspend_state);
-# endif
-# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- rgb_matrix_config = serial_m2s_buffer.rgb_matrix;
- rgb_matrix_set_suspend_state(serial_m2s_buffer.rgb_suspend_state);
-# endif
-}
+bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { return transactions_master(master_matrix, slave_matrix); }
-#endif
+void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { transactions_slave(master_matrix, slave_matrix); }
\ No newline at end of file
diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h
index a9f66301bf..2e07f6b25c 100644
--- a/quantum/split_common/transport.h
+++ b/quantum/split_common/transport.h
@@ -1,10 +1,175 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
#pragma once
+#include "stdint.h"
+#include "stdbool.h"
+
+#include "progmem.h"
+#include "action_layer.h"
#include "matrix.h"
+#ifndef RPC_M2S_BUFFER_SIZE
+# define RPC_M2S_BUFFER_SIZE 32
+#endif // RPC_M2S_BUFFER_SIZE
+
+#ifndef RPC_S2M_BUFFER_SIZE
+# define RPC_S2M_BUFFER_SIZE 32
+#endif // RPC_S2M_BUFFER_SIZE
+
void transport_master_init(void);
void transport_slave_init(void);
// returns false if valid data not received from slave
bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]);
void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]);
+
+bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length);
+
+#ifdef ENCODER_ENABLE
+# include "encoder.h"
+# define NUMBER_OF_ENCODERS (sizeof((pin_t[])ENCODERS_PAD_A) / sizeof(pin_t))
+#endif // ENCODER_ENABLE
+
+#ifdef BACKLIGHT_ENABLE
+# include "backlight.h"
+#endif // BACKLIGHT_ENABLE
+
+#ifdef RGBLIGHT_ENABLE
+# include "rgblight.h"
+#endif // RGBLIGHT_ENABLE
+
+typedef struct _split_slave_matrix_sync_t {
+ uint8_t checksum;
+ matrix_row_t matrix[(MATRIX_ROWS) / 2];
+} split_slave_matrix_sync_t;
+
+#ifdef SPLIT_TRANSPORT_MIRROR
+typedef struct _split_master_matrix_sync_t {
+ matrix_row_t matrix[(MATRIX_ROWS) / 2];
+} split_master_matrix_sync_t;
+#endif // SPLIT_TRANSPORT_MIRROR
+
+#ifdef ENCODER_ENABLE
+typedef struct _split_slave_encoder_sync_t {
+ uint8_t checksum;
+ uint8_t state[NUMBER_OF_ENCODERS];
+} split_slave_encoder_sync_t;
+#endif // ENCODER_ENABLE
+
+#if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+typedef struct _split_layers_sync_t {
+ layer_state_t layer_state;
+ layer_state_t default_layer_state;
+} split_layers_sync_t;
+#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+
+#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+# include "led_matrix.h"
+
+typedef struct _led_matrix_sync_t {
+ led_eeconfig_t led_matrix;
+ bool led_suspend_state;
+} led_matrix_sync_t;
+#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+
+#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
+# include "rgb_matrix.h"
+
+typedef struct _rgb_matrix_sync_t {
+ rgb_config_t rgb_matrix;
+ bool rgb_suspend_state;
+} rgb_matrix_sync_t;
+#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
+
+#ifdef SPLIT_MODS_ENABLE
+typedef struct _split_mods_sync_t {
+ uint8_t real_mods;
+ uint8_t weak_mods;
+# ifndef NO_ACTION_ONESHOT
+ uint8_t oneshot_mods;
+# endif // NO_ACTION_ONESHOT
+} split_mods_sync_t;
+#endif // SPLIT_MODS_ENABLE
+
+#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+typedef struct _rpc_sync_info_t {
+ int8_t transaction_id;
+ uint8_t m2s_length;
+ uint8_t s2m_length;
+} rpc_sync_info_t;
+#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+
+typedef struct _split_shared_memory_t {
+#ifdef USE_I2C
+ int8_t transaction_id;
+#endif // USE_I2C
+
+ split_slave_matrix_sync_t smatrix;
+
+#ifdef SPLIT_TRANSPORT_MIRROR
+ split_master_matrix_sync_t mmatrix;
+#endif // SPLIT_TRANSPORT_MIRROR
+
+#ifdef ENCODER_ENABLE
+ split_slave_encoder_sync_t encoders;
+#endif // ENCODER_ENABLE
+
+#ifndef DISABLE_SYNC_TIMER
+ uint32_t sync_timer;
+#endif // DISABLE_SYNC_TIMER
+
+#if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+ split_layers_sync_t layers;
+#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE)
+
+#ifdef SPLIT_LED_STATE_ENABLE
+ uint8_t led_state;
+#endif // SPLIT_LED_STATE_ENABLE
+
+#ifdef SPLIT_MODS_ENABLE
+ split_mods_sync_t mods;
+#endif // SPLIT_MODS_ENABLE
+
+#ifdef BACKLIGHT_ENABLE
+ uint8_t backlight_level;
+#endif // BACKLIGHT_ENABLE
+
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+ rgblight_syncinfo_t rgblight_sync;
+#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
+
+#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+ led_matrix_sync_t led_matrix_sync;
+#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
+
+#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
+ rgb_matrix_sync_t rgb_matrix_sync;
+#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
+
+#if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
+ uint8_t current_wpm;
+#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
+
+#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+ rpc_sync_info_t rpc_info;
+ uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE];
+ uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE];
+#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
+} split_shared_memory_t;
+
+extern split_shared_memory_t *const split_shmem;
\ No newline at end of file
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c
index e7d92cfac6..a8b391e893 100644
--- a/tmk_core/common/host.c
+++ b/tmk_core/common/host.c
@@ -17,6 +17,7 @@ along with this program. If not, see .
#include
//#include
+#include "keyboard.h"
#include "keycode.h"
#include "host.h"
#include "util.h"
@@ -35,15 +36,20 @@ void host_set_driver(host_driver_t *d) { driver = d; }
host_driver_t *host_get_driver(void) { return driver; }
+#ifdef SPLIT_KEYBOARD
+uint8_t split_led_state = 0;
+void set_split_host_keyboard_leds(uint8_t led_state) { split_led_state = led_state; }
+#endif
+
uint8_t host_keyboard_leds(void) {
+#ifdef SPLIT_KEYBOARD
+ if (!is_keyboard_master()) return split_led_state;
+#endif
if (!driver) return 0;
return (*driver->keyboard_leds)();
}
-led_t host_keyboard_led_state(void) {
- if (!driver) return (led_t){0};
- return (led_t)((*driver->keyboard_leds)());
-}
+led_t host_keyboard_led_state(void) { return (led_t)host_keyboard_leds(); }
/* send report */
void host_keyboard_send(report_keyboard_t *report) {
--
cgit v1.2.3
From 0311c8036d693baf63ed4d3b7badf4257ffd5f46 Mon Sep 17 00:00:00 2001
From: Ignaz Kevenaar
Date: Fri, 18 Jun 2021 17:08:22 +0200
Subject: Add oled_invert (#13172)
Co-authored-by: Drashna Jaelre ---
docs/feature_oled_driver.md | 4 ++++
drivers/oled/oled_driver.c | 26 ++++++++++++++++++++++++++
drivers/oled/oled_driver.h | 4 ++++
3 files changed, 34 insertions(+)
(limited to 'drivers')
diff --git a/docs/feature_oled_driver.md b/docs/feature_oled_driver.md
index f3b659b1bc..c90aabb9c6 100644
--- a/docs/feature_oled_driver.md
+++ b/docs/feature_oled_driver.md
@@ -346,6 +346,10 @@ bool oled_scroll_left(void);
// Returns true if the screen was not scrolling or stops scrolling
bool oled_scroll_off(void);
+// Inverts the display
+// Returns true if the screen was or is inverted
+bool oled_invert(bool invert);
+
// Returns the maximum number of characters that will fit on a line
uint8_t oled_max_chars(void);
diff --git a/drivers/oled/oled_driver.c b/drivers/oled/oled_driver.c
index 8e5ed5f070..7d41978905 100644
--- a/drivers/oled/oled_driver.c
+++ b/drivers/oled/oled_driver.c
@@ -34,6 +34,7 @@ along with this program. If not, see .
#define DISPLAY_ALL_ON 0xA5
#define DISPLAY_ALL_ON_RESUME 0xA4
#define NORMAL_DISPLAY 0xA6
+#define INVERT_DISPLAY 0xA7
#define DISPLAY_ON 0xAF
#define DISPLAY_OFF 0xAE
#define NOP 0xE3
@@ -114,6 +115,7 @@ OLED_BLOCK_TYPE oled_dirty = 0;
bool oled_initialized = false;
bool oled_active = false;
bool oled_scrolling = false;
+bool oled_inverted = false;
uint8_t oled_brightness = OLED_BRIGHTNESS;
oled_rotation_t oled_rotation = 0;
uint8_t oled_rotation_width = 0;
@@ -690,6 +692,30 @@ bool oled_scroll_off(void) {
return !oled_scrolling;
}
+bool oled_invert(bool invert) {
+ if (!oled_initialized) {
+ return oled_inverted;
+ }
+
+ if (invert && !oled_inverted) {
+ static const uint8_t PROGMEM display_inverted[] = {I2C_CMD, INVERT_DISPLAY};
+ if (I2C_TRANSMIT_P(display_inverted) != I2C_STATUS_SUCCESS) {
+ print("oled_invert cmd failed\n");
+ return oled_inverted;
+ }
+ oled_inverted = true;
+ } else if (!invert && oled_inverted) {
+ static const uint8_t PROGMEM display_normal[] = {I2C_CMD, NORMAL_DISPLAY};
+ if (I2C_TRANSMIT_P(display_normal) != I2C_STATUS_SUCCESS) {
+ print("oled_invert cmd failed\n");
+ return oled_inverted;
+ }
+ oled_inverted = false;
+ }
+
+ return oled_inverted;
+}
+
uint8_t oled_max_chars(void) {
if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
return OLED_DISPLAY_WIDTH / OLED_FONT_WIDTH;
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h
index a6b85f37e6..fc68f0ec95 100644
--- a/drivers/oled/oled_driver.h
+++ b/drivers/oled/oled_driver.h
@@ -313,6 +313,10 @@ bool oled_scroll_left(void);
// Returns true if the screen was not scrolling or stops scrolling
bool oled_scroll_off(void);
+// Inverts the display
+// Returns true if the screen was or is inverted
+bool oled_invert(bool invert);
+
// Returns the maximum number of characters that will fit on a line
uint8_t oled_max_chars(void);
--
cgit v1.2.3
From 37fba09021fe094ea4daf0813626b1b6a201c8c0 Mon Sep 17 00:00:00 2001
From: Ryan
Date: Sat, 19 Jun 2021 18:51:35 +1000
Subject: ST7565 invert (#13237)
---
docs/feature_st7565.md | 4 ++++
drivers/lcd/st7565.c | 16 ++++++++++++++++
drivers/lcd/st7565.h | 4 ++++
3 files changed, 24 insertions(+)
(limited to 'drivers')
diff --git a/docs/feature_st7565.md b/docs/feature_st7565.md
index 7db0f9ac4a..de3e44d8e9 100644
--- a/docs/feature_st7565.md
+++ b/docs/feature_st7565.md
@@ -262,6 +262,10 @@ void st7565_task(void);
// Called at the start of st7565_task, weak function overridable by the user
void st7565_task_user(void);
+// Inverts the display
+// Returns true if the screen was or is inverted
+bool st7565_invert(bool invert);
+
// Returns the maximum number of characters that will fit on a line
uint8_t st7565_max_chars(void);
diff --git a/drivers/lcd/st7565.c b/drivers/lcd/st7565.c
index ee2661a5eb..49b13c00f1 100644
--- a/drivers/lcd/st7565.c
+++ b/drivers/lcd/st7565.c
@@ -31,6 +31,7 @@ along with this program. If not, see .
#define DISPLAY_ALL_ON 0xA5
#define DISPLAY_ALL_ON_RESUME 0xA4
#define NORMAL_DISPLAY 0xA6
+#define INVERT_DISPLAY 0xA7
#define DISPLAY_ON 0xAF
#define DISPLAY_OFF 0xAE
#define NOP 0xE3
@@ -72,6 +73,7 @@ uint8_t * st7565_cursor;
ST7565_BLOCK_TYPE st7565_dirty = 0;
bool st7565_initialized = false;
bool st7565_active = false;
+bool st7565_inverted = false;
display_rotation_t st7565_rotation = DISPLAY_ROTATION_0;
#if ST7565_TIMEOUT > 0
uint32_t st7565_timeout;
@@ -429,6 +431,20 @@ __attribute__((weak)) void st7565_off_user(void) {}
bool st7565_is_on(void) { return st7565_active; }
+bool st7565_invert(bool invert) {
+ if (!st7565_initialized) {
+ return st7565_inverted;
+ }
+
+ if (invert != st7565_inverted) {
+ spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR);
+ st7565_send_cmd(invert ? INVERT_DISPLAY : NORMAL_DISPLAY);
+ spi_stop();
+ st7565_inverted = invert;
+ }
+ return st7565_inverted;
+}
+
uint8_t st7565_max_chars(void) { return ST7565_DISPLAY_WIDTH / ST7565_FONT_WIDTH; }
uint8_t st7565_max_lines(void) { return ST7565_DISPLAY_HEIGHT / ST7565_FONT_HEIGHT; }
diff --git a/drivers/lcd/st7565.h b/drivers/lcd/st7565.h
index 53cfc9a810..d453dbe6da 100644
--- a/drivers/lcd/st7565.h
+++ b/drivers/lcd/st7565.h
@@ -202,6 +202,10 @@ void st7565_task(void);
// Called at the start of st7565_task, weak function overridable by the user
void st7565_task_user(void);
+// Inverts the display
+// Returns true if the screen was or is inverted
+bool st7565_invert(bool invert);
+
// Returns the maximum number of characters that will fit on a line
uint8_t st7565_max_chars(void);
--
cgit v1.2.3
From e4c5b1bbbb3d76a7632c8a9d5c19c5eb8a9a4e1f Mon Sep 17 00:00:00 2001
From: Roland Huber
Date: Sun, 20 Jun 2021 04:28:54 +0200
Subject: Add Per Key exclusions for Haptic Feedback (#12386)
Co-authored-by: Drashna Jaelre ---
docs/feature_haptic_feedback.md | 26 ++++++++++++++-
drivers/haptic/haptic.c | 71 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 94 insertions(+), 3 deletions(-)
(limited to 'drivers')
diff --git a/docs/feature_haptic_feedback.md b/docs/feature_haptic_feedback.md
index a092e784c7..469c9c7981 100644
--- a/docs/feature_haptic_feedback.md
+++ b/docs/feature_haptic_feedback.md
@@ -162,4 +162,28 @@ This will set what sequence HPT_RST will set as the active mode. If not defined,
### DRV2605L Continuous Haptic Mode
-This mode sets continuous haptic feedback with the option to increase or decrease strength.
+This mode sets continuous haptic feedback with the option to increase or decrease strength.
+
+## Haptic Key Exclusion
+The Haptic Exclusion is implemented as `__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record)` in haptic.c. This allows a re-definition at the required level with the specific requirement / exclusion.
+
+### NO_HAPTIC_MOD
+With the entry of `#define NO_HAPTIC_MOD` in config.h, modifiers from Left Control to Right GUI will not trigger a feedback. This also includes modifiers in a Mod Tap configuration.
+
+### NO_HAPTIC_FN
+With the entry of `#define NO_HAPTIC_FN` in config.h, layer keys will not rigger a feedback.
+
+### NO_HAPTIC_ALPHA
+With the entry of `#define NO_HAPTIC_ALPHA` in config.h, none of the alpha keys (A ... Z) will trigger a feedback.
+
+### NO_HAPTIC_PUNCTUATION
+With the entry of `#define NO_HAPTIC_PUNCTUATION` in config.h, none of the following keys will trigger a feedback: Enter, ESC, Backspace, Space, Minus, Equal, Left Bracket, Right Bracket, Backslash, Non-US Hash, Semicolon, Quote, Grave, Comma, Slash, Dot, Non-US Backslash.
+
+### NO_HAPTIC_LOCKKEYS
+With the entry of `#define NO_HAPTIC_LOCKKEYS` in config.h, none of the following keys will trigger a feedback: Caps Lock, Scroll Lock, Num Lock.
+
+### NO_HAPTIC_NAV
+With the entry of `#define NO_HAPTIC_NAV` in config.h, none of the following keys will trigger a feedback: Print Screen, Pause, Insert, Delete, Page Down, Page Up, Left Arrow, Up Arrow, Right Arrow, Down Arrow, End, Home.
+
+### NO_HAPTIC_NUMERIC
+With the entry of `#define NO_HAPTIC_NUMERIC` in config.h, none of the following keys between 0 and 9 (KC_1 ... KC_0) will trigger a feedback.
\ No newline at end of file
diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c
index de3f400527..3fab1be1ae 100644
--- a/drivers/haptic/haptic.c
+++ b/drivers/haptic/haptic.c
@@ -291,6 +291,73 @@ void haptic_play(void) {
#endif
}
+__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
+ switch(keycode) {
+# ifdef NO_HAPTIC_MOD
+ case QK_MOD_TAP ... QK_MOD_TAP_MAX:
+ if (record->tap.count == 0) return false;
+ break;
+ case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
+ if (record->tap.count != TAPPING_TOGGLE) return false;
+ break;
+ case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
+ if (record->tap.count == 0) return false;
+ break;
+ case KC_LCTRL ... KC_RGUI:
+ case QK_MOMENTARY ... QK_MOMENTARY_MAX:
+# endif
+# ifdef NO_HAPTIC_FN
+ case KC_FN0 ... KC_FN31:
+# endif
+# ifdef NO_HAPTIC_ALPHA
+ case KC_A ... KC_Z:
+# endif
+# ifdef NO_HAPTIC_PUNCTUATION
+ case KC_ENTER:
+ case KC_ESCAPE:
+ case KC_BSPACE:
+ case KC_SPACE:
+ case KC_MINUS:
+ case KC_EQUAL:
+ case KC_LBRACKET:
+ case KC_RBRACKET:
+ case KC_BSLASH:
+ case KC_NONUS_HASH:
+ case KC_SCOLON:
+ case KC_QUOTE:
+ case KC_GRAVE:
+ case KC_COMMA:
+ case KC_SLASH:
+ case KC_DOT:
+ case KC_NONUS_BSLASH:
+# endif
+# ifdef NO_HAPTIC_LOCKKEYS
+ case KC_CAPSLOCK:
+ case KC_SCROLLLOCK:
+ case KC_NUMLOCK:
+# endif
+# ifdef NO_HAPTIC_NAV
+ case KC_PSCREEN:
+ case KC_PAUSE:
+ case KC_INSERT:
+ case KC_DELETE:
+ case KC_PGDOWN:
+ case KC_PGUP:
+ case KC_LEFT:
+ case KC_UP:
+ case KC_RIGHT:
+ case KC_DOWN:
+ case KC_END:
+ case KC_HOME:
+# endif
+# ifdef NO_HAPTIC_NUMERIC
+ case KC_1 ... KC_0:
+# endif
+ return false;
+ }
+ return true;
+}
+
bool process_haptic(uint16_t keycode, keyrecord_t *record) {
if (keycode == HPT_ON && record->event.pressed) {
haptic_enable();
@@ -335,12 +402,12 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) {
if (haptic_config.enable) {
if (record->event.pressed) {
// keypress
- if (haptic_config.feedback < 2) {
+ if (haptic_config.feedback < 2 && get_haptic_enabled_key(keycode, record)) {
haptic_play();
}
} else {
// keyrelease
- if (haptic_config.feedback > 0) {
+ if (haptic_config.feedback > 0 && get_haptic_enabled_key(keycode, record)) {
haptic_play();
}
}
--
cgit v1.2.3
From 6901411bca0760ceb8acbe1f0c95feaed9d2aaeb Mon Sep 17 00:00:00 2001
From: Drashna Jaelre
Date: Mon, 21 Jun 2021 13:00:11 -0700
Subject: Move optical sensor code to drivers folder (#13044)
---
drivers/sensors/adns5050.c | 193 ++
drivers/sensors/adns5050.h | 79 +
drivers/sensors/adns9800.c | 219 ++
drivers/sensors/adns9800.h | 35 +
drivers/sensors/adns9800_srom_A6.h | 3078 ++++++++++++++++++++
drivers/sensors/pimoroni_trackball.c | 140 +
drivers/sensors/pimoroni_trackball.h | 35 +
drivers/sensors/pmw3360.c | 237 ++
drivers/sensors/pmw3360.h | 104 +
drivers/sensors/pmw3360_firmware.h | 300 ++
keyboards/draculad/keymaps/pimoroni/keymap.c | 2 +-
.../draculad/keymaps/pimoroni/pimoroni_trackball.c | 177 --
.../draculad/keymaps/pimoroni/pimoroni_trackball.h | 35 -
keyboards/draculad/keymaps/pimoroni/rules.mk | 2 +-
.../5x6_right_trackball/5x6_right_trackball.h | 2 +-
.../dactyl_manuform/5x6_right_trackball/pmw3360.c | 221 --
.../dactyl_manuform/5x6_right_trackball/pmw3360.h | 103 -
.../5x6_right_trackball/pmw3360_firmware.h | 300 --
.../dactyl_manuform/5x6_right_trackball/rules.mk | 2 +-
keyboards/oddball/adns/adns.c | 219 --
keyboards/oddball/adns/adns.h | 35 -
keyboards/oddball/adns/adns9800_srom_A6.h | 3078 --------------------
keyboards/oddball/optical_sensor/optical_sensor.h | 2 +-
keyboards/oddball/rules.mk | 2 +-
keyboards/ploopyco/adns5050.c | 197 --
keyboards/ploopyco/adns5050.h | 79 -
keyboards/ploopyco/mouse/mouse.h | 2 +-
keyboards/ploopyco/mouse/rules.mk | 2 +-
keyboards/ploopyco/pmw3360.c | 218 --
keyboards/ploopyco/pmw3360.h | 103 -
keyboards/ploopyco/pmw3360_firmware.h | 300 --
keyboards/ploopyco/trackball/rules.mk | 2 +-
keyboards/ploopyco/trackball/trackball.h | 2 +-
keyboards/ploopyco/trackball_mini/rules.mk | 2 +-
keyboards/ploopyco/trackball_mini/trackball_mini.h | 2 +-
keyboards/ploopyco/trackball_nano/rules.mk | 2 +-
keyboards/ploopyco/trackball_nano/trackball_nano.h | 2 +-
layouts/community/ergodox/drashna/config.h | 1 +
users/drashna/drashna.h | 2 +-
users/drashna/pimoroni_trackball.c | 151 -
users/drashna/pimoroni_trackball.h | 35 -
users/drashna/rules.mk | 2 +-
42 files changed, 4437 insertions(+), 5267 deletions(-)
create mode 100644 drivers/sensors/adns5050.c
create mode 100644 drivers/sensors/adns5050.h
create mode 100644 drivers/sensors/adns9800.c
create mode 100644 drivers/sensors/adns9800.h
create mode 100644 drivers/sensors/adns9800_srom_A6.h
create mode 100644 drivers/sensors/pimoroni_trackball.c
create mode 100644 drivers/sensors/pimoroni_trackball.h
create mode 100644 drivers/sensors/pmw3360.c
create mode 100644 drivers/sensors/pmw3360.h
create mode 100644 drivers/sensors/pmw3360_firmware.h
delete mode 100644 keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.c
delete mode 100644 keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.h
delete mode 100644 keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360.c
delete mode 100644 keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360.h
delete mode 100644 keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360_firmware.h
delete mode 100644 keyboards/oddball/adns/adns.c
delete mode 100644 keyboards/oddball/adns/adns.h
delete mode 100644 keyboards/oddball/adns/adns9800_srom_A6.h
delete mode 100644 keyboards/ploopyco/adns5050.c
delete mode 100644 keyboards/ploopyco/adns5050.h
delete mode 100644 keyboards/ploopyco/pmw3360.c
delete mode 100644 keyboards/ploopyco/pmw3360.h
delete mode 100644 keyboards/ploopyco/pmw3360_firmware.h
delete mode 100644 users/drashna/pimoroni_trackball.c
delete mode 100644 users/drashna/pimoroni_trackball.h
(limited to 'drivers')
diff --git a/drivers/sensors/adns5050.c b/drivers/sensors/adns5050.c
new file mode 100644
index 0000000000..3c4f5e258a
--- /dev/null
+++ b/drivers/sensors/adns5050.c
@@ -0,0 +1,193 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+
+#include "adns5050.h"
+#include "wait.h"
+#include "debug.h"
+#include "print.h"
+#include "gpio.h"
+
+#ifndef OPTIC_ROTATED
+# define OPTIC_ROTATED false
+#endif
+
+// Definitions for the ADNS serial line.
+#ifndef ADNS_SCLK_PIN
+# define ADNS_SCLK_PIN B7
+#endif
+
+#ifndef ADNS_SDIO_PIN
+# define ADNS_SDIO_PIN C6
+#endif
+
+#ifndef ADNS_CS_PIN
+# define ADNS_CS_PIN B4
+#endif
+
+#ifdef CONSOLE_ENABLE
+void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); }
+#endif
+
+// Initialize the ADNS serial pins.
+void adns_init(void) {
+ setPinOutput(ADNS_SCLK_PIN);
+ setPinOutput(ADNS_SDIO_PIN);
+ setPinOutput(ADNS_CS_PIN);
+}
+
+// Perform a synchronization with the ADNS.
+// Just as with the serial protocol, this is used by the slave to send a
+// synchronization signal to the master.
+void adns_sync(void) {
+ writePinLow(ADNS_CS_PIN);
+ wait_us(1);
+ writePinHigh(ADNS_CS_PIN);
+}
+
+void adns_cs_select(void) {
+ writePinLow(ADNS_CS_PIN);
+}
+
+void adns_cs_deselect(void) {
+ writePinHigh(ADNS_CS_PIN);
+}
+
+uint8_t adns_serial_read(void) {
+ setPinInput(ADNS_SDIO_PIN);
+ uint8_t byte = 0;
+
+ for (uint8_t i = 0; i < 8; ++i) {
+ writePinLow(ADNS_SCLK_PIN);
+ wait_us(1);
+
+ byte = (byte << 1) | readPin(ADNS_SDIO_PIN);
+
+ writePinHigh(ADNS_SCLK_PIN);
+ wait_us(1);
+ }
+
+ return byte;
+}
+
+void adns_serial_write(uint8_t data) {
+ setPinOutput(ADNS_SDIO_PIN);
+
+ for (int8_t b = 7; b >= 0; b--) {
+ writePinLow(ADNS_SCLK_PIN);
+
+ if (data & (1 << b))
+ writePinHigh(ADNS_SDIO_PIN);
+ else
+ writePinLow(ADNS_SDIO_PIN);
+
+ wait_us(2);
+
+ writePinHigh(ADNS_SCLK_PIN);
+ }
+
+ // tSWR. See page 15 of the ADNS spec sheet.
+ // Technically, this is only necessary if the next operation is an SDIO
+ // read. This is not guaranteed to be the case, but we're being lazy.
+ wait_us(4);
+
+ // Note that tSWW is never necessary. All write operations require at
+ // least 32us, which exceeds tSWW, so there's never a need to wait for it.
+}
+
+// Read a byte of data from a register on the ADNS.
+// Don't forget to use the register map (as defined in the header file).
+uint8_t adns_read_reg(uint8_t reg_addr) {
+ adns_cs_select();
+
+ adns_serial_write(reg_addr);
+
+ // We don't need a minimum tSRAD here. That's because a 4ms wait time is
+ // already included in adns_serial_write(), so we're good.
+ // See page 10 and 15 of the ADNS spec sheet.
+ //wait_us(4);
+
+ uint8_t byte = adns_serial_read();
+
+ // tSRW & tSRR. See page 15 of the ADNS spec sheet.
+ // Technically, this is only necessary if the next operation is an SDIO
+ // read or write. This is not guaranteed to be the case.
+ // Honestly, this wait could probably be removed.
+ wait_us(1);
+
+ adns_cs_deselect();
+
+ return byte;
+}
+
+void adns_write_reg(uint8_t reg_addr, uint8_t data) {
+ adns_cs_select();
+ adns_serial_write(reg_addr);
+ adns_serial_write(data);
+ adns_cs_deselect();
+}
+
+report_adns_t adns_read_burst(void) {
+ adns_cs_select();
+
+ report_adns_t data;
+ data.dx = 0;
+ data.dy = 0;
+
+ adns_serial_write(REG_MOTION_BURST);
+
+ // We don't need a minimum tSRAD here. That's because a 4ms wait time is
+ // already included in adns_serial_write(), so we're good.
+ // See page 10 and 15 of the ADNS spec sheet.
+ //wait_us(4);
+
+ uint8_t x = adns_serial_read();
+ uint8_t y = adns_serial_read();
+
+ // Burst mode returns a bunch of other shit that we don't really need.
+ // Setting CS to high ends burst mode early.
+ adns_cs_deselect();
+
+ data.dx = convert_twoscomp(x);
+ data.dy = convert_twoscomp(y);
+
+ return data;
+}
+
+// Convert a two's complement byte from an unsigned data type into a signed
+// data type.
+int8_t convert_twoscomp(uint8_t data) {
+ if ((data & 0x80) == 0x80)
+ return -128 + (data & 0x7F);
+ else
+ return data;
+}
+
+// Don't forget to use the definitions for CPI in the header file.
+void adns_set_cpi(uint8_t cpi) {
+ adns_write_reg(REG_MOUSE_CONTROL2, cpi);
+}
+
+bool adns_check_signature(void) {
+ uint8_t pid = adns_read_reg(REG_PRODUCT_ID);
+ uint8_t rid = adns_read_reg(REG_REVISION_ID);
+ uint8_t pid2 = adns_read_reg(REG_PRODUCT_ID2);
+
+ return (pid == 0x12 && rid == 0x01 && pid2 == 0x26);
+}
diff --git a/drivers/sensors/adns5050.h b/drivers/sensors/adns5050.h
new file mode 100644
index 0000000000..ff8e8f78e9
--- /dev/null
+++ b/drivers/sensors/adns5050.h
@@ -0,0 +1,79 @@
+/* Copyright 2021 Colin Lam (Ploopy Corporation)
+ * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2019 Hiroyuki Okada
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+
+// Registers
+#define REG_PRODUCT_ID 0x00
+#define REG_REVISION_ID 0x01
+#define REG_MOTION 0x02
+#define REG_DELTA_X 0x03
+#define REG_DELTA_Y 0x04
+#define REG_SQUAL 0x05
+#define REG_SHUTTER_UPPER 0x06
+#define REG_SHUTTER_LOWER 0x07
+#define REG_MAXIMUM_PIXEL 0x08
+#define REG_PIXEL_SUM 0x09
+#define REG_MINIMUM_PIXEL 0x0a
+#define REG_PIXEL_GRAB 0x0b
+#define REG_MOUSE_CONTROL 0x0d
+#define REG_MOUSE_CONTROL2 0x19
+#define REG_LED_DC_MODE 0x22
+#define REG_CHIP_RESET 0x3a
+#define REG_PRODUCT_ID2 0x3e
+#define REG_INV_REV_ID 0x3f
+#define REG_MOTION_BURST 0x63
+
+// CPI values
+#define CPI125 0x11
+#define CPI250 0x12
+#define CPI375 0x13
+#define CPI500 0x14
+#define CPI625 0x15
+#define CPI750 0x16
+#define CPI875 0x17
+#define CPI1000 0x18
+#define CPI1125 0x19
+#define CPI1250 0x1a
+#define CPI1375 0x1b
+
+#ifdef CONSOLE_ENABLE
+void print_byte(uint8_t byte);
+#endif
+
+typedef struct {
+ int8_t dx;
+ int8_t dy;
+} report_adns_t;
+
+// A bunch of functions to implement the ADNS5050-specific serial protocol.
+// Note that the "serial.h" driver is insufficient, because it does not
+// manually manipulate a serial clock signal.
+void adns_init(void);
+void adns_sync(void);
+uint8_t adns_serial_read(void);
+void adns_serial_write(uint8_t data);
+uint8_t adns_read_reg(uint8_t reg_addr);
+void adns_write_reg(uint8_t reg_addr, uint8_t data);
+report_adns_t adns_read_burst(void);
+int8_t convert_twoscomp(uint8_t data);
+void adns_set_cpi(uint8_t cpi);
+bool adns_check_signature(void);
diff --git a/drivers/sensors/adns9800.c b/drivers/sensors/adns9800.c
new file mode 100644
index 0000000000..36213179f7
--- /dev/null
+++ b/drivers/sensors/adns9800.c
@@ -0,0 +1,219 @@
+/* Copyright 2020 Alexander Tulloh
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "spi_master.h"
+#include "quantum.h"
+#include "adns9800_srom_A6.h"
+#include "adns9800.h"
+
+// registers
+#define REG_Product_ID 0x00
+#define REG_Revision_ID 0x01
+#define REG_Motion 0x02
+#define REG_Delta_X_L 0x03
+#define REG_Delta_X_H 0x04
+#define REG_Delta_Y_L 0x05
+#define REG_Delta_Y_H 0x06
+#define REG_SQUAL 0x07
+#define REG_Pixel_Sum 0x08
+#define REG_Maximum_Pixel 0x09
+#define REG_Minimum_Pixel 0x0a
+#define REG_Shutter_Lower 0x0b
+#define REG_Shutter_Upper 0x0c
+#define REG_Frame_Period_Lower 0x0d
+#define REG_Frame_Period_Upper 0x0e
+#define REG_Configuration_I 0x0f
+#define REG_Configuration_II 0x10
+#define REG_Frame_Capture 0x12
+#define REG_SROM_Enable 0x13
+#define REG_Run_Downshift 0x14
+#define REG_Rest1_Rate 0x15
+#define REG_Rest1_Downshift 0x16
+#define REG_Rest2_Rate 0x17
+#define REG_Rest2_Downshift 0x18
+#define REG_Rest3_Rate 0x19
+#define REG_Frame_Period_Max_Bound_Lower 0x1a
+#define REG_Frame_Period_Max_Bound_Upper 0x1b
+#define REG_Frame_Period_Min_Bound_Lower 0x1c
+#define REG_Frame_Period_Min_Bound_Upper 0x1d
+#define REG_Shutter_Max_Bound_Lower 0x1e
+#define REG_Shutter_Max_Bound_Upper 0x1f
+#define REG_LASER_CTRL0 0x20
+#define REG_Observation 0x24
+#define REG_Data_Out_Lower 0x25
+#define REG_Data_Out_Upper 0x26
+#define REG_SROM_ID 0x2a
+#define REG_Lift_Detection_Thr 0x2e
+#define REG_Configuration_V 0x2f
+#define REG_Configuration_IV 0x39
+#define REG_Power_Up_Reset 0x3a
+#define REG_Shutdown 0x3b
+#define REG_Inverse_Product_ID 0x3f
+#define REG_Motion_Burst 0x50
+#define REG_SROM_Load_Burst 0x62
+#define REG_Pixel_Burst 0x64
+
+#define ADNS_CLOCK_SPEED 2000000
+#define MIN_CPI 200
+#define MAX_CPI 8200
+#define CPI_STEP 200
+#define CLAMP_CPI(value) value < MIN_CPI ? MIN_CPI : value > MAX_CPI ? MAX_CPI : value
+#define SPI_MODE 3
+#define SPI_DIVISOR (F_CPU / ADNS_CLOCK_SPEED)
+#define US_BETWEEN_WRITES 120
+#define US_BETWEEN_READS 20
+#define US_BEFORE_MOTION 100
+#define MSB1 0x80
+
+extern const uint16_t adns_firmware_length;
+extern const uint8_t adns_firmware_data[];
+
+void adns_spi_start(void){
+ spi_start(SPI_SS_PIN, false, SPI_MODE, SPI_DIVISOR);
+}
+
+void adns_write(uint8_t reg_addr, uint8_t data){
+
+ adns_spi_start();
+ spi_write(reg_addr | MSB1);
+ spi_write(data);
+ spi_stop();
+ wait_us(US_BETWEEN_WRITES);
+}
+
+uint8_t adns_read(uint8_t reg_addr){
+
+ adns_spi_start();
+ spi_write(reg_addr & 0x7f );
+ uint8_t data = spi_read();
+ spi_stop();
+ wait_us(US_BETWEEN_READS);
+
+ return data;
+}
+
+void adns_init() {
+
+ setPinOutput(SPI_SS_PIN);
+
+ spi_init();
+
+ // reboot
+ adns_write(REG_Power_Up_Reset, 0x5a);
+ wait_ms(50);
+
+ // read registers and discard
+ adns_read(REG_Motion);
+ adns_read(REG_Delta_X_L);
+ adns_read(REG_Delta_X_H);
+ adns_read(REG_Delta_Y_L);
+ adns_read(REG_Delta_Y_H);
+
+ // upload firmware
+
+ // 3k firmware mode
+ adns_write(REG_Configuration_IV, 0x02);
+
+ // enable initialisation
+ adns_write(REG_SROM_Enable, 0x1d);
+
+ // wait a frame
+ wait_ms(10);
+
+ // start SROM download
+ adns_write(REG_SROM_Enable, 0x18);
+
+ // write the SROM file
+
+ adns_spi_start();
+
+ spi_write(REG_SROM_Load_Burst | 0x80);
+ wait_us(15);
+
+ // send all bytes of the firmware
+ unsigned char c;
+ for(int i = 0; i < adns_firmware_length; i++){
+ c = (unsigned char)pgm_read_byte(adns_firmware_data + i);
+ spi_write(c);
+ wait_us(15);
+ }
+
+ spi_stop();
+
+ wait_ms(10);
+
+ // enable laser
+ uint8_t laser_ctrl0 = adns_read(REG_LASER_CTRL0);
+ adns_write(REG_LASER_CTRL0, laser_ctrl0 & 0xf0);
+}
+
+config_adns_t adns_get_config(void) {
+ uint8_t config_1 = adns_read(REG_Configuration_I);
+ return (config_adns_t){ (config_1 & 0xFF) * CPI_STEP };
+}
+
+void adns_set_config(config_adns_t config) {
+ uint8_t config_1 = (CLAMP_CPI(config.cpi) / CPI_STEP) & 0xFF;
+ adns_write(REG_Configuration_I, config_1);
+}
+
+static int16_t convertDeltaToInt(uint8_t high, uint8_t low){
+
+ // join bytes into twos compliment
+ uint16_t twos_comp = (high << 8) | low;
+
+ // convert twos comp to int
+ if (twos_comp & 0x8000)
+ return -1 * (~twos_comp + 1);
+
+ return twos_comp;
+}
+
+report_adns_t adns_get_report(void) {
+
+ report_adns_t report = {0, 0};
+
+ adns_spi_start();
+
+ // start burst mode
+ spi_write(REG_Motion_Burst & 0x7f);
+
+ wait_us(US_BEFORE_MOTION);
+
+ uint8_t motion = spi_read();
+
+ if(motion & 0x80) {
+
+ // clear observation register
+ spi_read();
+
+ // delta registers
+ uint8_t delta_x_l = spi_read();
+ uint8_t delta_x_h = spi_read();
+ uint8_t delta_y_l = spi_read();
+ uint8_t delta_y_h = spi_read();
+
+ report.x = convertDeltaToInt(delta_x_h, delta_x_l);
+ report.y = convertDeltaToInt(delta_y_h, delta_y_l);
+ }
+
+ // clear residual motion
+ spi_write(REG_Motion & 0x7f);
+
+ spi_stop();
+
+ return report;
+}
diff --git a/drivers/sensors/adns9800.h b/drivers/sensors/adns9800.h
new file mode 100644
index 0000000000..2f50b8f1be
--- /dev/null
+++ b/drivers/sensors/adns9800.h
@@ -0,0 +1,35 @@
+/* Copyright 2020 Alexander Tulloh
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+
+typedef struct {
+ /* 200 - 8200 CPI supported */
+ uint16_t cpi;
+} config_adns_t;
+
+typedef struct {
+ int16_t x;
+ int16_t y;
+} report_adns_t;
+
+void adns_init(void);
+config_adns_t adns_get_config(void);
+void adns_set_config(config_adns_t);
+/* Reads and clears the current delta values on the ADNS sensor */
+report_adns_t adns_get_report(void);
diff --git a/drivers/sensors/adns9800_srom_A6.h b/drivers/sensors/adns9800_srom_A6.h
new file mode 100644
index 0000000000..f5b3abeb62
--- /dev/null
+++ b/drivers/sensors/adns9800_srom_A6.h
@@ -0,0 +1,3078 @@
+#pragma once
+
+#include "progmem.h"
+
+const uint16_t adns_firmware_length = 3070;
+
+const uint8_t adns_firmware_data[] PROGMEM = {
+0x03,
+0xa6,
+0x68,
+0x1e,
+0x7d,
+0x10,
+0x7e,
+0x7e,
+0x5f,
+0x1c,
+0xb8,
+0xf2,
+0x47,
+0x0c,
+0x7b,
+0x74,
+0x4b,
+0x14,
+0x8b,
+0x75,
+0x66,
+0x51,
+0x0b,
+0x8c,
+0x76,
+0x74,
+0x4b,
+0x14,
+0xaa,
+0xd6,
+0x0f,
+0x9c,
+0xba,
+0xf6,
+0x6e,
+0x3f,
+0xdd,
+0x38,
+0xd5,
+0x02,
+0x80,
+0x9b,
+0x82,
+0x6d,
+0x58,
+0x13,
+0xa4,
+0xab,
+0xb5,
+0xc9,
+0x10,
+0xa2,
+0xc6,
+0x0a,
+0x7f,
+0x5d,
+0x19,
+0x91,
+0xa0,
+0xa3,
+0xce,
+0xeb,
+0x3e,
+0xc9,
+0xf1,
+0x60,
+0x42,
+0xe7,
+0x4c,
+0xfb,
+0x74,
+0x6a,
+0x56,
+0x2e,
+0xbf,
+0xdd,
+0x38,
+0xd3,
+0x05,
+0x88,
+0x92,
+0xa6,
+0xce,
+0xff,
+0x5d,
+0x38,
+0xd1,
+0xcf,
+0xef,
+0x58,
+0xcb,
+0x65,
+0x48,
+0xf0,
+0x35,
+0x85,
+0xa9,
+0xb2,
+0x8f,
+0x5e,
+0xf3,
+0x80,
+0x94,
+0x97,
+0x7e,
+0x75,
+0x97,
+0x87,
+0x73,
+0x13,
+0xb0,
+0x8a,
+0x69,
+0xd4,
+0x0a,
+0xde,
+0xc1,
+0x79,
+0x59,
+0x36,
+0xdb,
+0x9d,
+0xd6,
+0xb8,
+0x15,
+0x6f,
+0xce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44,
+0x4d,
+0xb8,
+0xda,
+0xa2,
+0xa1,
+0xc9,
+0x15,
+0xd3,
+0x73,
+0x03,
+0x0e,
+0x43,
+0xe9,
+0x8e,
+0x15,
+0xf9,
+0xbe,
+0xc6,
+0xc5,
+0x8a,
+0xe5,
+0xc0,
+0x1e,
+0xc2,
+0x37,
+0x9e,
+0x2a,
+0x26,
+0xa5,
+0xa0,
+0xbd,
+0x24,
+0x5f,
+0xb9,
+0xc1,
+0xab,
+0x34,
+0x48,
+0xb9,
+0x5d,
+0x98,
+0xb4,
+0x65,
+0x18,
+0xf3,
+0x63,
+0x19,
+0x44,
+0x1b,
+0x11,
+0x16,
+0xff,
+0xdc,
+0xf1,
+0x79,
+0x08,
+0x86,
+0x0f,
+0x52,
+0x98,
+0x73,
+0xc4,
+0x92,
+0x90,
+0x2b,
+0x47,
+0x09,
+0xd0,
+0x43,
+0x6c,
+0x2f,
+0x20,
+0xeb,
+0xdc,
+0xda,
+0xc5,
+0x08,
+0x7b,
+0x94,
+0x42,
+0x30,
+0x6a,
+0xc7,
+0xda,
+0x8c,
+0xc3,
+0x76,
+0xa7,
+0xa5,
+0xcc,
+0x62,
+0x13,
+0x00,
+0x60,
+0x31,
+0x58,
+0x44,
+0x9b,
+0xf5,
+0x64,
+0x14,
+0xf5,
+0x11,
+0xc5,
+0x54,
+0x52,
+0x83,
+0xd4,
+0x73,
+0x01,
+0x16,
+0x0e,
+0xb3,
+0x7a,
+0x29,
+0x69,
+0x35,
+0x56,
+0xd4,
+0xee,
+0x8a,
+0x17,
+0xa2,
+0x99,
+0x24,
+0x9c,
+0xd7,
+0x8f,
+0xdb,
+0x55,
+0xb5,
+0x3e
+};
diff --git a/drivers/sensors/pimoroni_trackball.c b/drivers/sensors/pimoroni_trackball.c
new file mode 100644
index 0000000000..c0ac644f70
--- /dev/null
+++ b/drivers/sensors/pimoroni_trackball.c
@@ -0,0 +1,140 @@
+/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "pimoroni_trackball.h"
+#include "i2c_master.h"
+
+static uint8_t scrolling = 0;
+static int16_t x_offset = 0;
+static int16_t y_offset = 0;
+static int16_t h_offset = 0;
+static int16_t v_offset = 0;
+static float precisionSpeed = 1;
+
+static uint16_t i2c_timeout_timer;
+
+#ifndef PIMORONI_I2C_TIMEOUT
+# define PIMORONI_I2C_TIMEOUT 100
+#endif
+#ifndef I2C_WAITCHECK
+# define I2C_WAITCHECK 1000
+#endif
+#ifndef MOUSE_DEBOUNCE
+# define MOUSE_DEBOUNCE 5
+#endif
+
+void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
+ uint8_t data[] = {0x00, red, green, blue, white};
+ i2c_transmit(TRACKBALL_WRITE, data, sizeof(data), PIMORONI_I2C_TIMEOUT);
+}
+
+int16_t mouse_offset(uint8_t positive, uint8_t negative, int16_t scale) {
+ int16_t offset = (int16_t)positive - (int16_t)negative;
+ int16_t magnitude = (int16_t)(scale * offset * offset * precisionSpeed);
+ return offset < 0 ? -magnitude : magnitude;
+}
+
+void update_member(int8_t* member, int16_t* offset) {
+ if (*offset > 127) {
+ *member = 127;
+ *offset -= 127;
+ } else if (*offset < -127) {
+ *member = -127;
+ *offset += 127;
+ } else {
+ *member = *offset;
+ *offset = 0;
+ }
+}
+
+__attribute__((weak)) void trackball_check_click(bool pressed, report_mouse_t* mouse) {
+ if (pressed) {
+ mouse->buttons |= MOUSE_BTN1;
+ } else {
+ mouse->buttons &= ~MOUSE_BTN1;
+ }
+}
+
+float trackball_get_precision(void) { return precisionSpeed; }
+void trackball_set_precision(float precision) { precisionSpeed = precision; }
+bool trackball_is_scrolling(void) { return scrolling; }
+void trackball_set_scrolling(bool scroll) { scrolling = scroll; }
+
+__attribute__((weak)) void pointing_device_init(void) { i2c_init(); trackball_set_rgbw(0x00, 0x00, 0x00, 0x00); }
+
+void pointing_device_task(void) {
+ static bool debounce;
+ static uint16_t debounce_timer;
+ uint8_t state[5] = {};
+ if (timer_elapsed(i2c_timeout_timer) > I2C_WAITCHECK) {
+ if (i2c_readReg(TRACKBALL_READ, 0x04, state, 5, PIMORONI_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
+ if (!state[4] && !debounce) {
+ if (scrolling) {
+#ifdef PIMORONI_TRACKBALL_INVERT_X
+ h_offset += mouse_offset(state[2], state[3], 1);
+#else
+ h_offset -= mouse_offset(state[2], state[3], 1);
+#endif
+#ifdef PIMORONI_TRACKBALL_INVERT_Y
+ v_offset += mouse_offset(state[1], state[0], 1);
+#else
+ v_offset -= mouse_offset(state[1], state[0], 1);
+#endif
+ } else {
+#ifdef PIMORONI_TRACKBALL_INVERT_X
+ x_offset -= mouse_offset(state[2], state[3], 5);
+#else
+ x_offset += mouse_offset(state[2], state[3], 5);
+#endif
+#ifdef PIMORONI_TRACKBALL_INVERT_Y
+ y_offset -= mouse_offset(state[1], state[0], 5);
+#else
+ y_offset += mouse_offset(state[1], state[0], 5);
+#endif
+ }
+ } else {
+ if (state[4]) {
+ debounce = true;
+ debounce_timer = timer_read();
+ }
+ }
+ } else {
+ i2c_timeout_timer = timer_read();
+ }
+ }
+
+ if (timer_elapsed(debounce_timer) > MOUSE_DEBOUNCE) debounce = false;
+
+ report_mouse_t mouse = pointing_device_get_report();
+
+#ifdef PIMORONI_TRACKBALL_CLICK
+ trackball_check_click(state[4] & (1 << 7), &mouse);
+#endif
+
+#ifndef PIMORONI_TRACKBALL_ROTATE
+ update_member(&mouse.x, &x_offset);
+ update_member(&mouse.y, &y_offset);
+ update_member(&mouse.h, &h_offset);
+ update_member(&mouse.v, &v_offset);
+#else
+ update_member(&mouse.x, &y_offset);
+ update_member(&mouse.y, &x_offset);
+ update_member(&mouse.h, &v_offset);
+ update_member(&mouse.v, &h_offset);
+#endif
+ pointing_device_set_report(mouse);
+ pointing_device_send();
+}
diff --git a/drivers/sensors/pimoroni_trackball.h b/drivers/sensors/pimoroni_trackball.h
new file mode 100644
index 0000000000..a30fb0bb8c
--- /dev/null
+++ b/drivers/sensors/pimoroni_trackball.h
@@ -0,0 +1,35 @@
+/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include "quantum.h"
+#include "pointing_device.h"
+
+#ifndef TRACKBALL_ADDRESS
+# define TRACKBALL_ADDRESS 0x0A
+#endif
+#define TRACKBALL_WRITE ((TRACKBALL_ADDRESS << 1) | I2C_WRITE)
+#define TRACKBALL_READ ((TRACKBALL_ADDRESS << 1) | I2C_READ)
+
+void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white);
+void trackball_check_click(bool pressed, report_mouse_t *mouse);
+void trackball_register_button(bool pressed, enum mouse_buttons button);
+
+float trackball_get_precision(void);
+void trackball_set_precision(float precision);
+bool trackball_is_scrolling(void);
+void trackball_set_scrolling(bool scroll);
diff --git a/drivers/sensors/pmw3360.c b/drivers/sensors/pmw3360.c
new file mode 100644
index 0000000000..91ee87b957
--- /dev/null
+++ b/drivers/sensors/pmw3360.c
@@ -0,0 +1,237 @@
+/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2020 Ploopy Corporation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "wait.h"
+#include "debug.h"
+#include "print.h"
+#include "pmw3360.h"
+#include "pmw3360_firmware.h"
+
+bool _inBurst = false;
+
+#ifndef PMW_CPI
+# define PMW_CPI 1600
+#endif
+#ifndef PMW_CLOCK_SPEED
+# define PMW_CLOCK_SPEED 70000000
+#endif
+#ifndef SPI_MODE
+# define SPI_MODE 3
+#endif
+#ifndef SPI_DIVISOR
+# define SPI_DIVISOR (F_CPU / PMW_CLOCK_SPEED)
+#endif
+#ifndef ROTATIONAL_TRANSFORM_ANGLE
+# define ROTATIONAL_TRANSFORM_ANGLE 0x00
+#endif
+#ifndef PMW_CS_PIN
+# define PMW_CS_PIN SPI_SS_PIN
+#endif
+
+void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); }
+
+bool spi_start_adv(void) {
+ bool status = spi_start(PMW_CS_PIN, false, SPI_MODE, SPI_DIVISOR);
+ wait_us(1);
+ return status;
+}
+
+void spi_stop_adv(void) {
+ wait_us(1);
+ spi_stop();
+}
+
+spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data) {
+ if (reg_addr != REG_Motion_Burst) {
+ _inBurst = false;
+ }
+
+ spi_start_adv();
+ // send address of the register, with MSBit = 1 to indicate it's a write
+ spi_status_t status = spi_write(reg_addr | 0x80);
+ status = spi_write(data);
+
+ // tSCLK-NCS for write operation
+ wait_us(20);
+
+ // tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
+ wait_us(100);
+ spi_stop();
+ return status;
+}
+
+uint8_t spi_read_adv(uint8_t reg_addr) {
+ spi_start_adv();
+ // send adress of the register, with MSBit = 0 to indicate it's a read
+ spi_write(reg_addr & 0x7f);
+
+ uint8_t data = spi_read();
+
+ // tSCLK-NCS for read operation is 120ns
+ wait_us(1);
+
+ // tSRW/tSRR (=20us) minus tSCLK-NCS
+ wait_us(19);
+
+ spi_stop();
+ return data;
+}
+
+void pmw_set_cpi(uint16_t cpi) {
+ uint8_t cpival = constrain((cpi / 100) - 1, 0, 0x77); // limits to 0--119
+
+ spi_start_adv();
+ spi_write_adv(REG_Config1, cpival);
+ spi_stop();
+}
+
+uint16_t pmw_get_cpi(void) {
+ uint8_t cpival = spi_read_adv(REG_Config1);
+ return (uint16_t)(cpival & 0xFF) * 100;
+}
+
+bool pmw_spi_init(void) {
+ setPinOutput(PMW_CS_PIN);
+
+ spi_init();
+ _inBurst = false;
+
+ spi_stop();
+ spi_start_adv();
+ spi_stop();
+
+ spi_write_adv(REG_Shutdown, 0xb6); // Shutdown first
+ wait_ms(300);
+
+ spi_start_adv();
+ wait_us(40);
+ spi_stop_adv();
+ wait_us(40);
+
+ spi_write_adv(REG_Power_Up_Reset, 0x5a);
+ wait_ms(50);
+
+ spi_read_adv(REG_Motion);
+ spi_read_adv(REG_Delta_X_L);
+ spi_read_adv(REG_Delta_X_H);
+ spi_read_adv(REG_Delta_Y_L);
+ spi_read_adv(REG_Delta_Y_H);
+
+ pmw_upload_firmware();
+
+ spi_stop_adv();
+
+ wait_ms(10);
+ pmw_set_cpi(PMW_CPI);
+
+ wait_ms(1);
+
+ spi_write_adv(REG_Config2, 0x00);
+
+ spi_write_adv(REG_Angle_Tune, constrain(ROTATIONAL_TRANSFORM_ANGLE, -30, 30));
+
+ bool init_success = pmw_check_signature();
+
+ writePinLow(PMW_CS_PIN);
+
+ return init_success;
+}
+
+void pmw_upload_firmware(void) {
+ spi_write_adv(REG_SROM_Enable, 0x1d);
+
+ wait_ms(10);
+
+ spi_write_adv(REG_SROM_Enable, 0x18);
+
+ spi_start_adv();
+ spi_write(REG_SROM_Load_Burst | 0x80);
+ wait_us(15);
+
+ unsigned char c;
+ for (int i = 0; i < firmware_length; i++) {
+ c = (unsigned char)pgm_read_byte(firmware_data + i);
+ spi_write(c);
+ wait_us(15);
+ }
+ wait_us(200);
+
+ spi_read_adv(REG_SROM_ID);
+
+ spi_write_adv(REG_Config2, 0x00);
+
+ spi_stop();
+ wait_ms(10);
+}
+
+bool pmw_check_signature(void) {
+ uint8_t pid = spi_read_adv(REG_Product_ID);
+ uint8_t iv_pid = spi_read_adv(REG_Inverse_Product_ID);
+ uint8_t SROM_ver = spi_read_adv(REG_SROM_ID);
+ return (pid == 0x42 && iv_pid == 0xBD && SROM_ver == 0x04); // signature for SROM 0x04
+}
+
+report_pmw_t pmw_read_burst(void) {
+ if (!_inBurst) {
+ dprintf("burst on");
+ spi_write_adv(REG_Motion_Burst, 0x00);
+ _inBurst = true;
+ }
+
+ spi_start_adv();
+ spi_write(REG_Motion_Burst);
+ wait_us(35); // waits for tSRAD
+
+ report_pmw_t data;
+ data.motion = 0;
+ data.dx = 0;
+ data.mdx = 0;
+ data.dy = 0;
+ data.mdx = 0;
+
+ data.motion = spi_read();
+ spi_write(0x00); // skip Observation
+ data.dx = spi_read();
+ data.mdx = spi_read();
+ data.dy = spi_read();
+ data.mdy = spi_read();
+
+ spi_stop();
+
+ print_byte(data.motion);
+ print_byte(data.dx);
+ print_byte(data.mdx);
+ print_byte(data.dy);
+ print_byte(data.mdy);
+ dprintf("\n");
+
+ data.isMotion = (data.motion & 0x80) != 0;
+ data.isOnSurface = (data.motion & 0x08) == 0;
+ data.dx |= (data.mdx << 8);
+ data.dx = data.dx * -1;
+ data.dy |= (data.mdy << 8);
+ data.dy = data.dy * -1;
+
+ spi_stop();
+
+ if (data.motion & 0b111) { // panic recovery, sometimes burst mode works weird.
+ _inBurst = false;
+ }
+
+ return data;
+}
diff --git a/drivers/sensors/pmw3360.h b/drivers/sensors/pmw3360.h
new file mode 100644
index 0000000000..d5b1741791
--- /dev/null
+++ b/drivers/sensors/pmw3360.h
@@ -0,0 +1,104 @@
+/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2020 Ploopy Corporation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include "spi_master.h"
+
+// Registers
+#define REG_Product_ID 0x00
+#define REG_Revision_ID 0x01
+#define REG_Motion 0x02
+#define REG_Delta_X_L 0x03
+#define REG_Delta_X_H 0x04
+#define REG_Delta_Y_L 0x05
+#define REG_Delta_Y_H 0x06
+#define REG_SQUAL 0x07
+#define REG_Raw_Data_Sum 0x08
+#define REG_Maximum_Raw_data 0x09
+#define REG_Minimum_Raw_data 0x0A
+#define REG_Shutter_Lower 0x0B
+#define REG_Shutter_Upper 0x0C
+#define REG_Control 0x0D
+#define REG_Config1 0x0F
+#define REG_Config2 0x10
+#define REG_Angle_Tune 0x11
+#define REG_Frame_Capture 0x12
+#define REG_SROM_Enable 0x13
+#define REG_Run_Downshift 0x14
+#define REG_Rest1_Rate_Lower 0x15
+#define REG_Rest1_Rate_Upper 0x16
+#define REG_Rest1_Downshift 0x17
+#define REG_Rest2_Rate_Lower 0x18
+#define REG_Rest2_Rate_Upper 0x19
+#define REG_Rest2_Downshift 0x1A
+#define REG_Rest3_Rate_Lower 0x1B
+#define REG_Rest3_Rate_Upper 0x1C
+#define REG_Observation 0x24
+#define REG_Data_Out_Lower 0x25
+#define REG_Data_Out_Upper 0x26
+#define REG_Raw_Data_Dump 0x29
+#define REG_SROM_ID 0x2A
+#define REG_Min_SQ_Run 0x2B
+#define REG_Raw_Data_Threshold 0x2C
+#define REG_Config5 0x2F
+#define REG_Power_Up_Reset 0x3A
+#define REG_Shutdown 0x3B
+#define REG_Inverse_Product_ID 0x3F
+#define REG_LiftCutoff_Tune3 0x41
+#define REG_Angle_Snap 0x42
+#define REG_LiftCutoff_Tune1 0x4A
+#define REG_Motion_Burst 0x50
+#define REG_LiftCutoff_Tune_Timeout 0x58
+#define REG_LiftCutoff_Tune_Min_Length 0x5A
+#define REG_SROM_Load_Burst 0x62
+#define REG_Lift_Config 0x63
+#define REG_Raw_Data_Burst 0x64
+#define REG_LiftCutoff_Tune2 0x65
+
+#ifdef CONSOLE_ENABLE
+void print_byte(uint8_t byte);
+#endif
+
+typedef struct {
+ int8_t motion;
+ bool isMotion; // True if a motion is detected.
+ bool isOnSurface; // True when a chip is on a surface
+ int16_t dx; // displacement on x directions. Unit: Count. (CPI * Count = Inch value)
+ int8_t mdx;
+ int16_t dy; // displacement on y directions.
+ int8_t mdy;
+} report_pmw_t;
+
+
+
+bool spi_start_adv(void);
+void spi_stop_adv(void);
+spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data);
+uint8_t spi_read_adv(uint8_t reg_addr);
+bool pmw_spi_init(void);
+void pmw_set_cpi(uint16_t cpi);
+uint16_t pmw_get_cpi(void);
+void pmw_upload_firmware(void);
+bool pmw_check_signature(void);
+report_pmw_t pmw_read_burst(void);
+
+
+#define degToRad(angleInDegrees) ((angleInDegrees)*M_PI / 180.0)
+#define radToDeg(angleInRadians) ((angleInRadians)*180.0 / M_PI)
+#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
diff --git a/drivers/sensors/pmw3360_firmware.h b/drivers/sensors/pmw3360_firmware.h
new file mode 100644
index 0000000000..cca5a6a4d8
--- /dev/null
+++ b/drivers/sensors/pmw3360_firmware.h
@@ -0,0 +1,300 @@
+/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
+ * Copyright 2019 Sunjun Kim
+ * Copyright 2020 Ploopy Corporation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+// clang-format off
+// Firmware Blob foor PMW3360
+const uint16_t firmware_length = 4094;
+// clang-format off
+const uint8_t firmware_data[] PROGMEM = { // SROM 0x04
+0x01, 0x04, 0x8e, 0x96, 0x6e, 0x77, 0x3e, 0xfe, 0x7e, 0x5f, 0x1d, 0xb8, 0xf2, 0x66, 0x4e,
+0xff, 0x5d, 0x19, 0xb0, 0xc2, 0x04, 0x69, 0x54, 0x2a, 0xd6, 0x2e, 0xbf, 0xdd, 0x19, 0xb0,
+0xc3, 0xe5, 0x29, 0xb1, 0xe0, 0x23, 0xa5, 0xa9, 0xb1, 0xc1, 0x00, 0x82, 0x67, 0x4c, 0x1a,
+0x97, 0x8d, 0x79, 0x51, 0x20, 0xc7, 0x06, 0x8e, 0x7c, 0x7c, 0x7a, 0x76, 0x4f, 0xfd, 0x59,
+0x30, 0xe2, 0x46, 0x0e, 0x9e, 0xbe, 0xdf, 0x1d, 0x99, 0x91, 0xa0, 0xa5, 0xa1, 0xa9, 0xd0,
+0x22, 0xc6, 0x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ang-format off
diff --git a/keyboards/draculad/keymaps/pimoroni/keymap.c b/keyboards/draculad/keymaps/pimoroni/keymap.c
index 87cbe3cd3a..762ae26c70 100644
--- a/keyboards/draculad/keymaps/pimoroni/keymap.c
+++ b/keyboards/draculad/keymaps/pimoroni/keymap.c
@@ -16,7 +16,7 @@ along with this program. If not, see .
*/
#include QMK_KEYBOARD_H
-#include "pimoroni_trackball.h"
+#include "drivers/sensors/pimoroni_trackball.h"
#include "pointing_device.h"
diff --git a/keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.c b/keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.c
deleted file mode 100644
index c4f4a0441a..0000000000
--- a/keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "pimoroni_trackball.h"
-#include "i2c_master.h"
-
-static uint8_t scrolling = 0;
-static int16_t x_offset = 0;
-static int16_t y_offset = 0;
-static int16_t h_offset = 0;
-static int16_t v_offset = 0;
-static float precisionSpeed = 1;
-
-static uint16_t i2c_timeout_timer;
-
-#ifndef I2C_TIMEOUT
-# define I2C_TIMEOUT 100
-#endif
-#ifndef I2C_WAITCHECK
-# define I2C_WAITCHECK 1000
-#endif
-#ifndef MOUSE_DEBOUNCE
-# define MOUSE_DEBOUNCE 5
-#endif
-
-void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
- uint8_t data[] = {0x00, red, green, blue, white};
- i2c_transmit(TRACKBALL_WRITE, data, sizeof(data), I2C_TIMEOUT);
-}
-
-int16_t mouse_offset(uint8_t positive, uint8_t negative, int16_t scale) {
- int16_t offset = (int16_t)positive - (int16_t)negative;
- int16_t magnitude = (int16_t)(scale * offset * offset * precisionSpeed);
- return offset < 0 ? -magnitude : magnitude;
-}
-
-void update_member(int8_t* member, int16_t* offset) {
- if (*offset > 127) {
- *member = 127;
- *offset -= 127;
- } else if (*offset < -127) {
- *member = -127;
- *offset += 127;
- } else {
- *member = *offset;
- *offset = 0;
- }
-}
-
-__attribute__((weak)) void trackball_check_click(bool pressed, report_mouse_t* mouse) {
- if (pressed) {
- mouse->buttons |= MOUSE_BTN1;
- } else {
- mouse->buttons &= ~MOUSE_BTN1;
- }
-}
-
-bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
- if (true) {
- xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
- }
-
-
- if (!process_record_user(keycode, record)) { return false; }
-
-/* If Mousekeys is disabled, then use handle the mouse button
- * keycodes. This makes things simpler, and allows usage of
- * the keycodes in a consistent manner. But only do this if
- * Mousekeys is not enable, so it's not handled twice.
- */
-#ifndef MOUSEKEY_ENABLE
- if (IS_MOUSEKEY_BUTTON(keycode)) {
- report_mouse_t currentReport = pointing_device_get_report();
- if (record->event.pressed) {
- currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
- } else {
- currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
- }
- pointing_device_set_report(currentReport);
- pointing_device_send();
- }
-#endif
-
- return true;
-}
-
-void trackball_register_button(bool pressed, enum mouse_buttons button) {
- report_mouse_t currentReport = pointing_device_get_report();
- if (pressed) {
- currentReport.buttons |= button;
- } else {
- currentReport.buttons &= ~button;
- }
- pointing_device_set_report(currentReport);
-}
-
-float trackball_get_precision(void) { return precisionSpeed; }
-void trackball_set_precision(float precision) { precisionSpeed = precision; }
-bool trackball_is_scrolling(void) { return scrolling; }
-void trackball_set_scrolling(bool scroll) { scrolling = scroll; }
-
-
-__attribute__((weak)) void pointing_device_init(void) { trackball_set_rgbw(0x80, 0x00, 0x00, 0x00); }
-
-void pointing_device_task(void) {
- static bool debounce;
- static uint16_t debounce_timer;
- uint8_t state[5] = {};
- if (timer_elapsed(i2c_timeout_timer) > I2C_WAITCHECK) {
- if (i2c_readReg(TRACKBALL_WRITE, 0x04, state, 5, I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
- if (!state[4] && !debounce) {
- if (scrolling) {
-#ifdef PIMORONI_TRACKBALL_INVERT_X
- h_offset += mouse_offset(state[2], state[3], 1);
-#else
- h_offset -= mouse_offset(state[2], state[3], 1);
-#endif
-#ifdef PIMORONI_TRACKBALL_INVERT_Y
- v_offset += mouse_offset(state[1], state[0], 1);
-#else
- v_offset -= mouse_offset(state[1], state[0], 1);
-#endif
- } else {
-#ifdef PIMORONI_TRACKBALL_INVERT_X
- x_offset -= mouse_offset(state[2], state[3], 5);
-#else
- x_offset += mouse_offset(state[2], state[3], 5);
-#endif
-#ifdef PIMORONI_TRACKBALL_INVERT_Y
- y_offset -= mouse_offset(state[1], state[0], 5);
-#else
- y_offset += mouse_offset(state[1], state[0], 5);
-#endif
- }
- } else {
- if (state[4]) {
- debounce = true;
- debounce_timer = timer_read();
- }
- }
- } else {
- i2c_timeout_timer = timer_read();
- }
- }
-
- if (timer_elapsed(debounce_timer) > MOUSE_DEBOUNCE) debounce = false;
-
- report_mouse_t mouse = pointing_device_get_report();
- // trackball_check_click(state[4] & (1 << 7), &mouse);
-
-#ifndef PIMORONI_TRACKBALL_ROTATE
- update_member(&mouse.x, &x_offset);
- update_member(&mouse.y, &y_offset);
- update_member(&mouse.h, &h_offset);
- update_member(&mouse.v, &v_offset);
-#else
- update_member(&mouse.x, &y_offset);
- update_member(&mouse.y, &x_offset);
- update_member(&mouse.h, &v_offset);
- update_member(&mouse.v, &h_offset);
-#endif
- pointing_device_set_report(mouse);
- pointing_device_send();
-}
diff --git a/keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.h b/keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.h
deleted file mode 100644
index cfcd5a47a1..0000000000
--- a/keyboards/draculad/keymaps/pimoroni/pimoroni_trackball.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include "quantum.h"
-#include "pointing_device.h"
-
-#ifndef TRACKBALL_ADDRESS
-# define TRACKBALL_ADDRESS 0x0A
-#endif
-#define TRACKBALL_WRITE ((TRACKBALL_ADDRESS << 1) | I2C_WRITE)
-#define TRACKBALL_READ ((TRACKBALL_ADDRESS << 1) | I2C_READ)
-
-void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white);
-void trackball_check_click(bool pressed, report_mouse_t *mouse);
-void trackball_register_button(bool pressed, enum mouse_buttons button);
-
-float trackball_get_precision(void);
-void trackball_set_precision(float precision);
-bool trackball_is_scrolling(void);
-void trackball_set_scrolling(bool scroll);
\ No newline at end of file
diff --git a/keyboards/draculad/keymaps/pimoroni/rules.mk b/keyboards/draculad/keymaps/pimoroni/rules.mk
index 547a02f26f..d8dc92fbfc 100644
--- a/keyboards/draculad/keymaps/pimoroni/rules.mk
+++ b/keyboards/draculad/keymaps/pimoroni/rules.mk
@@ -1,6 +1,6 @@
# only uncomment on the side you have your trackball on
POINTING_DEVICE_ENABLE = yes
-SRC += pimoroni_trackball.c
+SRC += drivers/sensors/pimoroni_trackball.c
QUANTUM_LIB_SRC += i2c_master.c
OLED_DRIVER_ENABLE = yes
MOUSEKEY_ENABLE = no
diff --git a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/5x6_right_trackball.h b/keyboards/handwired/dactyl_manuform/5x6_right_trackball/5x6_right_trackball.h
index c8650f73d3..ed408563f7 100644
--- a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/5x6_right_trackball.h
+++ b/keyboards/handwired/dactyl_manuform/5x6_right_trackball/5x6_right_trackball.h
@@ -19,7 +19,7 @@
#include "dactyl_manuform.h"
#include "quantum.h"
#include "spi_master.h"
-#include "pmw3360.h"
+#include "drivers/sensors/pmw3360.h"
#include "pointing_device.h"
diff --git a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360.c b/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360.c
deleted file mode 100644
index 59e3495127..0000000000
--- a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- * Copyright 2019 Sunjun Kim
- * Copyright 2020 Ploopy Corporation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#ifdef POINTING_DEVICE_ENABLE
-
-#include "wait.h"
-#include "debug.h"
-#include "print.h"
-#include "pmw3360.h"
-#include "pmw3360_firmware.h"
-
-bool _inBurst = false;
-
-#ifndef PMW_CPI
-# define PMW_CPI 1600
-#endif
-#ifndef SPI_DIVISOR
-# define SPI_DIVISOR 2
-#endif
-#ifndef ROTATIONAL_TRANSFORM_ANGLE
-# define ROTATIONAL_TRANSFORM_ANGLE 0x00
-#endif
-
-void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); }
-
-bool spi_start_adv(void) {
- bool status = spi_start(SPI_SS_PIN, false, 3, SPI_DIVISOR);
- wait_us(1);
- return status;
-}
-
-void spi_stop_adv(void) {
- wait_us(1);
- spi_stop();
-}
-
-spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data) {
- if (reg_addr != REG_Motion_Burst) {
- _inBurst = false;
- }
-
- spi_start_adv();
- // send address of the register, with MSBit = 1 to indicate it's a write
- spi_status_t status = spi_write(reg_addr | 0x80);
- status = spi_write(data);
-
- // tSCLK-NCS for write operation
- wait_us(20);
-
- // tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
- wait_us(100);
- spi_stop();
- return status;
-}
-
-uint8_t spi_read_adv(uint8_t reg_addr) {
- spi_start_adv();
- // send adress of the register, with MSBit = 0 to indicate it's a read
- spi_write(reg_addr & 0x7f);
-
- uint8_t data = spi_read();
-
- // tSCLK-NCS for read operation is 120ns
- wait_us(1);
-
- // tSRW/tSRR (=20us) minus tSCLK-NCS
- wait_us(19);
-
- spi_stop();
- return data;
-}
-
-void pmw_set_cpi(uint16_t cpi) {
- int cpival = constrain((cpi / 100) - 1, 0, 0x77); // limits to 0--119
-
- spi_start_adv();
- spi_write_adv(REG_Config1, cpival);
- spi_stop();
-}
-
-bool pmw_spi_init(void) {
- spi_init();
- _inBurst = false;
-
- spi_stop();
- spi_start_adv();
- spi_stop();
-
- spi_write_adv(REG_Shutdown, 0xb6); // Shutdown first
- wait_ms(300);
-
- spi_start_adv();
- wait_us(40);
- spi_stop_adv();
- wait_us(40);
-
- spi_write_adv(REG_Power_Up_Reset, 0x5a);
- wait_ms(50);
-
- spi_read_adv(REG_Motion);
- spi_read_adv(REG_Delta_X_L);
- spi_read_adv(REG_Delta_X_H);
- spi_read_adv(REG_Delta_Y_L);
- spi_read_adv(REG_Delta_Y_H);
-
- pmw_upload_firmware();
-
- spi_stop_adv();
-
- wait_ms(10);
- pmw_set_cpi(PMW_CPI);
-
- wait_ms(1);
-
- return pmw_check_signature();
-}
-
-void pmw_upload_firmware(void) {
- spi_write_adv(REG_Config2, 0x00);
-
- spi_write_adv(REG_Angle_Tune, constrain(ROTATIONAL_TRANSFORM_ANGLE, -30, 30));
-
- spi_write_adv(REG_SROM_Enable, 0x1d);
-
- wait_ms(10);
-
- spi_write_adv(REG_SROM_Enable, 0x18);
-
- spi_start_adv();
- spi_write(REG_SROM_Load_Burst | 0x80);
- wait_us(15);
-
- unsigned char c;
- for (int i = 0; i < firmware_length; i++) {
- c = (unsigned char)pgm_read_byte(firmware_data + i);
- spi_write(c);
- wait_us(15);
- }
- wait_us(200);
-
- spi_read_adv(REG_SROM_ID);
-
- spi_write_adv(REG_Config2, 0x00);
-
- spi_stop();
- wait_ms(10);
-}
-
-bool pmw_check_signature(void) {
- uint8_t pid = spi_read_adv(REG_Product_ID);
- uint8_t iv_pid = spi_read_adv(REG_Inverse_Product_ID);
- uint8_t SROM_ver = spi_read_adv(REG_SROM_ID);
- return (pid == 0x42 && iv_pid == 0xBD && SROM_ver == 0x04); // signature for SROM 0x04
-}
-
-report_pmw_t pmw_read_burst(void) {
- if (!_inBurst) {
- dprintf("burst on");
- spi_write_adv(REG_Motion_Burst, 0x00);
- _inBurst = true;
- }
-
- spi_start_adv();
- spi_write(REG_Motion_Burst);
- wait_us(35); // waits for tSRAD
-
- report_pmw_t data;
- data.motion = 0;
- data.dx = 0;
- data.mdx = 0;
- data.dy = 0;
- data.mdx = 0;
-
- data.motion = spi_read();
- spi_write(0x00); // skip Observation
- data.dx = spi_read();
- data.mdx = spi_read();
- data.dy = spi_read();
- data.mdy = spi_read();
-
- spi_stop();
-
- print_byte(data.motion);
- print_byte(data.dx);
- print_byte(data.mdx);
- print_byte(data.dy);
- print_byte(data.mdy);
- dprintf("\n");
-
- data.isMotion = (data.motion & 0x80) != 0;
- data.isOnSurface = (data.motion & 0x08) == 0;
- data.dx |= (data.mdx << 8);
- data.dx = data.dx * -1;
- data.dy |= (data.mdy << 8);
- data.dy = data.dy * -1;
-
- spi_stop();
-
- if (data.motion & 0b111) { // panic recovery, sometimes burst mode works weird.
- _inBurst = false;
- }
-
- return data;
-}
-
-#endif
diff --git a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360.h b/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360.h
deleted file mode 100644
index c1d5e3badb..0000000000
--- a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- * Copyright 2019 Sunjun Kim
- * Copyright 2020 Ploopy Corporation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include "spi_master.h"
-
-// Registers
-#define REG_Product_ID 0x00
-#define REG_Revision_ID 0x01
-#define REG_Motion 0x02
-#define REG_Delta_X_L 0x03
-#define REG_Delta_X_H 0x04
-#define REG_Delta_Y_L 0x05
-#define REG_Delta_Y_H 0x06
-#define REG_SQUAL 0x07
-#define REG_Raw_Data_Sum 0x08
-#define REG_Maximum_Raw_data 0x09
-#define REG_Minimum_Raw_data 0x0A
-#define REG_Shutter_Lower 0x0B
-#define REG_Shutter_Upper 0x0C
-#define REG_Control 0x0D
-#define REG_Config1 0x0F
-#define REG_Config2 0x10
-#define REG_Angle_Tune 0x11
-#define REG_Frame_Capture 0x12
-#define REG_SROM_Enable 0x13
-#define REG_Run_Downshift 0x14
-#define REG_Rest1_Rate_Lower 0x15
-#define REG_Rest1_Rate_Upper 0x16
-#define REG_Rest1_Downshift 0x17
-#define REG_Rest2_Rate_Lower 0x18
-#define REG_Rest2_Rate_Upper 0x19
-#define REG_Rest2_Downshift 0x1A
-#define REG_Rest3_Rate_Lower 0x1B
-#define REG_Rest3_Rate_Upper 0x1C
-#define REG_Observation 0x24
-#define REG_Data_Out_Lower 0x25
-#define REG_Data_Out_Upper 0x26
-#define REG_Raw_Data_Dump 0x29
-#define REG_SROM_ID 0x2A
-#define REG_Min_SQ_Run 0x2B
-#define REG_Raw_Data_Threshold 0x2C
-#define REG_Config5 0x2F
-#define REG_Power_Up_Reset 0x3A
-#define REG_Shutdown 0x3B
-#define REG_Inverse_Product_ID 0x3F
-#define REG_LiftCutoff_Tune3 0x41
-#define REG_Angle_Snap 0x42
-#define REG_LiftCutoff_Tune1 0x4A
-#define REG_Motion_Burst 0x50
-#define REG_LiftCutoff_Tune_Timeout 0x58
-#define REG_LiftCutoff_Tune_Min_Length 0x5A
-#define REG_SROM_Load_Burst 0x62
-#define REG_Lift_Config 0x63
-#define REG_Raw_Data_Burst 0x64
-#define REG_LiftCutoff_Tune2 0x65
-
-#ifdef CONSOLE_ENABLE
-void print_byte(uint8_t byte);
-#endif
-
-typedef struct {
- int8_t motion;
- bool isMotion; // True if a motion is detected.
- bool isOnSurface; // True when a chip is on a surface
- int16_t dx; // displacement on x directions. Unit: Count. (CPI * Count = Inch value)
- int8_t mdx;
- int16_t dy; // displacement on y directions.
- int8_t mdy;
-} report_pmw_t;
-
-
-
-bool spi_start_adv(void);
-void spi_stop_adv(void);
-spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data);
-uint8_t spi_read_adv(uint8_t reg_addr);
-bool pmw_spi_init(void);
-void pmw_set_cpi(uint16_t cpi);
-void pmw_upload_firmware(void);
-bool pmw_check_signature(void);
-report_pmw_t pmw_read_burst(void);
-
-
-#define degToRad(angleInDegrees) ((angleInDegrees)*M_PI / 180.0)
-#define radToDeg(angleInRadians) ((angleInRadians)*180.0 / M_PI)
-#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
diff --git a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360_firmware.h b/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360_firmware.h
deleted file mode 100644
index cca5a6a4d8..0000000000
--- a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/pmw3360_firmware.h
+++ /dev/null
@@ -1,300 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- * Copyright 2019 Sunjun Kim
- * Copyright 2020 Ploopy Corporation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-// clang-format off
-// Firmware Blob foor PMW3360
-const uint16_t firmware_length = 4094;
-// clang-format off
-const uint8_t firmware_data[] PROGMEM = { // SROM 0x04
-0x01, 0x04, 0x8e, 0x96, 0x6e, 0x77, 0x3e, 0xfe, 0x7e, 0x5f, 0x1d, 0xb8, 0xf2, 0x66, 0x4e,
-0xff, 0x5d, 0x19, 0xb0, 0xc2, 0x04, 0x69, 0x54, 0x2a, 0xd6, 0x2e, 0xbf, 0xdd, 0x19, 0xb0,
-0xc3, 0xe5, 0x29, 0xb1, 0xe0, 0x23, 0xa5, 0xa9, 0xb1, 0xc1, 0x00, 0x82, 0x67, 0x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, 0x32, 0xc7, 0x0c, 0x7b,
-0x74, 0x4b, 0x14, 0xaa, 0xb7, 0xec, 0x3b, 0xd5, 0x28, 0xd2, 0x07, 0x6d, 0x39, 0xd1, 0x20,
-0xc2, 0xe7, 0x4c, 0x1a, 0x97, 0x8d, 0x98, 0xb2, 0xc7, 0x0c, 0x59, 0x28, 0xf3, 0x9b };
-
-// clang-format off
diff --git a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/rules.mk b/keyboards/handwired/dactyl_manuform/5x6_right_trackball/rules.mk
index 3fb9ab2a84..9f4a5ea02e 100644
--- a/keyboards/handwired/dactyl_manuform/5x6_right_trackball/rules.mk
+++ b/keyboards/handwired/dactyl_manuform/5x6_right_trackball/rules.mk
@@ -27,5 +27,5 @@ MOUSE_SHARED_EP = no
SPLIT_KEYBOARD = yes
SPLIT_TRANSPORT = custom
-SRC += pmw3360.c
+SRC += drivers/sensors/pmw3360.c
QUANTUM_LIB_SRC += pointer_transport.c serial.c i2c_master.c i2c_slave.c spi_master.c
diff --git a/keyboards/oddball/adns/adns.c b/keyboards/oddball/adns/adns.c
deleted file mode 100644
index 9338808ff7..0000000000
--- a/keyboards/oddball/adns/adns.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/* Copyright 2020 Alexander Tulloh
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "spi_master.h"
-#include "quantum.h"
-#include "adns9800_srom_A6.h"
-#include "adns.h"
-
-// registers
-#define REG_Product_ID 0x00
-#define REG_Revision_ID 0x01
-#define REG_Motion 0x02
-#define REG_Delta_X_L 0x03
-#define REG_Delta_X_H 0x04
-#define REG_Delta_Y_L 0x05
-#define REG_Delta_Y_H 0x06
-#define REG_SQUAL 0x07
-#define REG_Pixel_Sum 0x08
-#define REG_Maximum_Pixel 0x09
-#define REG_Minimum_Pixel 0x0a
-#define REG_Shutter_Lower 0x0b
-#define REG_Shutter_Upper 0x0c
-#define REG_Frame_Period_Lower 0x0d
-#define REG_Frame_Period_Upper 0x0e
-#define REG_Configuration_I 0x0f
-#define REG_Configuration_II 0x10
-#define REG_Frame_Capture 0x12
-#define REG_SROM_Enable 0x13
-#define REG_Run_Downshift 0x14
-#define REG_Rest1_Rate 0x15
-#define REG_Rest1_Downshift 0x16
-#define REG_Rest2_Rate 0x17
-#define REG_Rest2_Downshift 0x18
-#define REG_Rest3_Rate 0x19
-#define REG_Frame_Period_Max_Bound_Lower 0x1a
-#define REG_Frame_Period_Max_Bound_Upper 0x1b
-#define REG_Frame_Period_Min_Bound_Lower 0x1c
-#define REG_Frame_Period_Min_Bound_Upper 0x1d
-#define REG_Shutter_Max_Bound_Lower 0x1e
-#define REG_Shutter_Max_Bound_Upper 0x1f
-#define REG_LASER_CTRL0 0x20
-#define REG_Observation 0x24
-#define REG_Data_Out_Lower 0x25
-#define REG_Data_Out_Upper 0x26
-#define REG_SROM_ID 0x2a
-#define REG_Lift_Detection_Thr 0x2e
-#define REG_Configuration_V 0x2f
-#define REG_Configuration_IV 0x39
-#define REG_Power_Up_Reset 0x3a
-#define REG_Shutdown 0x3b
-#define REG_Inverse_Product_ID 0x3f
-#define REG_Motion_Burst 0x50
-#define REG_SROM_Load_Burst 0x62
-#define REG_Pixel_Burst 0x64
-
-#define ADNS_CLOCK_SPEED 2000000
-#define MIN_CPI 200
-#define MAX_CPI 8200
-#define CPI_STEP 200
-#define CLAMP_CPI(value) value < MIN_CPI ? MIN_CPI : value > MAX_CPI ? MAX_CPI : value
-#define SPI_MODE 3
-#define SPI_DIVISOR (F_CPU / ADNS_CLOCK_SPEED)
-#define US_BETWEEN_WRITES 120
-#define US_BETWEEN_READS 20
-#define US_BEFORE_MOTION 100
-#define MSB1 0x80
-
-extern const uint16_t adns_firmware_length;
-extern const uint8_t adns_firmware_data[];
-
-void adns_spi_start(void){
- spi_start(SPI_SS_PIN, false, SPI_MODE, SPI_DIVISOR);
-}
-
-void adns_write(uint8_t reg_addr, uint8_t data){
-
- adns_spi_start();
- spi_write(reg_addr | MSB1);
- spi_write(data);
- spi_stop();
- wait_us(US_BETWEEN_WRITES);
-}
-
-uint8_t adns_read(uint8_t reg_addr){
-
- adns_spi_start();
- spi_write(reg_addr & 0x7f );
- uint8_t data = spi_read();
- spi_stop();
- wait_us(US_BETWEEN_READS);
-
- return data;
-}
-
-void adns_init() {
-
- setPinOutput(SPI_SS_PIN);
-
- spi_init();
-
- // reboot
- adns_write(REG_Power_Up_Reset, 0x5a);
- wait_ms(50);
-
- // read registers and discard
- adns_read(REG_Motion);
- adns_read(REG_Delta_X_L);
- adns_read(REG_Delta_X_H);
- adns_read(REG_Delta_Y_L);
- adns_read(REG_Delta_Y_H);
-
- // upload firmware
-
- // 3k firmware mode
- adns_write(REG_Configuration_IV, 0x02);
-
- // enable initialisation
- adns_write(REG_SROM_Enable, 0x1d);
-
- // wait a frame
- wait_ms(10);
-
- // start SROM download
- adns_write(REG_SROM_Enable, 0x18);
-
- // write the SROM file
-
- adns_spi_start();
-
- spi_write(REG_SROM_Load_Burst | 0x80);
- wait_us(15);
-
- // send all bytes of the firmware
- unsigned char c;
- for(int i = 0; i < adns_firmware_length; i++){
- c = (unsigned char)pgm_read_byte(adns_firmware_data + i);
- spi_write(c);
- wait_us(15);
- }
-
- spi_stop();
-
- wait_ms(10);
-
- // enable laser
- uint8_t laser_ctrl0 = adns_read(REG_LASER_CTRL0);
- adns_write(REG_LASER_CTRL0, laser_ctrl0 & 0xf0);
-}
-
-config_adns_t adns_get_config(void) {
- uint8_t config_1 = adns_read(REG_Configuration_I);
- return (config_adns_t){ (config_1 & 0xFF) * CPI_STEP };
-}
-
-void adns_set_config(config_adns_t config) {
- uint8_t config_1 = (CLAMP_CPI(config.cpi) / CPI_STEP) & 0xFF;
- adns_write(REG_Configuration_I, config_1);
-}
-
-static int16_t convertDeltaToInt(uint8_t high, uint8_t low){
-
- // join bytes into twos compliment
- uint16_t twos_comp = (high << 8) | low;
-
- // convert twos comp to int
- if (twos_comp & 0x8000)
- return -1 * (~twos_comp + 1);
-
- return twos_comp;
-}
-
-report_adns_t adns_get_report(void) {
-
- report_adns_t report = {0, 0};
-
- adns_spi_start();
-
- // start burst mode
- spi_write(REG_Motion_Burst & 0x7f);
-
- wait_us(US_BEFORE_MOTION);
-
- uint8_t motion = spi_read();
-
- if(motion & 0x80) {
-
- // clear observation register
- spi_read();
-
- // delta registers
- uint8_t delta_x_l = spi_read();
- uint8_t delta_x_h = spi_read();
- uint8_t delta_y_l = spi_read();
- uint8_t delta_y_h = spi_read();
-
- report.x = convertDeltaToInt(delta_x_h, delta_x_l);
- report.y = convertDeltaToInt(delta_y_h, delta_y_l);
- }
-
- // clear residual motion
- spi_write(REG_Motion & 0x7f);
-
- spi_stop();
-
- return report;
-}
diff --git a/keyboards/oddball/adns/adns.h b/keyboards/oddball/adns/adns.h
deleted file mode 100644
index 2f50b8f1be..0000000000
--- a/keyboards/oddball/adns/adns.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright 2020 Alexander Tulloh
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-
-typedef struct {
- /* 200 - 8200 CPI supported */
- uint16_t cpi;
-} config_adns_t;
-
-typedef struct {
- int16_t x;
- int16_t y;
-} report_adns_t;
-
-void adns_init(void);
-config_adns_t adns_get_config(void);
-void adns_set_config(config_adns_t);
-/* Reads and clears the current delta values on the ADNS sensor */
-report_adns_t adns_get_report(void);
diff --git a/keyboards/oddball/adns/adns9800_srom_A6.h b/keyboards/oddball/adns/adns9800_srom_A6.h
deleted file mode 100644
index f5b3abeb62..0000000000
--- a/keyboards/oddball/adns/adns9800_srom_A6.h
+++ /dev/null
@@ -1,3078 +0,0 @@
-#pragma once
-
-#include "progmem.h"
-
-const uint16_t adns_firmware_length = 3070;
-
-const uint8_t adns_firmware_data[] PROGMEM = {
-0x03,
-0xa6,
-0x68,
-0x1e,
-0x7d,
-0x10,
-0x7e,
-0x7e,
-0x5f,
-0x1c,
-0xb8,
-0xf2,
-0x47,
-0x0c,
-0x7b,
-0x74,
-0x4b,
-0x14,
-0x8b,
-0x75,
-0x66,
-0x51,
-0x0b,
-0x8c,
-0x76,
-0x74,
-0x4b,
-0x14,
-0xaa,
-0xd6,
-0x0f,
-0x9c,
-0xba,
-0xf6,
-0x6e,
-0x3f,
-0xdd,
-0x38,
-0xd5,
-0x02,
-0x80,
-0x9b,
-0x82,
-0x6d,
-0x58,
-0x13,
-0xa4,
-0xab,
-0xb5,
-0xc9,
-0x10,
-0xa2,
-0xc6,
-0x0a,
-0x7f,
-0x5d,
-0x19,
-0x91,
-0xa0,
-0xa3,
-0xce,
-0xeb,
-0x3e,
-0xc9,
-0xf1,
-0x60,
-0x42,
-0xe7,
-0x4c,
-0xfb,
-0x74,
-0x6a,
-0x56,
-0x2e,
-0xbf,
-0xdd,
-0x38,
-0xd3,
-0x05,
-0x88,
-0x92,
-0xa6,
-0xce,
-0xff,
-0x5d,
-0x38,
-0xd1,
-0xcf,
-0xef,
-0x58,
-0xcb,
-0x65,
-0x48,
-0xf0,
-0x35,
-0x85,
-0xa9,
-0xb2,
-0x8f,
-0x5e,
-0xf3,
-0x80,
-0x94,
-0x97,
-0x7e,
-0x75,
-0x97,
-0x87,
-0x73,
-0x13,
-0xb0,
-0x8a,
-0x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
-0xae,
-0x54,
-0x7c,
-0xd3,
-0x57,
-0x84,
-0x7b,
-0x3a,
-0x65,
-0x18,
-0x81,
-0xee,
-0x05,
-0x9b,
-0x44,
-0x4d,
-0xb8,
-0xda,
-0xa2,
-0xa1,
-0xc9,
-0x15,
-0xd3,
-0x73,
-0x03,
-0x0e,
-0x43,
-0xe9,
-0x8e,
-0x15,
-0xf9,
-0xbe,
-0xc6,
-0xc5,
-0x8a,
-0xe5,
-0xc0,
-0x1e,
-0xc2,
-0x37,
-0x9e,
-0x2a,
-0x26,
-0xa5,
-0xa0,
-0xbd,
-0x24,
-0x5f,
-0xb9,
-0xc1,
-0xab,
-0x34,
-0x48,
-0xb9,
-0x5d,
-0x98,
-0xb4,
-0x65,
-0x18,
-0xf3,
-0x63,
-0x19,
-0x44,
-0x1b,
-0x11,
-0x16,
-0xff,
-0xdc,
-0xf1,
-0x79,
-0x08,
-0x86,
-0x0f,
-0x52,
-0x98,
-0x73,
-0xc4,
-0x92,
-0x90,
-0x2b,
-0x47,
-0x09,
-0xd0,
-0x43,
-0x6c,
-0x2f,
-0x20,
-0xeb,
-0xdc,
-0xda,
-0xc5,
-0x08,
-0x7b,
-0x94,
-0x42,
-0x30,
-0x6a,
-0xc7,
-0xda,
-0x8c,
-0xc3,
-0x76,
-0xa7,
-0xa5,
-0xcc,
-0x62,
-0x13,
-0x00,
-0x60,
-0x31,
-0x58,
-0x44,
-0x9b,
-0xf5,
-0x64,
-0x14,
-0xf5,
-0x11,
-0xc5,
-0x54,
-0x52,
-0x83,
-0xd4,
-0x73,
-0x01,
-0x16,
-0x0e,
-0xb3,
-0x7a,
-0x29,
-0x69,
-0x35,
-0x56,
-0xd4,
-0xee,
-0x8a,
-0x17,
-0xa2,
-0x99,
-0x24,
-0x9c,
-0xd7,
-0x8f,
-0xdb,
-0x55,
-0xb5,
-0x3e
-};
diff --git a/keyboards/oddball/optical_sensor/optical_sensor.h b/keyboards/oddball/optical_sensor/optical_sensor.h
index a152d02cf1..00955209e2 100644
--- a/keyboards/oddball/optical_sensor/optical_sensor.h
+++ b/keyboards/oddball/optical_sensor/optical_sensor.h
@@ -17,7 +17,7 @@
/* common interface for opitcal sensors */
#if defined ADNS_9800
- #include "../adns/adns.h"
+ #include "drivers/sensors/adns9800.h"
#define config_optical_sensor_t config_adns_t
#define report_optical_sensor_t report_adns_t
#define optical_sensor_init adns_init
diff --git a/keyboards/oddball/rules.mk b/keyboards/oddball/rules.mk
index e9e540c3ca..8fc86b570d 100644
--- a/keyboards/oddball/rules.mk
+++ b/keyboards/oddball/rules.mk
@@ -25,5 +25,5 @@ POINTING_DEVICE_ENABLE = yes
DEFAULT_FOLDER = oddball/v1
SRC += spi_master.c
-SRC += adns/adns.c
+SRC += drivers/sensors/adns9800.c
SRC += pmw/pmw.c
diff --git a/keyboards/ploopyco/adns5050.c b/keyboards/ploopyco/adns5050.c
deleted file mode 100644
index fcf2f213e4..0000000000
--- a/keyboards/ploopyco/adns5050.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/* Copyright 2021 Colin Lam (Ploopy Corporation)
- * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- * Copyright 2019 Sunjun Kim
- * Copyright 2019 Hiroyuki Okada
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-
-#include "adns5050.h"
-#include "quantum.h"
-#include "wait.h"
-
-#ifdef CONSOLE_ENABLE
-# include "print.h"
-#endif
-
-#ifndef OPTIC_ROTATED
-# define OPTIC_ROTATED false
-#endif
-
-// Definitions for the ADNS serial line.
-// These really ought to be defined in your config.h, but defaults are
-// here if you're really lazy.
-#ifndef ADNS_SCLK_PIN
-# define ADNS_SCLK_PIN B7
-#endif
-
-#ifndef ADNS_SDIO_PIN
-# define ADNS_SDIO_PIN C6
-#endif
-
-#ifndef ADNS_CS_PIN
-# define ADNS_CS_PIN B4
-#endif
-
-#ifdef CONSOLE_ENABLE
-void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); }
-#endif
-
-// Initialize the ADNS serial pins.
-void adns_init(void) {
- setPinOutput(ADNS_SCLK_PIN);
- setPinOutput(ADNS_SDIO_PIN);
- setPinOutput(ADNS_CS_PIN);
-}
-
-// Perform a synchronization with the ADNS.
-// Just as with the serial protocol, this is used by the slave to send a
-// synchronization signal to the master.
-void adns_sync(void) {
- writePinLow(ADNS_CS_PIN);
- wait_us(1);
- writePinHigh(ADNS_CS_PIN);
-}
-
-void adns_cs_select(void) {
- writePinLow(ADNS_CS_PIN);
-}
-
-void adns_cs_deselect(void) {
- writePinHigh(ADNS_CS_PIN);
-}
-
-uint8_t adns_serial_read(void) {
- setPinInput(ADNS_SDIO_PIN);
- uint8_t byte = 0;
-
- for (uint8_t i = 0; i < 8; ++i) {
- writePinLow(ADNS_SCLK_PIN);
- wait_us(1);
-
- byte = (byte << 1) | readPin(ADNS_SDIO_PIN);
-
- writePinHigh(ADNS_SCLK_PIN);
- wait_us(1);
- }
-
- return byte;
-}
-
-void adns_serial_write(uint8_t data) {
- setPinOutput(ADNS_SDIO_PIN);
-
- for (int8_t b = 7; b >= 0; b--) {
- writePinLow(ADNS_SCLK_PIN);
-
- if (data & (1 << b))
- writePinHigh(ADNS_SDIO_PIN);
- else
- writePinLow(ADNS_SDIO_PIN);
-
- wait_us(2);
-
- writePinHigh(ADNS_SCLK_PIN);
- }
-
- // tSWR. See page 15 of the ADNS spec sheet.
- // Technically, this is only necessary if the next operation is an SDIO
- // read. This is not guaranteed to be the case, but we're being lazy.
- wait_us(4);
-
- // Note that tSWW is never necessary. All write operations require at
- // least 32us, which exceeds tSWW, so there's never a need to wait for it.
-}
-
-// Read a byte of data from a register on the ADNS.
-// Don't forget to use the register map (as defined in the header file).
-uint8_t adns_read_reg(uint8_t reg_addr) {
- adns_cs_select();
-
- adns_serial_write(reg_addr);
-
- // We don't need a minimum tSRAD here. That's because a 4ms wait time is
- // already included in adns_serial_write(), so we're good.
- // See page 10 and 15 of the ADNS spec sheet.
- //wait_us(4);
-
- uint8_t byte = adns_serial_read();
-
- // tSRW & tSRR. See page 15 of the ADNS spec sheet.
- // Technically, this is only necessary if the next operation is an SDIO
- // read or write. This is not guaranteed to be the case.
- // Honestly, this wait could probably be removed.
- wait_us(1);
-
- adns_cs_deselect();
-
- return byte;
-}
-
-void adns_write_reg(uint8_t reg_addr, uint8_t data) {
- adns_cs_select();
- adns_serial_write(reg_addr);
- adns_serial_write(data);
- adns_cs_deselect();
-}
-
-report_adns_t adns_read_burst(void) {
- adns_cs_select();
-
- report_adns_t data;
- data.dx = 0;
- data.dy = 0;
-
- adns_serial_write(REG_MOTION_BURST);
-
- // We don't need a minimum tSRAD here. That's because a 4ms wait time is
- // already included in adns_serial_write(), so we're good.
- // See page 10 and 15 of the ADNS spec sheet.
- //wait_us(4);
-
- uint8_t x = adns_serial_read();
- uint8_t y = adns_serial_read();
-
- // Burst mode returns a bunch of other shit that we don't really need.
- // Setting CS to high ends burst mode early.
- adns_cs_deselect();
-
- data.dx = convert_twoscomp(x);
- data.dy = convert_twoscomp(y);
-
- return data;
-}
-
-// Convert a two's complement byte from an unsigned data type into a signed
-// data type.
-int8_t convert_twoscomp(uint8_t data) {
- if ((data & 0x80) == 0x80)
- return -128 + (data & 0x7F);
- else
- return data;
-}
-
-// Don't forget to use the definitions for CPI in the header file.
-void adns_set_cpi(uint8_t cpi) {
- adns_write_reg(REG_MOUSE_CONTROL2, cpi);
-}
-
-bool adns_check_signature(void) {
- uint8_t pid = adns_read_reg(REG_PRODUCT_ID);
- uint8_t rid = adns_read_reg(REG_REVISION_ID);
- uint8_t pid2 = adns_read_reg(REG_PRODUCT_ID2);
-
- return (pid == 0x12 && rid == 0x01 && pid2 == 0x26);
-}
diff --git a/keyboards/ploopyco/adns5050.h b/keyboards/ploopyco/adns5050.h
deleted file mode 100644
index ff8e8f78e9..0000000000
--- a/keyboards/ploopyco/adns5050.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* Copyright 2021 Colin Lam (Ploopy Corporation)
- * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- * Copyright 2019 Sunjun Kim
- * Copyright 2019 Hiroyuki Okada
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-
-// Registers
-#define REG_PRODUCT_ID 0x00
-#define REG_REVISION_ID 0x01
-#define REG_MOTION 0x02
-#define REG_DELTA_X 0x03
-#define REG_DELTA_Y 0x04
-#define REG_SQUAL 0x05
-#define REG_SHUTTER_UPPER 0x06
-#define REG_SHUTTER_LOWER 0x07
-#define REG_MAXIMUM_PIXEL 0x08
-#define REG_PIXEL_SUM 0x09
-#define REG_MINIMUM_PIXEL 0x0a
-#define REG_PIXEL_GRAB 0x0b
-#define REG_MOUSE_CONTROL 0x0d
-#define REG_MOUSE_CONTROL2 0x19
-#define REG_LED_DC_MODE 0x22
-#define REG_CHIP_RESET 0x3a
-#define REG_PRODUCT_ID2 0x3e
-#define REG_INV_REV_ID 0x3f
-#define REG_MOTION_BURST 0x63
-
-// CPI values
-#define CPI125 0x11
-#define CPI250 0x12
-#define CPI375 0x13
-#define CPI500 0x14
-#define CPI625 0x15
-#define CPI750 0x16
-#define CPI875 0x17
-#define CPI1000 0x18
-#define CPI1125 0x19
-#define CPI1250 0x1a
-#define CPI1375 0x1b
-
-#ifdef CONSOLE_ENABLE
-void print_byte(uint8_t byte);
-#endif
-
-typedef struct {
- int8_t dx;
- int8_t dy;
-} report_adns_t;
-
-// A bunch of functions to implement the ADNS5050-specific serial protocol.
-// Note that the "serial.h" driver is insufficient, because it does not
-// manually manipulate a serial clock signal.
-void adns_init(void);
-void adns_sync(void);
-uint8_t adns_serial_read(void);
-void adns_serial_write(uint8_t data);
-uint8_t adns_read_reg(uint8_t reg_addr);
-void adns_write_reg(uint8_t reg_addr, uint8_t data);
-report_adns_t adns_read_burst(void);
-int8_t convert_twoscomp(uint8_t data);
-void adns_set_cpi(uint8_t cpi);
-bool adns_check_signature(void);
diff --git a/keyboards/ploopyco/mouse/mouse.h b/keyboards/ploopyco/mouse/mouse.h
index 5d49d2f2d2..d11aa5e9a4 100644
--- a/keyboards/ploopyco/mouse/mouse.h
+++ b/keyboards/ploopyco/mouse/mouse.h
@@ -20,7 +20,7 @@
#include "quantum.h"
#include "spi_master.h"
-#include "pmw3360.h"
+#include "drivers/sensors/pmw3360.h"
#include "analog.h"
#include "opt_encoder.h"
#include "pointing_device.h"
diff --git a/keyboards/ploopyco/mouse/rules.mk b/keyboards/ploopyco/mouse/rules.mk
index f998672f14..17aac98016 100644
--- a/keyboards/ploopyco/mouse/rules.mk
+++ b/keyboards/ploopyco/mouse/rules.mk
@@ -27,4 +27,4 @@ POINTING_DEVICE_ENABLE = yes
MOUSEKEY_ENABLE = yes # Mouse keys
QUANTUM_LIB_SRC += analog.c spi_master.c
-SRC += pmw3360.c opt_encoder.c
+SRC += drivers/sensors/pmw3360.c opt_encoder.c
diff --git a/keyboards/ploopyco/pmw3360.c b/keyboards/ploopyco/pmw3360.c
deleted file mode 100644
index 5f9f72a9ec..0000000000
--- a/keyboards/ploopyco/pmw3360.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- * Copyright 2019 Sunjun Kim
- * Copyright 2020 Ploopy Corporation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "wait.h"
-#include "debug.h"
-#include "print.h"
-#include "pmw3360.h"
-#include "pmw3360_firmware.h"
-
-bool _inBurst = false;
-
-#ifndef PMW_CPI
-# define PMW_CPI 1600
-#endif
-#ifndef SPI_DIVISOR
-# define SPI_DIVISOR 2
-#endif
-#ifndef ROTATIONAL_TRANSFORM_ANGLE
-# define ROTATIONAL_TRANSFORM_ANGLE 0x00
-#endif
-
-void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); }
-
-
-bool spi_start_adv(void) {
- bool status = spi_start(SPI_SS_PIN, false, 3, SPI_DIVISOR);
- wait_us(1);
- return status;
-}
-
-void spi_stop_adv(void) {
- wait_us(1);
- spi_stop();
-}
-
-spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data) {
- if (reg_addr != REG_Motion_Burst) {
- _inBurst = false;
- }
-
- spi_start_adv();
- // send address of the register, with MSBit = 1 to indicate it's a write
- spi_status_t status = spi_write(reg_addr | 0x80);
- status = spi_write(data);
-
- // tSCLK-NCS for write operation
- wait_us(20);
-
- // tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
- wait_us(100);
- spi_stop();
- return status;
-}
-
-uint8_t spi_read_adv(uint8_t reg_addr) {
- spi_start_adv();
- // send adress of the register, with MSBit = 0 to indicate it's a read
- spi_write(reg_addr & 0x7f);
-
- uint8_t data = spi_read();
-
- // tSCLK-NCS for read operation is 120ns
- wait_us(1);
-
- // tSRW/tSRR (=20us) minus tSCLK-NCS
- wait_us(19);
-
- spi_stop();
- return data;
-}
-
-void pmw_set_cpi(uint16_t cpi) {
- int cpival = constrain((cpi / 100) - 1, 0, 0x77); // limits to 0--119
-
- spi_start_adv();
- spi_write_adv(REG_Config1, cpival);
- spi_stop();
-}
-
-bool pmw_spi_init(void) {
- spi_init();
- _inBurst = false;
-
- spi_stop();
- spi_start_adv();
- spi_stop();
-
- spi_write_adv(REG_Shutdown, 0xb6); // Shutdown first
- wait_ms(300);
-
- spi_start_adv();
- wait_us(40);
- spi_stop_adv();
- wait_us(40);
-
- spi_write_adv(REG_Power_Up_Reset, 0x5a);
- wait_ms(50);
-
- spi_read_adv(REG_Motion);
- spi_read_adv(REG_Delta_X_L);
- spi_read_adv(REG_Delta_X_H);
- spi_read_adv(REG_Delta_Y_L);
- spi_read_adv(REG_Delta_Y_H);
-
- pmw_upload_firmware();
-
- spi_stop_adv();
-
- wait_ms(10);
- pmw_set_cpi(PMW_CPI);
-
- wait_ms(1);
-
- return pmw_check_signature();
-}
-
-void pmw_upload_firmware(void) {
- spi_write_adv(REG_Config2, 0x00);
-
- spi_write_adv(REG_Angle_Tune, constrain(ROTATIONAL_TRANSFORM_ANGLE, -30, 30));
-
- spi_write_adv(REG_SROM_Enable, 0x1d);
-
- wait_ms(10);
-
- spi_write_adv(REG_SROM_Enable, 0x18);
-
- spi_start_adv();
- spi_write(REG_SROM_Load_Burst | 0x80);
- wait_us(15);
-
- unsigned char c;
- for (int i = 0; i < firmware_length; i++) {
- c = (unsigned char)pgm_read_byte(firmware_data + i);
- spi_write(c);
- wait_us(15);
- }
- wait_us(200);
-
- spi_read_adv(REG_SROM_ID);
-
- spi_write_adv(REG_Config2, 0x00);
-
- spi_stop();
- wait_ms(10);
-}
-
-bool pmw_check_signature(void) {
- uint8_t pid = spi_read_adv(REG_Product_ID);
- uint8_t iv_pid = spi_read_adv(REG_Inverse_Product_ID);
- uint8_t SROM_ver = spi_read_adv(REG_SROM_ID);
- return (pid == 0x42 && iv_pid == 0xBD && SROM_ver == 0x04); // signature for SROM 0x04
-}
-
-report_pmw_t pmw_read_burst(void) {
- if (!_inBurst) {
- dprintf("burst on");
- spi_write_adv(REG_Motion_Burst, 0x00);
- _inBurst = true;
- }
-
- spi_start_adv();
- spi_write(REG_Motion_Burst);
- wait_us(35); // waits for tSRAD
-
- report_pmw_t data;
- data.motion = 0;
- data.dx = 0;
- data.mdx = 0;
- data.dy = 0;
- data.mdx = 0;
-
- data.motion = spi_read();
- spi_write(0x00); // skip Observation
- data.dx = spi_read();
- data.mdx = spi_read();
- data.dy = spi_read();
- data.mdy = spi_read();
-
- spi_stop();
-
- print_byte(data.motion);
- print_byte(data.dx);
- print_byte(data.mdx);
- print_byte(data.dy);
- print_byte(data.mdy);
- dprintf("\n");
-
- data.isMotion = (data.motion & 0x80) != 0;
- data.isOnSurface = (data.motion & 0x08) == 0;
- data.dx |= (data.mdx << 8);
- data.dx = data.dx * -1;
- data.dy |= (data.mdy << 8);
- data.dy = data.dy * -1;
-
- spi_stop();
-
- if (data.motion & 0b111) { // panic recovery, sometimes burst mode works weird.
- _inBurst = false;
- }
-
- return data;
-}
diff --git a/keyboards/ploopyco/pmw3360.h b/keyboards/ploopyco/pmw3360.h
deleted file mode 100644
index c1d5e3badb..0000000000
--- a/keyboards/ploopyco/pmw3360.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- * Copyright 2019 Sunjun Kim
- * Copyright 2020 Ploopy Corporation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include "spi_master.h"
-
-// Registers
-#define REG_Product_ID 0x00
-#define REG_Revision_ID 0x01
-#define REG_Motion 0x02
-#define REG_Delta_X_L 0x03
-#define REG_Delta_X_H 0x04
-#define REG_Delta_Y_L 0x05
-#define REG_Delta_Y_H 0x06
-#define REG_SQUAL 0x07
-#define REG_Raw_Data_Sum 0x08
-#define REG_Maximum_Raw_data 0x09
-#define REG_Minimum_Raw_data 0x0A
-#define REG_Shutter_Lower 0x0B
-#define REG_Shutter_Upper 0x0C
-#define REG_Control 0x0D
-#define REG_Config1 0x0F
-#define REG_Config2 0x10
-#define REG_Angle_Tune 0x11
-#define REG_Frame_Capture 0x12
-#define REG_SROM_Enable 0x13
-#define REG_Run_Downshift 0x14
-#define REG_Rest1_Rate_Lower 0x15
-#define REG_Rest1_Rate_Upper 0x16
-#define REG_Rest1_Downshift 0x17
-#define REG_Rest2_Rate_Lower 0x18
-#define REG_Rest2_Rate_Upper 0x19
-#define REG_Rest2_Downshift 0x1A
-#define REG_Rest3_Rate_Lower 0x1B
-#define REG_Rest3_Rate_Upper 0x1C
-#define REG_Observation 0x24
-#define REG_Data_Out_Lower 0x25
-#define REG_Data_Out_Upper 0x26
-#define REG_Raw_Data_Dump 0x29
-#define REG_SROM_ID 0x2A
-#define REG_Min_SQ_Run 0x2B
-#define REG_Raw_Data_Threshold 0x2C
-#define REG_Config5 0x2F
-#define REG_Power_Up_Reset 0x3A
-#define REG_Shutdown 0x3B
-#define REG_Inverse_Product_ID 0x3F
-#define REG_LiftCutoff_Tune3 0x41
-#define REG_Angle_Snap 0x42
-#define REG_LiftCutoff_Tune1 0x4A
-#define REG_Motion_Burst 0x50
-#define REG_LiftCutoff_Tune_Timeout 0x58
-#define REG_LiftCutoff_Tune_Min_Length 0x5A
-#define REG_SROM_Load_Burst 0x62
-#define REG_Lift_Config 0x63
-#define REG_Raw_Data_Burst 0x64
-#define REG_LiftCutoff_Tune2 0x65
-
-#ifdef CONSOLE_ENABLE
-void print_byte(uint8_t byte);
-#endif
-
-typedef struct {
- int8_t motion;
- bool isMotion; // True if a motion is detected.
- bool isOnSurface; // True when a chip is on a surface
- int16_t dx; // displacement on x directions. Unit: Count. (CPI * Count = Inch value)
- int8_t mdx;
- int16_t dy; // displacement on y directions.
- int8_t mdy;
-} report_pmw_t;
-
-
-
-bool spi_start_adv(void);
-void spi_stop_adv(void);
-spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data);
-uint8_t spi_read_adv(uint8_t reg_addr);
-bool pmw_spi_init(void);
-void pmw_set_cpi(uint16_t cpi);
-void pmw_upload_firmware(void);
-bool pmw_check_signature(void);
-report_pmw_t pmw_read_burst(void);
-
-
-#define degToRad(angleInDegrees) ((angleInDegrees)*M_PI / 180.0)
-#define radToDeg(angleInRadians) ((angleInRadians)*180.0 / M_PI)
-#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
diff --git a/keyboards/ploopyco/pmw3360_firmware.h b/keyboards/ploopyco/pmw3360_firmware.h
deleted file mode 100644
index cca5a6a4d8..0000000000
--- a/keyboards/ploopyco/pmw3360_firmware.h
+++ /dev/null
@@ -1,300 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- * Copyright 2019 Sunjun Kim
- * Copyright 2020 Ploopy Corporation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-// clang-format off
-// Firmware Blob foor PMW3360
-const uint16_t firmware_length = 4094;
-// clang-format off
-const uint8_t firmware_data[] PROGMEM = { // SROM 0x04
-0x01, 0x04, 0x8e, 0x96, 0x6e, 0x77, 0x3e, 0xfe, 0x7e, 0x5f, 0x1d, 0xb8, 0xf2, 0x66, 0x4e,
-0xff, 0x5d, 0x19, 0xb0, 0xc2, 0x04, 0x69, 0x54, 0x2a, 0xd6, 0x2e, 0xbf, 0xdd, 0x19, 0xb0,
-0xc3, 0xe5, 0x29, 0xb1, 0xe0, 0x23, 0xa5, 0xa9, 0xb1, 0xc1, 0x00, 0x82, 0x67, 0x4c, 0x1a,
-0x97, 0x8d, 0x79, 0x51, 0x20, 0xc7, 0x06, 0x8e, 0x7c, 0x7c, 0x7a, 0x76, 0x4f, 0xfd, 0x59,
-0x30, 0xe2, 0x46, 0x0e, 0x9e, 0xbe, 0xdf, 0x1d, 0x99, 0x91, 0xa0, 0xa5, 0xa1, 0xa9, 0xd0,
-0x22, 0xc6, 0xef, 0x5c, 0x1b, 0x95, 0x89, 0x90, 0xa2, 0xa7, 0xcc, 0xfb, 0x55, 0x28, 0xb3,
-0xe4, 0x4a, 0xf7, 0x6c, 0x3b, 0xf4, 0x6a, 0x56, 0x2e, 0xde, 0x1f, 0x9d, 0xb8, 0xd3, 0x05,
-0x88, 0x92, 0xa6, 0xce, 0x1e, 0xbe, 0xdf, 0x1d, 0x99, 0xb0, 0xe2, 0x46, 0xef, 0x5c, 0x07,
-0x11, 0x5d, 0x98, 0x0b, 0x9d, 0x94, 0x97, 0xee, 0x4e, 0x45, 0x33, 0x6b, 0x44, 0xc7, 0x29,
-0x56, 0x27, 0x30, 0xc6, 0xa7, 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 0x01, 0x61, 0x21, 0xa1, 0xc0, 0xe3, 0x25, 0xa9, 0xb1, 0xc1, 0xe1, 0x40, 0x02,
-0x67, 0x4c, 0x1a, 0x97, 0x8d, 0x98, 0x93, 0xa4, 0xab, 0xd4, 0x2a, 0xd6, 0x0f, 0x9c, 0x9b,
-0xb4, 0xcb, 0x14, 0xaa, 0xb7, 0xcd, 0xf9, 0x51, 0x20, 0xa3, 0xc4, 0xeb, 0x35, 0xc9, 0xf1,
-0x60, 0x42, 0x06, 0x8e, 0x7f, 0x7c, 0x7a, 0x76, 0x6e, 0x3f, 0xfc, 0x7a, 0x76, 0x6e, 0x5e,
-0x3e, 0xfe, 0x7e, 0x5f, 0x3c, 0xdb, 0x15, 0x89, 0x71, 0x41, 0xe1, 0x21, 0xc0, 0xe3, 0x44,
-0xeb, 0x54, 0x2a, 0xb7, 0xcd, 0xf9, 0x70, 0x62, 0x27, 0xad, 0xd8, 0x32, 0xc7, 0x0c, 0x7b,
-0x74, 0x4b, 0x14, 0xaa, 0xb7, 0xec, 0x3b, 0xd5, 0x28, 0xd2, 0x07, 0x6d, 0x39, 0xd1, 0x20,
-0xc2, 0xe7, 0x4c, 0x1a, 0x97, 0x8d, 0x98, 0xb2, 0xc7, 0x0c, 0x59, 0x28, 0xf3, 0x9b };
-
-// clang-format off
diff --git a/keyboards/ploopyco/trackball/rules.mk b/keyboards/ploopyco/trackball/rules.mk
index e1eb998fe0..4ac92ebf64 100644
--- a/keyboards/ploopyco/trackball/rules.mk
+++ b/keyboards/ploopyco/trackball/rules.mk
@@ -24,6 +24,6 @@ POINTING_DEVICE_ENABLE = yes
MOUSEKEY_ENABLE = yes # Mouse keys
QUANTUM_LIB_SRC += analog.c spi_master.c
-SRC += pmw3360.c opt_encoder.c
+SRC += drivers/sensors/pmw3360.c opt_encoder.c
DEFAULT_FOLDER = ploopyco/trackball/rev1_005
diff --git a/keyboards/ploopyco/trackball/trackball.h b/keyboards/ploopyco/trackball/trackball.h
index fd2bf465a5..70f5d83b11 100644
--- a/keyboards/ploopyco/trackball/trackball.h
+++ b/keyboards/ploopyco/trackball/trackball.h
@@ -20,7 +20,7 @@
#include "quantum.h"
#include "spi_master.h"
-#include "pmw3360.h"
+#include "drivers/sensors/pmw3360.h"
#include "analog.h"
#include "opt_encoder.h"
#include "pointing_device.h"
diff --git a/keyboards/ploopyco/trackball_mini/rules.mk b/keyboards/ploopyco/trackball_mini/rules.mk
index 58fad239f4..22c5e3c062 100644
--- a/keyboards/ploopyco/trackball_mini/rules.mk
+++ b/keyboards/ploopyco/trackball_mini/rules.mk
@@ -27,6 +27,6 @@ POINTING_DEVICE_ENABLE = yes
MOUSEKEY_ENABLE = no # Mouse keys
QUANTUM_LIB_SRC += analog.c
-SRC += adns5050.c opt_encoder.c
+SRC += drivers/sensors/adns5050.c opt_encoder.c
DEFAULT_FOLDER = ploopyco/trackball_mini/rev1_001
diff --git a/keyboards/ploopyco/trackball_mini/trackball_mini.h b/keyboards/ploopyco/trackball_mini/trackball_mini.h
index b9754cbc72..da1b51b17e 100644
--- a/keyboards/ploopyco/trackball_mini/trackball_mini.h
+++ b/keyboards/ploopyco/trackball_mini/trackball_mini.h
@@ -20,7 +20,7 @@
#pragma once
#include "quantum.h"
-#include "adns5050.h"
+#include "drivers/sensors/adns5050.h"
#include "analog.h"
#include "opt_encoder.h"
#include "pointing_device.h"
diff --git a/keyboards/ploopyco/trackball_nano/rules.mk b/keyboards/ploopyco/trackball_nano/rules.mk
index 0286194b9f..f47c316153 100644
--- a/keyboards/ploopyco/trackball_nano/rules.mk
+++ b/keyboards/ploopyco/trackball_nano/rules.mk
@@ -27,6 +27,6 @@ POINTING_DEVICE_ENABLE = yes
MOUSEKEY_ENABLE = no # Mouse keys
QUANTUM_LIB_SRC += analog.c
-SRC += adns5050.c opt_encoder.c
+SRC += drivers/sensors/adns5050.c opt_encoder.c
DEFAULT_FOLDER = ploopyco/trackball_nano/rev1_001
diff --git a/keyboards/ploopyco/trackball_nano/trackball_nano.h b/keyboards/ploopyco/trackball_nano/trackball_nano.h
index 5692383b1e..6c8ecace7d 100644
--- a/keyboards/ploopyco/trackball_nano/trackball_nano.h
+++ b/keyboards/ploopyco/trackball_nano/trackball_nano.h
@@ -20,7 +20,7 @@
#pragma once
#include "quantum.h"
-#include "adns5050.h"
+#include "drivers/sensors/adns5050.h"
#include "analog.h"
#include "opt_encoder.h"
#include "pointing_device.h"
diff --git a/layouts/community/ergodox/drashna/config.h b/layouts/community/ergodox/drashna/config.h
index 4ccba8f04b..f9daf277fb 100644
--- a/layouts/community/ergodox/drashna/config.h
+++ b/layouts/community/ergodox/drashna/config.h
@@ -47,3 +47,4 @@
#define PIMORONI_TRACKBALL_INVERT_X
#define PIMORONI_TRACKBALL_INVERT_Y
+#define PIMORONI_TRACKBALL_CLICK
diff --git a/users/drashna/drashna.h b/users/drashna/drashna.h
index e66f106574..e37c73bb28 100644
--- a/users/drashna/drashna.h
+++ b/users/drashna/drashna.h
@@ -33,7 +33,7 @@
# include "oled_stuff.h"
#endif
#if defined(PIMORONI_TRACKBALL_ENABLE)
-# include "pimoroni_trackball.h"
+# include "drivers/sensors/pimoroni_trackball.h"
#endif
/* Define layer names */
diff --git a/users/drashna/pimoroni_trackball.c b/users/drashna/pimoroni_trackball.c
deleted file mode 100644
index a6ca6c9966..0000000000
--- a/users/drashna/pimoroni_trackball.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "pimoroni_trackball.h"
-#include "i2c_master.h"
-
-static uint8_t scrolling = 0;
-static int16_t x_offset = 0;
-static int16_t y_offset = 0;
-static int16_t h_offset = 0;
-static int16_t v_offset = 0;
-static float precisionSpeed = 1;
-
-#ifndef I2C_TIMEOUT
-# define I2C_TIMEOUT 100
-#endif
-#ifndef MOUSE_DEBOUNCE
-# define MOUSE_DEBOUNCE 5
-#endif
-
-void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
- uint8_t data[] = {0x00, red, green, blue, white};
- i2c_transmit(TRACKBALL_ADDRESS << 1, data, sizeof(data), I2C_TIMEOUT);
-}
-
-int16_t mouse_offset(uint8_t positive, uint8_t negative, int16_t scale) {
- int16_t offset = (int16_t)positive - (int16_t)negative;
- int16_t magnitude = (int16_t)(scale * offset * offset * precisionSpeed);
- return offset < 0 ? -magnitude : magnitude;
-}
-
-void update_member(int8_t* member, int16_t* offset) {
- if (*offset > 127) {
- *member = 127;
- *offset -= 127;
- } else if (*offset < -127) {
- *member = -127;
- *offset += 127;
- } else {
- *member = *offset;
- *offset = 0;
- }
-}
-
-__attribute__((weak)) void trackball_check_click(bool pressed, report_mouse_t* mouse) {
- if (pressed) {
- mouse->buttons |= MOUSE_BTN1;
- } else {
- mouse->buttons &= ~MOUSE_BTN1;
- }
-}
-
-void trackball_register_button(bool pressed, enum mouse_buttons button) {
- report_mouse_t currentReport = pointing_device_get_report();
- if (pressed) {
- currentReport.buttons |= button;
- } else {
- currentReport.buttons &= ~button;
- }
- pointing_device_set_report(currentReport);
-}
-
-float trackball_get_precision(void) { return precisionSpeed; }
-void trackball_set_precision(float precision) { precisionSpeed = precision; }
-bool trackball_is_scrolling(void) { return scrolling; }
-void trackball_set_scrolling(bool scroll) { scrolling = scroll; }
-
-bool has_report_changed (report_mouse_t first, report_mouse_t second) {
- return !(
- (!first.buttons && first.buttons == second.buttons) &&
- (!first.x && first.x == second.x) &&
- (!first.y && first.y == second.y) &&
- (!first.h && first.h == second.h) &&
- (!first.v && first.v == second.v) );
-}
-
-
-__attribute__((weak)) void pointing_device_init(void) { trackball_set_rgbw(0x00, 0x00, 0x00, 0x4F); }
-
-void pointing_device_task(void) {
- static bool debounce;
- static uint16_t debounce_timer;
- uint8_t state[5] = {};
- if (i2c_readReg(TRACKBALL_ADDRESS << 1, 0x04, state, 5, I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
- if (!state[4] && !debounce) {
- if (scrolling) {
-#ifdef PIMORONI_TRACKBALL_INVERT_X
- h_offset += mouse_offset(state[2], state[3], 1);
-#else
- h_offset -= mouse_offset(state[2], state[3], 1);
-#endif
-#ifdef PIMORONI_TRACKBALL_INVERT_Y
- v_offset += mouse_offset(state[1], state[0], 1);
-#else
- v_offset -= mouse_offset(state[1], state[0], 1);
-#endif
- } else {
-#ifdef PIMORONI_TRACKBALL_INVERT_X
- x_offset -= mouse_offset(state[2], state[3], 5);
-#else
- x_offset += mouse_offset(state[2], state[3], 5);
-#endif
-#ifdef PIMORONI_TRACKBALL_INVERT_Y
- y_offset -= mouse_offset(state[1], state[0], 5);
-#else
- y_offset += mouse_offset(state[1], state[0], 5);
-#endif
- }
- } else {
- if (state[4]) {
- debounce = true;
- debounce_timer = timer_read();
- }
- }
- }
-
- if (timer_elapsed(debounce_timer) > MOUSE_DEBOUNCE) debounce = false;
-
- report_mouse_t mouse = pointing_device_get_report();
-
- trackball_check_click(state[4] & (1 << 7), &mouse);
-
-#ifndef PIMORONI_TRACKBALL_ROTATE
- update_member(&mouse.x, &x_offset);
- update_member(&mouse.y, &y_offset);
- update_member(&mouse.h, &h_offset);
- update_member(&mouse.v, &v_offset);
-#else
- update_member(&mouse.x, &y_offset);
- update_member(&mouse.y, &x_offset);
- update_member(&mouse.h, &v_offset);
- update_member(&mouse.v, &h_offset);
-#endif
- pointing_device_set_report(mouse);
- if (has_report_changed(mouse, pointing_device_get_report())) {
- pointing_device_send();
- }
-}
diff --git a/users/drashna/pimoroni_trackball.h b/users/drashna/pimoroni_trackball.h
deleted file mode 100644
index a30fb0bb8c..0000000000
--- a/users/drashna/pimoroni_trackball.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include "quantum.h"
-#include "pointing_device.h"
-
-#ifndef TRACKBALL_ADDRESS
-# define TRACKBALL_ADDRESS 0x0A
-#endif
-#define TRACKBALL_WRITE ((TRACKBALL_ADDRESS << 1) | I2C_WRITE)
-#define TRACKBALL_READ ((TRACKBALL_ADDRESS << 1) | I2C_READ)
-
-void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white);
-void trackball_check_click(bool pressed, report_mouse_t *mouse);
-void trackball_register_button(bool pressed, enum mouse_buttons button);
-
-float trackball_get_precision(void);
-void trackball_set_precision(float precision);
-bool trackball_is_scrolling(void);
-void trackball_set_scrolling(bool scroll);
diff --git a/users/drashna/rules.mk b/users/drashna/rules.mk
index b79051508b..fa4fb2420d 100644
--- a/users/drashna/rules.mk
+++ b/users/drashna/rules.mk
@@ -74,7 +74,7 @@ endif
ifeq ($(strip $(PIMORONI_TRACKBALL_ENABLE)), yes)
POINTING_DEVICE_ENABLE := yes
OPT_DEFS += -DPIMORONI_TRACKBALL_ENABLE
- SRC += pimoroni_trackball.c
+ SRC += drivers/sensors/pimoroni_trackball.c
QUANTUM_LIB_SRC += i2c_master.c
endif
--
cgit v1.2.3
From dd16d3cc7e427c5256f5d2089d0cc2b6bbc776e1 Mon Sep 17 00:00:00 2001
From: Purdea Andrei
Date: Tue, 22 Jun 2021 05:34:28 +0300
Subject: eeprom_i2c driver: added EXTERNAL_EEPROM_WP_PIN configuration option.
(#12617)
---
docs/eeprom_driver.md | 3 +++
drivers/eeprom/eeprom_i2c.c | 23 ++++++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
(limited to 'drivers')
diff --git a/docs/eeprom_driver.md b/docs/eeprom_driver.md
index e2c262546d..6dcf10c04d 100644
--- a/docs/eeprom_driver.md
+++ b/docs/eeprom_driver.md
@@ -31,6 +31,9 @@ Currently QMK supports 24xx-series chips over I2C. As such, requires a working i
`#define EXTERNAL_EEPROM_PAGE_SIZE` | Page size of the EEPROM in bytes, as specified in the datasheet | 32
`#define EXTERNAL_EEPROM_ADDRESS_SIZE` | The number of bytes to transmit for the memory location within the EEPROM | 2
`#define EXTERNAL_EEPROM_WRITE_TIME` | Write cycle time of the EEPROM, as specified in the datasheet | 5
+`#define EXTERNAL_EEPROM_WP_PIN` | If defined the WP pin will be toggled appropriately when writing to the EEPROM. | _none_
+
+Some I2C EEPROM manufacturers explicitly recommend against hardcoding the WP pin to ground. This is in order to protect the eeprom memory content during power-up/power-down/brown-out conditions at low voltage where the eeprom is still operational, but the i2c master output might be unpredictable. If a WP pin is configured, then having an external pull-up on the WP pin is recommended.
Default values and extended descriptions can be found in `drivers/eeprom/eeprom_i2c.h`.
diff --git a/drivers/eeprom/eeprom_i2c.c b/drivers/eeprom/eeprom_i2c.c
index 4210f06f9f..8e80ff544f 100644
--- a/drivers/eeprom/eeprom_i2c.c
+++ b/drivers/eeprom/eeprom_i2c.c
@@ -16,6 +16,9 @@
#include
#include
+#if defined(EXTERNAL_EEPROM_WP_PIN)
+# include "gpio.h"
+#endif
/*
Note that the implementations of eeprom_XXXX_YYYY on AVR are normally
@@ -50,7 +53,14 @@ static inline void fill_target_address(uint8_t *buffer, const void *addr) {
}
}
-void eeprom_driver_init(void) { i2c_init(); }
+void eeprom_driver_init(void) {
+ i2c_init();
+#if defined(EXTERNAL_EEPROM_WP_PIN)
+ /* We are setting the WP pin to high in a way that requires at least two bit-flips to change back to 0 */
+ writePin(EXTERNAL_EEPROM_WP_PIN, 1);
+ setPinInputHigh(EXTERNAL_EEPROM_WP_PIN);
+#endif
+}
void eeprom_driver_erase(void) {
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
@@ -89,6 +99,11 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
uint8_t * read_buf = (uint8_t *)buf;
uintptr_t target_addr = (uintptr_t)addr;
+#if defined(EXTERNAL_EEPROM_WP_PIN)
+ setPinOutput(EXTERNAL_EEPROM_WP_PIN);
+ writePin(EXTERNAL_EEPROM_WP_PIN, 0);
+#endif
+
while (len > 0) {
uintptr_t page_offset = target_addr % EXTERNAL_EEPROM_PAGE_SIZE;
int write_length = EXTERNAL_EEPROM_PAGE_SIZE - page_offset;
@@ -116,4 +131,10 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
target_addr += write_length;
len -= write_length;
}
+
+#if defined(EXTERNAL_EEPROM_WP_PIN)
+ /* We are setting the WP pin to high in a way that requires at least two bit-flips to change back to 0 */
+ writePin(EXTERNAL_EEPROM_WP_PIN, 1);
+ setPinInputHigh(EXTERNAL_EEPROM_WP_PIN);
+#endif
}
--
cgit v1.2.3
From 1ea01765e19bf84b9a09954443b7d64be2bec0c7 Mon Sep 17 00:00:00 2001
From: Gigahawk
Date: Wed, 23 Jun 2021 02:57:46 -0700
Subject: Allow settable SPI divisor for AW20216 driver, set default to 4
(#13309)
---
docs/feature_rgb_matrix.md | 1 +
drivers/awinic/aw20216.c | 6 +++++-
2 files changed, 6 insertions(+), 1 deletion(-)
(limited to 'drivers')
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index 25ba3ffe32..925c9de6e4 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -250,6 +250,7 @@ You can use up to 2 AW20216 IC's. Do not specify `DRIVER__xxx` defines for IC
| `DRIVER_LED_TOTAL` | (Required) How many RGB lights are present across all drivers | |
| `AW_SCALING_MAX` | (Optional) LED current scaling value (0-255, higher values mean LED is brighter at full PWM) | 150 |
| `AW_GLOBAL_CURRENT_MAX` | (Optional) Driver global current limit (0-255, higher values means the driver may consume more power) | 150 |
+| `AW_SPI_DIVISOR` | (Optional) Clock divisor for SPI communication (powers of 2, smaller numbers means faster communication, should not be less than 4) | 4 |
Here is an example using 2 drivers.
diff --git a/drivers/awinic/aw20216.c b/drivers/awinic/aw20216.c
index 236c42a3cd..269bb3a59a 100644
--- a/drivers/awinic/aw20216.c
+++ b/drivers/awinic/aw20216.c
@@ -59,13 +59,17 @@
# define DRIVER_1_EN C13
#endif
+#ifndef AW_SPI_DIVISOR
+# define AW_SPI_DIVISOR 4
+#endif
+
uint8_t g_spi_transfer_buffer[20] = {0};
aw_led g_pwm_buffer[DRIVER_LED_TOTAL];
bool g_pwm_buffer_update_required[DRIVER_LED_TOTAL];
bool AW20216_write_register(pin_t slave_pin, uint8_t page, uint8_t reg, uint8_t data) {
// Do we need to call spi_stop() if this fails?
- if (!spi_start(slave_pin, false, 0, 16)) {
+ if (!spi_start(slave_pin, false, 0, AW_SPI_DIVISOR)) {
return false;
}
--
cgit v1.2.3
From 117bff17ba89a70dd85163b499c262b879f52afd Mon Sep 17 00:00:00 2001
From: Stefan Kerkmann
Date: Fri, 2 Jul 2021 00:24:08 +0200
Subject: [Core] Unite half-duplex and full-duplex serial drivers (#13081)
* Unite half-duplex and full-duplex serial driver.
* Add full duplex operation mode to the interrupt based driver
* Delete DMA UART based full duplex driver
* The new driver targets #11930
* Fix freezes with failing transactions in half-duplex
* Increase default serial TX/RX buffer size to 128 bytes
* Correctly use bool instead of size_t
Co-authored-by: Nick Brassel ---
build_keyboard.mk | 1 +
docs/serial_driver.md | 15 +-
drivers/chibios/serial_usart.c | 337 +++++++++++++++--------
drivers/chibios/serial_usart.h | 40 ++-
drivers/chibios/serial_usart_duplex.c | 261 ------------------
platforms/chibios/QMK_PROTON_C/configs/halconf.h | 2 +-
platforms/chibios/common/configs/halconf.h | 2 +-
7 files changed, 273 insertions(+), 385 deletions(-)
delete mode 100644 drivers/chibios/serial_usart_duplex.c
(limited to 'drivers')
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 4c4ff3b5fd..38ca2aaa99 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -237,6 +237,7 @@ ifdef MCU_FAMILY
PLATFORM=CHIBIOS
PLATFORM_KEY=chibios
FIRMWARE_FORMAT?=bin
+ OPT_DEFS += -DMCU_$(MCU_FAMILY)
else ifdef ARM_ATSAM
PLATFORM=ARM_ATSAM
PLATFORM_KEY=arm_atsam
diff --git a/docs/serial_driver.md b/docs/serial_driver.md
index 359fc59551..ed989b0a15 100644
--- a/docs/serial_driver.md
+++ b/docs/serial_driver.md
@@ -73,7 +73,7 @@ You must also enable the ChibiOS `SERIAL` feature:
Do note that the configuration required is for the `SERIAL` peripheral, not the `UART` peripheral.
### USART Full-duplex
-Targeting STM32 boards where communication is offloaded to a USART hardware device. The advantage over bitbang is that this provides fast and accurate timings. USART Full-Duplex requires two conductors **without** pull-up resistors instead of one conductor with a pull-up resistor unlike the Half-duplex driver, but it is more efficent as it uses DMA transfers, which can result in even faster transmission speeds.
+Targeting STM32 boards where communication is offloaded to a USART hardware device. The advantage over bitbang is that this provides fast and accurate timings. USART Full-Duplex requires two conductors **without** pull-up resistors instead of one conductor with a pull-up resistor unlike the Half-duplex driver. Due to its internal design it is more efficent, which can result in even faster transmission speeds.
#### Pin configuration
@@ -86,12 +86,13 @@ Please note that `TX` of the master half has to be connected with the `RX` pin o
To use the driver, add this to your rules.mk:
```make
-SERIAL_DRIVER = usart_duplex
+SERIAL_DRIVER = usart
```
Next configure the hardware via your config.h:
```c
+#define SERIAL_USART_FULL_DUPLEX // Enable full duplex operation mode.
#define SERIAL_USART_TX_PIN B6 // USART TX pin
#define SERIAL_USART_RX_PIN B7 // USART RX pin
//#define USART1_REMAP // Remap USART TX and RX pins on STM32F103 MCUs, see table below.
@@ -104,17 +105,17 @@ Next configure the hardware via your config.h:
// 3: 57600 baud
// 4: 38400 baud
// 5: 19200 baud
-#define SERIAL_USART_DRIVER UARTD1 // USART driver of TX and RX pin. default: UARTD1
+#define SERIAL_USART_DRIVER SD1 // USART driver of TX and RX pin. default: SD1
#define SERIAL_USART_TX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
#define SERIAL_USART_RX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
#define SERIAL_USART_TIMEOUT 100 // USART driver timeout. default 100
```
-You must also enable the ChibiOS `UART` with blocking api feature:
-* In your board's halconf.h: `#define HAL_USE_UART TRUE` and `#define UART_USE_WAIT TRUE`
-* In your board's mcuconf.h: `#define STM32_UART_USE_USARTn TRUE` (where 'n' matches the peripheral number of your selected USART on the MCU)
+You must also enable the ChibiOS `SERIAL` feature:
+* In your board's halconf.h: `#define HAL_USE_SERIAL TRUE`
+* In your board's mcuconf.h: `#define STM32_SERIAL_USE_USARTn TRUE` (where 'n' matches the peripheral number of your selected USART on the MCU)
-Do note that the configuration required is for the `UART` peripheral, not the `SERIAL` peripheral.
+Do note that the configuration required is for the `SERIAL` peripheral, not the `UART` peripheral.
#### Pins for USART Peripherals with Alternate Functions for selected STM32 MCUs
diff --git a/drivers/chibios/serial_usart.c b/drivers/chibios/serial_usart.c
index 9f180d2d74..ea4473791c 100644
--- a/drivers/chibios/serial_usart.c
+++ b/drivers/chibios/serial_usart.c
@@ -16,179 +16,300 @@
#include "serial_usart.h"
-#ifndef USE_GPIOV1
-// The default PAL alternate modes are used to signal that the pins are used for USART
-# ifndef SERIAL_USART_TX_PAL_MODE
-# define SERIAL_USART_TX_PAL_MODE 7
+#if defined(SERIAL_USART_CONFIG)
+static SerialConfig serial_config = SERIAL_USART_CONFIG;
+#else
+static SerialConfig serial_config = {
+ .speed = (SERIAL_USART_SPEED), /* speed - mandatory */
+ .cr1 = (SERIAL_USART_CR1),
+ .cr2 = (SERIAL_USART_CR2),
+# if !defined(SERIAL_USART_FULL_DUPLEX)
+ .cr3 = ((SERIAL_USART_CR3) | USART_CR3_HDSEL) /* activate half-duplex mode */
+# else
+ .cr3 = (SERIAL_USART_CR3)
# endif
+};
#endif
-#ifndef SERIAL_USART_DRIVER
-# define SERIAL_USART_DRIVER SD1
-#endif
-
-#ifdef SOFT_SERIAL_PIN
-# define SERIAL_USART_TX_PIN SOFT_SERIAL_PIN
-#endif
-
-static inline msg_t sdWriteHalfDuplex(SerialDriver* driver, uint8_t* data, uint8_t size) {
- msg_t ret = sdWrite(driver, data, size);
+static SerialDriver* serial_driver = &SERIAL_USART_DRIVER;
- // Half duplex requires us to read back the data we just wrote - just throw it away
- uint8_t dump[size];
- sdRead(driver, dump, size);
+static inline bool react_to_transactions(void);
+static inline bool __attribute__((nonnull)) receive(uint8_t* destination, const size_t size);
+static inline bool __attribute__((nonnull)) send(const uint8_t* source, const size_t size);
+static inline int initiate_transaction(uint8_t sstd_index);
+static inline void usart_clear(void);
- return ret;
+/**
+ * @brief Clear the receive input queue.
+ */
+static inline void usart_clear(void) {
+ osalSysLock();
+ bool volatile queue_not_empty = !iqIsEmptyI(&serial_driver->iqueue);
+ osalSysUnlock();
+
+ while (queue_not_empty) {
+ osalSysLock();
+ /* Hard reset the input queue. */
+ iqResetI(&serial_driver->iqueue);
+ osalSysUnlock();
+ /* Allow pending interrupts to preempt.
+ * Do not merge the lock/unlock blocks into one
+ * or the code will not work properly.
+ * The empty read adds a tiny amount of delay. */
+ (void)queue_not_empty;
+ osalSysLock();
+ queue_not_empty = !iqIsEmptyI(&serial_driver->iqueue);
+ osalSysUnlock();
+ }
}
-#undef sdWrite
-#define sdWrite sdWriteHalfDuplex
-
-static inline msg_t sdWriteTimeoutHalfDuplex(SerialDriver* driver, uint8_t* data, uint8_t size, uint32_t timeout) {
- msg_t ret = sdWriteTimeout(driver, data, size, timeout);
- // Half duplex requires us to read back the data we just wrote - just throw it away
- uint8_t dump[size];
- sdReadTimeout(driver, dump, size, timeout);
+/**
+ * @brief Blocking send of buffer with timeout.
+ *
+ * @return true Send success.
+ * @return false Send failed.
+ */
+static inline bool send(const uint8_t* source, const size_t size) {
+ bool success = (size_t)sdWriteTimeout(serial_driver, source, size, TIME_MS2I(SERIAL_USART_TIMEOUT)) == size;
+
+#if !defined(SERIAL_USART_FULL_DUPLEX)
+ if (success) {
+ /* Half duplex fills the input queue with the data we wrote - just throw it away.
+ Under the right circumstances (e.g. bad cables paired with high baud rates)
+ less bytes can be present in the input queue, therefore a timeout is needed. */
+ uint8_t dump[size];
+ return receive(dump, size);
+ }
+#endif
- return ret;
+ return success;
}
-#undef sdWriteTimeout
-#define sdWriteTimeout sdWriteTimeoutHalfDuplex
-static inline void sdClear(SerialDriver* driver) {
- while (sdGetTimeout(driver, TIME_IMMEDIATE) != MSG_TIMEOUT) {
- // Do nothing with the data
- }
+/**
+ * @brief Blocking receive of size * bytes with timeout.
+ *
+ * @return true Receive success.
+ * @return false Receive failed.
+ */
+static inline bool receive(uint8_t* destination, const size_t size) {
+ bool success = (size_t)sdReadTimeout(serial_driver, destination, size, TIME_MS2I(SERIAL_USART_TIMEOUT)) == size;
+ return success;
}
-static SerialConfig sdcfg = {
- (SERIAL_USART_SPEED), // speed - mandatory
- (SERIAL_USART_CR1), // CR1
- (SERIAL_USART_CR2), // CR2
- (SERIAL_USART_CR3) // CR3
-};
-
-void handle_soft_serial_slave(void);
+#if !defined(SERIAL_USART_FULL_DUPLEX)
-/*
- * This thread runs on the slave and responds to transactions initiated
- * by the master
+/**
+ * @brief Initiate pins for USART peripheral. Half-duplex configuration.
*/
-static THD_WORKING_AREA(waSlaveThread, 2048);
-static THD_FUNCTION(SlaveThread, arg) {
- (void)arg;
- chRegSetThreadName("slave_transport");
+__attribute__((weak)) void usart_init(void) {
+# if defined(MCU_STM32)
+# if defined(USE_GPIOV1)
+ palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
+# else
+ palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
+# endif
- while (true) {
- handle_soft_serial_slave();
- }
+# if defined(USART_REMAP)
+ USART_REMAP;
+# endif
+# else
+# pragma message "usart_init: MCU Familiy not supported by default, please supply your own init code by implementing usart_init() in your keyboard files."
+# endif
}
-__attribute__((weak)) void usart_init(void) {
-#if defined(USE_GPIOV1)
- palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
#else
- palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
-#endif
-#if defined(USART_REMAP)
+/**
+ * @brief Initiate pins for USART peripheral. Full-duplex configuration.
+ */
+__attribute__((weak)) void usart_init(void) {
+# if defined(MCU_STM32)
+# if defined(USE_GPIOV1)
+ palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
+ palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);
+# else
+ palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
+ palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_RX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
+# endif
+
+# if defined(USART_REMAP)
USART_REMAP;
+# endif
+# else
+# pragma message "usart_init: MCU Familiy not supported by default, please supply your own init code by implementing usart_init() in your keyboard files."
+# endif
+}
+
#endif
+
+/**
+ * @brief Overridable master specific initializations.
+ */
+__attribute__((weak, nonnull)) void usart_master_init(SerialDriver** driver) {
+ (void)driver;
+ usart_init();
}
-void usart_master_init(void) {
+/**
+ * @brief Overridable slave specific initializations.
+ */
+__attribute__((weak, nonnull)) void usart_slave_init(SerialDriver** driver) {
+ (void)driver;
usart_init();
+}
+
+/**
+ * @brief This thread runs on the slave and responds to transactions initiated
+ * by the master.
+ */
+static THD_WORKING_AREA(waSlaveThread, 1024);
+static THD_FUNCTION(SlaveThread, arg) {
+ (void)arg;
+ chRegSetThreadName("usart_tx_rx");
- sdcfg.cr3 |= USART_CR3_HDSEL;
- sdStart(&SERIAL_USART_DRIVER, &sdcfg);
+ while (true) {
+ if (!react_to_transactions()) {
+ /* Clear the receive queue, to start with a clean slate.
+ * Parts of failed transactions or spurious bytes could still be in it. */
+ usart_clear();
+ }
+ }
}
-void usart_slave_init(void) {
- usart_init();
+/**
+ * @brief Slave specific initializations.
+ */
+void soft_serial_target_init(void) {
+ usart_slave_init(&serial_driver);
- sdcfg.cr3 |= USART_CR3_HDSEL;
- sdStart(&SERIAL_USART_DRIVER, &sdcfg);
+ sdStart(serial_driver, &serial_config);
- // Start transport thread
+ /* Start transport thread. */
chThdCreateStatic(waSlaveThread, sizeof(waSlaveThread), HIGHPRIO, SlaveThread, NULL);
}
-void soft_serial_initiator_init(void) { usart_master_init(); }
+/**
+ * @brief React to transactions started by the master.
+ */
+static inline bool react_to_transactions(void) {
+ /* Wait until there is a transaction for us. */
+ uint8_t sstd_index = (uint8_t)sdGet(serial_driver);
-void soft_serial_target_init(void) { usart_slave_init(); }
+ /* Sanity check that we are actually responding to a valid transaction. */
+ if (sstd_index >= NUM_TOTAL_TRANSACTIONS) {
+ return false;
+ }
-void handle_soft_serial_slave(void) {
- uint8_t sstd_index = sdGet(&SERIAL_USART_DRIVER); // first chunk is always transaction id
- split_transaction_desc_t* trans = &split_transaction_table[sstd_index];
+ split_transaction_desc_t* trans = &split_transaction_table[sstd_index];
- // Always write back the sstd_index as part of a basic handshake
+ /* Send back the handshake which is XORed as a simple checksum,
+ to signal that the slave is ready to receive possible transaction buffers */
sstd_index ^= HANDSHAKE_MAGIC;
- sdWrite(&SERIAL_USART_DRIVER, &sstd_index, sizeof(sstd_index));
+ if (!send(&sstd_index, sizeof(sstd_index))) {
+ *trans->status = TRANSACTION_DATA_ERROR;
+ return false;
+ }
+ /* Receive transaction buffer from the master. If this transaction requires it.*/
if (trans->initiator2target_buffer_size) {
- sdRead(&SERIAL_USART_DRIVER, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size);
+ if (!receive(split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
+ *trans->status = TRANSACTION_DATA_ERROR;
+ return false;
+ }
}
- // Allow any slave processing to occur
+ /* Allow any slave processing to occur. */
if (trans->slave_callback) {
- trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
+ trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, split_trans_target2initiator_buffer(trans));
}
+ /* Send transaction buffer to the master. If this transaction requires it. */
if (trans->target2initiator_buffer_size) {
- sdWrite(&SERIAL_USART_DRIVER, split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size);
+ if (!send(split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
+ *trans->status = TRANSACTION_DATA_ERROR;
+ return false;
+ }
}
- if (trans->status) {
- *trans->status = TRANSACTION_ACCEPTED;
- }
+ *trans->status = TRANSACTION_ACCEPTED;
+ return true;
+}
+
+/**
+ * @brief Master specific initializations.
+ */
+void soft_serial_initiator_init(void) {
+ usart_master_init(&serial_driver);
+
+#if defined(MCU_STM32) && defined(SERIAL_USART_PIN_SWAP)
+ serial_config.cr2 |= USART_CR2_SWAP; // master has swapped TX/RX pins
+#endif
+
+ sdStart(serial_driver, &serial_config);
}
-/////////
-// start transaction by initiator
-//
-// int soft_serial_transaction(int sstd_index)
-//
-// Returns:
-// TRANSACTION_END
-// TRANSACTION_NO_RESPONSE
-// TRANSACTION_DATA_ERROR
+/**
+ * @brief Start transaction from the master half to the slave half.
+ *
+ * @param index Transaction Table index of the transaction to start.
+ * @return int TRANSACTION_NO_RESPONSE in case of Timeout.
+ * TRANSACTION_TYPE_ERROR in case of invalid transaction index.
+ * TRANSACTION_END in case of success.
+ */
int soft_serial_transaction(int index) {
- uint8_t sstd_index = index;
+ /* Clear the receive queue, to start with a clean slate.
+ * Parts of failed transactions or spurious bytes could still be in it. */
+ usart_clear();
+ return initiate_transaction((uint8_t)index);
+}
- if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
- split_transaction_desc_t* trans = &split_transaction_table[sstd_index];
- msg_t res = 0;
+/**
+ * @brief Initiate transaction to slave half.
+ */
+static inline int initiate_transaction(uint8_t sstd_index) {
+ /* Sanity check that we are actually starting a valid transaction. */
+ if (sstd_index >= NUM_TOTAL_TRANSACTIONS) {
+ dprintln("USART: Illegal transaction Id.");
+ return TRANSACTION_TYPE_ERROR;
+ }
- if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
+ split_transaction_desc_t* trans = &split_transaction_table[sstd_index];
- sdClear(&SERIAL_USART_DRIVER);
+ /* Transaction is not registered. Abort. */
+ if (!trans->status) {
+ dprintln("USART: Transaction not registered.");
+ return TRANSACTION_TYPE_ERROR;
+ }
- // First chunk is always transaction id
- sdWriteTimeout(&SERIAL_USART_DRIVER, &sstd_index, sizeof(sstd_index), TIME_MS2I(SERIAL_USART_TIMEOUT));
+ /* Send transaction table index to the slave, which doubles as basic handshake token. */
+ if (!send(&sstd_index, sizeof(sstd_index))) {
+ dprintln("USART: Send Handshake failed.");
+ return TRANSACTION_TYPE_ERROR;
+ }
uint8_t sstd_index_shake = 0xFF;
- // Which we always read back first so that we can error out correctly
- // - due to the half duplex limitations on return codes, we always have to read *something*
- // - without the read, write only transactions *always* succeed, even during the boot process where the slave is not ready
- res = sdReadTimeout(&SERIAL_USART_DRIVER, &sstd_index_shake, sizeof(sstd_index_shake), TIME_MS2I(SERIAL_USART_TIMEOUT));
- if (res < 0 || (sstd_index_shake != (sstd_index ^ HANDSHAKE_MAGIC))) {
- dprintf("serial::usart_shake NO_RESPONSE\n");
+ /* Which we always read back first so that we can error out correctly.
+ * - due to the half duplex limitations on return codes, we always have to read *something*.
+ * - without the read, write only transactions *always* succeed, even during the boot process where the slave is not ready.
+ */
+ if (!receive(&sstd_index_shake, sizeof(sstd_index_shake)) || (sstd_index_shake != (sstd_index ^ HANDSHAKE_MAGIC))) {
+ dprintln("USART: Handshake failed.");
return TRANSACTION_NO_RESPONSE;
}
+ /* Send transaction buffer to the slave. If this transaction requires it. */
if (trans->initiator2target_buffer_size) {
- res = sdWriteTimeout(&SERIAL_USART_DRIVER, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, TIME_MS2I(SERIAL_USART_TIMEOUT));
- if (res < 0) {
- dprintf("serial::usart_transmit NO_RESPONSE\n");
+ if (!send(split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
+ dprintln("USART: Send failed.");
return TRANSACTION_NO_RESPONSE;
}
}
+ /* Receive transaction buffer from the slave. If this transaction requires it. */
if (trans->target2initiator_buffer_size) {
- res = sdReadTimeout(&SERIAL_USART_DRIVER, split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size, TIME_MS2I(SERIAL_USART_TIMEOUT));
- if (res < 0) {
- dprintf("serial::usart_receive NO_RESPONSE\n");
+ if (!receive(split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
+ dprintln("USART: Receive failed.");
return TRANSACTION_NO_RESPONSE;
}
}
diff --git a/drivers/chibios/serial_usart.h b/drivers/chibios/serial_usart.h
index fee7b4d159..c64e15566f 100644
--- a/drivers/chibios/serial_usart.h
+++ b/drivers/chibios/serial_usart.h
@@ -23,19 +23,45 @@
#include
#include
-#ifndef USART_CR1_M0
+#if !defined(SERIAL_USART_DRIVER)
+# define SERIAL_USART_DRIVER SD1
+#endif
+
+#if !defined(USE_GPIOV1)
+/* The default PAL alternate modes are used to signal that the pins are used for USART. */
+# if !defined(SERIAL_USART_TX_PAL_MODE)
+# define SERIAL_USART_TX_PAL_MODE 7
+# endif
+# if !defined(SERIAL_USART_RX_PAL_MODE)
+# define SERIAL_USART_RX_PAL_MODE 7
+# endif
+#endif
+
+#if defined(SOFT_SERIAL_PIN)
+# define SERIAL_USART_TX_PIN SOFT_SERIAL_PIN
+#endif
+
+#if !defined(SERIAL_USART_TX_PIN)
+# define SERIAL_USART_TX_PIN A9
+#endif
+
+#if !defined(SERIAL_USART_RX_PIN)
+# define SERIAL_USART_RX_PIN A10
+#endif
+
+#if !defined(USART_CR1_M0)
# define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so
#endif
-#ifndef SERIAL_USART_CR1
+#if !defined(SERIAL_USART_CR1)
# define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length
#endif
-#ifndef SERIAL_USART_CR2
+#if !defined(SERIAL_USART_CR2)
# define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits
#endif
-#ifndef SERIAL_USART_CR3
+#if !defined(SERIAL_USART_CR3)
# define SERIAL_USART_CR3 0
#endif
@@ -61,11 +87,11 @@
} while (0)
#endif
-#ifndef SELECT_SOFT_SERIAL_SPEED
+#if !defined(SELECT_SOFT_SERIAL_SPEED)
# define SELECT_SOFT_SERIAL_SPEED 1
#endif
-#ifdef SERIAL_USART_SPEED
+#if defined(SERIAL_USART_SPEED)
// Allow advanced users to directly set SERIAL_USART_SPEED
#elif SELECT_SOFT_SERIAL_SPEED == 0
# define SERIAL_USART_SPEED 460800
@@ -83,7 +109,7 @@
# error invalid SELECT_SOFT_SERIAL_SPEED value
#endif
-#ifndef SERIAL_USART_TIMEOUT
+#if !defined(SERIAL_USART_TIMEOUT)
# define SERIAL_USART_TIMEOUT 100
#endif
diff --git a/drivers/chibios/serial_usart_duplex.c b/drivers/chibios/serial_usart_duplex.c
deleted file mode 100644
index cc9b889ac2..0000000000
--- a/drivers/chibios/serial_usart_duplex.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/* Copyright 2021 QMK
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "serial_usart.h"
-
-#include
-
-#if !defined(USE_GPIOV1)
-// The default PAL alternate modes are used to signal that the pins are used for USART
-# if !defined(SERIAL_USART_TX_PAL_MODE)
-# define SERIAL_USART_TX_PAL_MODE 7
-# endif
-# if !defined(SERIAL_USART_RX_PAL_MODE)
-# define SERIAL_USART_RX_PAL_MODE 7
-# endif
-#endif
-
-#if !defined(SERIAL_USART_DRIVER)
-# define SERIAL_USART_DRIVER UARTD1
-#endif
-
-#if !defined(SERIAL_USART_TX_PIN)
-# define SERIAL_USART_TX_PIN A9
-#endif
-
-#if !defined(SERIAL_USART_RX_PIN)
-# define SERIAL_USART_RX_PIN A10
-#endif
-
-#define SIGNAL_HANDSHAKE_RECEIVED 0x1
-
-void handle_transactions_slave(uint8_t sstd_index);
-static void receive_transaction_handshake(UARTDriver* uartp, uint16_t received_handshake);
-
-/*
- * UART driver configuration structure. We use the blocking DMA enabled API and
- * the rxchar callback to receive handshake tokens but only on the slave halve.
- */
-// clang-format off
-static UARTConfig uart_config = {
- .txend1_cb = NULL,
- .txend2_cb = NULL,
- .rxend_cb = NULL,
- .rxchar_cb = NULL,
- .rxerr_cb = NULL,
- .timeout_cb = NULL,
- .speed = (SERIAL_USART_SPEED),
- .cr1 = (SERIAL_USART_CR1),
- .cr2 = (SERIAL_USART_CR2),
- .cr3 = (SERIAL_USART_CR3)
-};
-// clang-format on
-
-static SSTD_t* Transaction_table = NULL;
-static uint8_t Transaction_table_size = 0;
-static atomic_uint_least8_t handshake = 0xFF;
-static thread_reference_t tp_target = NULL;
-
-/*
- * This callback is invoked when a character is received but the application
- * was not ready to receive it, the character is passed as parameter.
- * Receive transaction table index from initiator, which doubles as basic handshake token. */
-static void receive_transaction_handshake(UARTDriver* uartp, uint16_t received_handshake) {
- /* Check if received handshake is not a valid transaction id.
- * Please note that we can still catch a seemingly valid handshake
- * i.e. a byte from a ongoing transfer which is in the allowed range.
- * So this check mainly prevents any obviously wrong handshakes and
- * subsequent wakeups of the receiving thread, which is a costly operation. */
- if (received_handshake > Transaction_table_size) {
- return;
- }
-
- handshake = (uint8_t)received_handshake;
- chSysLockFromISR();
- /* Wakeup receiving thread to start a transaction. */
- chEvtSignalI(tp_target, (eventmask_t)SIGNAL_HANDSHAKE_RECEIVED);
- chSysUnlockFromISR();
-}
-
-__attribute__((weak)) void usart_init(void) {
-#if defined(USE_GPIOV1)
- palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
- palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);
-#else
- palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
- palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_RX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
-#endif
-}
-
-/*
- * This thread runs on the slave half and reacts to transactions initiated from the master.
- */
-static THD_WORKING_AREA(waSlaveThread, 1024);
-static THD_FUNCTION(SlaveThread, arg) {
- (void)arg;
- chRegSetThreadName("slave_usart_tx_rx");
-
- while (true) {
- /* We sleep as long as there is no handshake waiting for us. */
- chEvtWaitAny((eventmask_t)SIGNAL_HANDSHAKE_RECEIVED);
- handle_transactions_slave(handshake);
- }
-}
-
-void soft_serial_target_init(SSTD_t* const sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
- usart_init();
-
-#if defined(USART_REMAP)
- USART_REMAP;
-#endif
-
- tp_target = chThdCreateStatic(waSlaveThread, sizeof(waSlaveThread), HIGHPRIO, SlaveThread, NULL);
-
- // Start receiving handshake tokens on slave halve
- uart_config.rxchar_cb = receive_transaction_handshake;
- uartStart(&SERIAL_USART_DRIVER, &uart_config);
-}
-
-/**
- * @brief React to transactions started by the master.
- * This version uses duplex send and receive usart pheriphals and DMA backed transfers.
- */
-void inline handle_transactions_slave(uint8_t sstd_index) {
- size_t buffer_size = 0;
- msg_t msg = 0;
- SSTD_t* trans = &Transaction_table[sstd_index];
-
- /* Send back the handshake which is XORed as a simple checksum,
- to signal that the slave is ready to receive possible transaction buffers */
- sstd_index ^= HANDSHAKE_MAGIC;
- buffer_size = (size_t)sizeof(sstd_index);
- msg = uartSendTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index, TIME_MS2I(SERIAL_USART_TIMEOUT));
-
- if (msg != MSG_OK) {
- if (trans->status) {
- *trans->status = TRANSACTION_NO_RESPONSE;
- }
- return;
- }
-
- /* Receive transaction buffer from the master. If this transaction requires it.*/
- buffer_size = (size_t)trans->initiator2target_buffer_size;
- if (buffer_size) {
- msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->initiator2target_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
- if (msg != MSG_OK) {
- if (trans->status) {
- *trans->status = TRANSACTION_NO_RESPONSE;
- }
- return;
- }
- }
-
- /* Send transaction buffer to the master. If this transaction requires it. */
- buffer_size = (size_t)trans->target2initiator_buffer_size;
- if (buffer_size) {
- msg = uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->target2initiator_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
- if (msg != MSG_OK) {
- if (trans->status) {
- *trans->status = TRANSACTION_NO_RESPONSE;
- }
- return;
- }
- }
-
- if (trans->status) {
- *trans->status = TRANSACTION_ACCEPTED;
- }
-}
-
-void soft_serial_initiator_init(SSTD_t* const sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
- usart_init();
-
-#if defined(SERIAL_USART_PIN_SWAP)
- uart_config.cr2 |= USART_CR2_SWAP; // master has swapped TX/RX pins
-#endif
-
-#if defined(USART_REMAP)
- USART_REMAP;
-#endif
-
- uartStart(&SERIAL_USART_DRIVER, &uart_config);
-}
-
-/**
- * @brief Start transaction from the master to the slave.
- * This version uses duplex send and receive usart pheriphals and DMA backed transfers.
- *
- * @param index Transaction Table index of the transaction to start.
- * @return int TRANSACTION_NO_RESPONSE in case of Timeout.
- * TRANSACTION_TYPE_ERROR in case of invalid transaction index.
- * TRANSACTION_END in case of success.
- */
-#if !defined(SERIAL_USE_MULTI_TRANSACTION)
-int soft_serial_transaction(void) {
- uint8_t sstd_index = 0;
-#else
-int soft_serial_transaction(int index) {
- uint8_t sstd_index = index;
-#endif
-
- if (sstd_index > Transaction_table_size) {
- return TRANSACTION_TYPE_ERROR;
- }
-
- SSTD_t* const trans = &Transaction_table[sstd_index];
- msg_t msg = 0;
- size_t buffer_size = (size_t)sizeof(sstd_index);
-
- /* Send transaction table index to the slave, which doubles as basic handshake token. */
- uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index, TIME_MS2I(SERIAL_USART_TIMEOUT));
-
- uint8_t sstd_index_shake = 0xFF;
- buffer_size = (size_t)sizeof(sstd_index_shake);
-
- /* Receive the handshake token from the slave. The token was XORed by the slave as a simple checksum.
- If the tokens match, the master will start to send and receive possible transaction buffers. */
- msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, &sstd_index_shake, TIME_MS2I(SERIAL_USART_TIMEOUT));
- if (msg != MSG_OK || (sstd_index_shake != (sstd_index ^ HANDSHAKE_MAGIC))) {
- dprintln("USART: Handshake Failed");
- return TRANSACTION_NO_RESPONSE;
- }
-
- /* Send transaction buffer to the slave. If this transaction requires it. */
- buffer_size = (size_t)trans->initiator2target_buffer_size;
- if (buffer_size) {
- msg = uartSendFullTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->initiator2target_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
- if (msg != MSG_OK) {
- dprintln("USART: Send Failed");
- return TRANSACTION_NO_RESPONSE;
- }
- }
-
- /* Receive transaction buffer from the slave. If this transaction requires it. */
- buffer_size = (size_t)trans->target2initiator_buffer_size;
- if (buffer_size) {
- msg = uartReceiveTimeout(&SERIAL_USART_DRIVER, &buffer_size, trans->target2initiator_buffer, TIME_MS2I(SERIAL_USART_TIMEOUT));
- if (msg != MSG_OK) {
- dprintln("USART: Receive Failed");
- return TRANSACTION_NO_RESPONSE;
- }
- }
-
- return TRANSACTION_END;
-}
diff --git a/platforms/chibios/QMK_PROTON_C/configs/halconf.h b/platforms/chibios/QMK_PROTON_C/configs/halconf.h
index 41fbac29e0..d7a639a6d0 100644
--- a/platforms/chibios/QMK_PROTON_C/configs/halconf.h
+++ b/platforms/chibios/QMK_PROTON_C/configs/halconf.h
@@ -412,7 +412,7 @@
* buffers.
*/
#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_BUFFERS_SIZE 16
+#define SERIAL_BUFFERS_SIZE 128
#endif
/*===========================================================================*/
diff --git a/platforms/chibios/common/configs/halconf.h b/platforms/chibios/common/configs/halconf.h
index 264ae4e6c1..c80f67ee27 100644
--- a/platforms/chibios/common/configs/halconf.h
+++ b/platforms/chibios/common/configs/halconf.h
@@ -412,7 +412,7 @@
* buffers.
*/
#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_BUFFERS_SIZE 16
+#define SERIAL_BUFFERS_SIZE 128
#endif
/*===========================================================================*/
--
cgit v1.2.3
From 6ac037aa3ccd2937bab3dbcc5108001534765e38 Mon Sep 17 00:00:00 2001
From: Gigahawk
Date: Sat, 3 Jul 2021 08:01:23 -0700
Subject: AW20216 use register increment for framebuffer flushes (#13430)
---
drivers/awinic/aw20216.c | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
(limited to 'drivers')
diff --git a/drivers/awinic/aw20216.c b/drivers/awinic/aw20216.c
index 269bb3a59a..776653fa6c 100644
--- a/drivers/awinic/aw20216.c
+++ b/drivers/awinic/aw20216.c
@@ -43,6 +43,10 @@
#define AW_CONFIG_DEFAULT 0b10110000
#define AW_CHIPEN 1
+#define AW_PWM_REGISTER_COUNT 216
+
+#define AW_SPI_START(PIN) spi_start(PIN, false, 0, AW_SPI_DIVISOR)
+
#ifndef AW_SCALING_MAX
# define AW_SCALING_MAX 150
#endif
@@ -63,13 +67,13 @@
# define AW_SPI_DIVISOR 4
#endif
-uint8_t g_spi_transfer_buffer[20] = {0};
-aw_led g_pwm_buffer[DRIVER_LED_TOTAL];
-bool g_pwm_buffer_update_required[DRIVER_LED_TOTAL];
+uint8_t g_spi_transfer_buffer[3] = {0};
+uint8_t g_pwm_buffer[DRIVER_COUNT][AW_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
bool AW20216_write_register(pin_t slave_pin, uint8_t page, uint8_t reg, uint8_t data) {
// Do we need to call spi_stop() if this fails?
- if (!spi_start(slave_pin, false, 0, AW_SPI_DIVISOR)) {
+ if (!AW_SPI_START(slave_pin)) {
return false;
}
@@ -147,10 +151,11 @@ void AW20216_init(void) {
}
void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- g_pwm_buffer[index].r = red;
- g_pwm_buffer[index].g = green;
- g_pwm_buffer[index].b = blue;
- g_pwm_buffer_update_required[index] = true;
+ aw_led led = g_aw_leds[index];
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ g_pwm_buffer_update_required[led.driver] = true;
return;
}
void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
@@ -159,12 +164,19 @@ void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
}
return;
}
+
+void AW20216_write_pwm_buffer(pin_t slave_pin, uint8_t buffer_idx) {
+ AW_SPI_START(slave_pin);
+ spi_write((AWINIC_ID | AW_PAGE_PWM | AW_WRITE));
+ spi_write(0);
+ spi_transmit(g_pwm_buffer[buffer_idx], AW_PWM_REGISTER_COUNT);
+ spi_stop();
+}
+
void AW20216_update_pwm_buffers(void) {
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- if (g_pwm_buffer_update_required[i]) {
- AW20216_update_pwm(i, g_pwm_buffer[i].r, g_pwm_buffer[i].g, g_pwm_buffer[i].b);
- g_pwm_buffer_update_required[i] = false;
- }
- }
+ AW20216_write_pwm_buffer(DRIVER_1_CS, 0);
+#ifdef DRIVER_2_CS
+ AW20216_write_pwm_buffer(DRIVER_2_CS, 1);
+#endif
return;
}
--
cgit v1.2.3
From 9c74fd14bc9777ec45cc93fa57bf83ab17b988db Mon Sep 17 00:00:00 2001
From: Chris Cullin
Date: Tue, 13 Jul 2021 01:51:23 +1000
Subject: Enable g_is31_leds PROGMEM for RGB Matrix IS31FL3737 driver (#13480)
---
docs/feature_rgb_matrix.md | 2 +-
drivers/issi/is31fl3737.c | 9 +++++++--
keyboards/mt84/mt84.c | 40 ++++++++++++++++++++--------------------
keyboards/planck/ez/ez.c | 2 +-
tmk_core/common/progmem.h | 1 +
5 files changed, 30 insertions(+), 24 deletions(-)
(limited to 'drivers')
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index 675b7a1be0..be763ee025 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -171,7 +171,7 @@ Currently only a single drivers is supported, but it would be trivial to support
Define these arrays listing all the LEDs in your `.c`:
```c
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/drivers/issi/is31fl3737.c b/drivers/issi/is31fl3737.c
index 8647c93cc1..e40bfa0d79 100644
--- a/drivers/issi/is31fl3737.c
+++ b/drivers/issi/is31fl3737.c
@@ -19,6 +19,7 @@
#include "is31fl3737.h"
#include "i2c_master.h"
#include "wait.h"
+#include "progmem.h"
// This is a 7-bit address, that gets left-shifted and bit 0
// set to 0 for write, 1 for read (as per I2C protocol)
@@ -153,7 +154,9 @@ void IS31FL3737_init(uint8_t addr) {
void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index >= 0 && index < DRIVER_LED_TOTAL) {
- is31_led led = g_is31_leds[index];
+ // copy the led config from progmem to SRAM
+ is31_led led;
+ memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
@@ -169,7 +172,9 @@ void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
}
void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
- is31_led led = g_is31_leds[index];
+ // copy the led config from progmem to SRAM
+ is31_led led;
+ memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
uint8_t control_register_r = led.r / 8;
uint8_t control_register_g = led.g / 8;
diff --git a/keyboards/mt84/mt84.c b/keyboards/mt84/mt84.c
index d9f509e14d..e15a1ff951 100644
--- a/keyboards/mt84/mt84.c
+++ b/keyboards/mt84/mt84.c
@@ -1,22 +1,22 @@
- /* Copyright 2020 MT<704340378@qq.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
+ /* Copyright 2020 MT<704340378@qq.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
#include "mt84.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -40,7 +40,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
{1, D_12, E_12, F_12},
{1, G_12, H_12, I_12},
{1, J_12, K_12, L_12},
-
+
{0, A_1, B_1, C_1},
{0, D_1, E_1, F_1},
{0, G_1, H_1, I_1},
@@ -72,7 +72,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
{1, A_7, B_7, C_7},
{1, D_7, E_7, F_7},
{1, G_7, H_7, I_7},
-
+
{0, A_3, B_3, C_3},
{0, D_3, E_3, F_3},
{0, G_3, H_3, I_3},
@@ -87,7 +87,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
{1, J_3, K_3, L_3},
{1, A_8, B_8, C_8},
{1, G_8, H_8, I_8},
-
+
{0, A_4, B_4, C_4},
{0, D_4, E_4, F_4},
{0, G_4, H_4, I_4},
@@ -130,7 +130,7 @@ led_config_t g_led_config = {{
{ 9, 52 }, { 27, 52 }, { 43, 52 }, { 59, 52 }, { 75, 52 }, { 91, 52 }, { 107, 52 }, { 123, 52 }, { 139, 52 }, { 155, 52 }, { 171, 52 }, { 187, 52 }, { 212, 52 }, { 224, 52 },
{ 2, 64 }, { 18, 64 }, { 33, 64 }, { 93, 64 }, { 150, 64 }, { 165, 64 }, { 180, 64 }, { 195, 64 }, { 210, 64 }, { 224, 64 }
}, {
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c
index 8c498a5520..818dc66587 100644
--- a/keyboards/planck/ez/ez.c
+++ b/keyboards/planck/ez/ez.c
@@ -19,7 +19,7 @@
keyboard_config_t keyboard_config;
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h
index 4e4771e523..3a7a169682 100644
--- a/tmk_core/common/progmem.h
+++ b/tmk_core/common/progmem.h
@@ -3,6 +3,7 @@
#if defined(__AVR__)
# include
#else
+# include
# define PROGMEM
# define PSTR(x) x
# define PGM_P const char*
--
cgit v1.2.3
From 70267b35c357f2744262300db03eafe642159734 Mon Sep 17 00:00:00 2001
From: Chris Cullin
Date: Fri, 16 Jul 2021 07:52:05 +1000
Subject: Dual RGB Matrix IS31FL3737 driver support to address #13442 (#13457)
* initial commit
* removed changes to write_pwm_buffer
* backward compatbility added
* fixed issue with backward compatibility
* documentation update
* removed unneccessary comment. branched from master
* updated per comments #13457
* removed blank line
* cformat on diff files---
docs/feature_rgb_matrix.md | 25 +++++++++++++++----
drivers/issi/is31fl3737.c | 43 ++++++++++++++++-----------------
quantum/rgb_matrix/rgb_matrix_drivers.c | 15 ++++++++++--
3 files changed, 54 insertions(+), 29 deletions(-)
(limited to 'drivers')
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index be763ee025..f3e25f2f13 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -145,9 +145,22 @@ There is basic support for addressable RGB matrix lighting with the I2C IS31FL37
RGB_MATRIX_ENABLE = yes
RGB_MATRIX_DRIVER = IS31FL3737
```
+You can use between 1 and 2 IS31FL3737 IC's. Do not specify `DRIVER_ADDR_2` define for second IC if not present on your keyboard.
Configure the hardware via your `config.h`:
+| Variable | Description | Default |
+|----------|-------------|---------|
+| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 |
+| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
+| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | |
+| `DRIVER_LED_TOTAL` | (Required) How many RGB lights are present across all drivers | |
+| `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | |
+| `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | |
+
+
+Here is an example using 2 drivers.
+
```c
// This is a 7-bit address, that gets left-shifted and bit 0
// set to 0 for write, 1 for read (as per I2C protocol)
@@ -159,14 +172,16 @@ Configure the hardware via your `config.h`:
// ADDR represents A3:A0 of the 7-bit address.
// The result is: 0b101(ADDR)
#define DRIVER_ADDR_1 0b1010000
-#define DRIVER_ADDR_2 0b1010000 // this is here for compliancy reasons.
+#define DRIVER_ADDR_2 0b1010001
#define DRIVER_COUNT 2
-#define DRIVER_1_LED_TOTAL 64
-#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL
+#define DRIVER_1_LED_TOTAL 30
+#define DRIVER_2_LED_TOTAL 36
+#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
```
+!> Note the parentheses, this is so when `DRIVER_LED_TOTAL` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`.
-Currently only a single drivers is supported, but it would be trivial to support all 4 combinations. For now define `DRIVER_ADDR_2` as `DRIVER_ADDR_1`
+Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations.
Define these arrays listing all the LEDs in your `.c`:
@@ -183,7 +198,7 @@ const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
}
```
-Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3737.pdf) and the header file `drivers/issi/is31fl3737.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now).
+Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3737.pdf) and the header file `drivers/issi/is31fl3737.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0`, `1` for now).
---
diff --git a/drivers/issi/is31fl3737.c b/drivers/issi/is31fl3737.c
index e40bfa0d79..30906b4840 100644
--- a/drivers/issi/is31fl3737.c
+++ b/drivers/issi/is31fl3737.c
@@ -66,11 +66,12 @@ uint8_t g_twi_transfer_buffer[20];
// We could optimize this and take out the unused registers from these
// buffers and the transfers in IS31FL3737_write_pwm_buffer() but it's
// probably not worth the extra complexity.
+
uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required = false;
+bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}};
-bool g_led_control_registers_update_required = false;
+uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
+bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
@@ -158,10 +159,10 @@ void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
is31_led led;
memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
- g_pwm_buffer[led.driver][led.r] = red;
- g_pwm_buffer[led.driver][led.g] = green;
- g_pwm_buffer[led.driver][led.b] = blue;
- g_pwm_buffer_update_required = true;
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ g_pwm_buffer_update_required[led.driver] = true;
}
}
@@ -199,30 +200,28 @@ void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bo
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
}
- g_led_control_registers_update_required = true;
+ g_led_control_registers_update_required[led.driver] = true;
}
-void IS31FL3737_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
- if (g_pwm_buffer_update_required) {
+void IS31FL3737_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
// Firstly we need to unlock the command register and select PG1
- IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
- IS31FL3737_write_pwm_buffer(addr1, g_pwm_buffer[0]);
- // IS31FL3737_write_pwm_buffer(addr2, g_pwm_buffer[1]);
+ IS31FL3737_write_pwm_buffer(addr, g_pwm_buffer[index]);
}
- g_pwm_buffer_update_required = false;
+ g_pwm_buffer_update_required[index] = false;
}
-void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2) {
- if (g_led_control_registers_update_required) {
+void IS31FL3737_update_led_control_registers(uint8_t addr, uint8_t index) {
+ if (g_led_control_registers_update_required[index]) {
// Firstly we need to unlock the command register and select PG0
- IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
for (int i = 0; i < 24; i++) {
- IS31FL3737_write_register(addr1, i, g_led_control_registers[0][i]);
- // IS31FL3737_write_register(addr2, i, g_led_control_registers[1][i]);
+ IS31FL3737_write_register(addr, i, g_led_control_registers[index][i]);
}
- g_led_control_registers_update_required = false;
}
+ g_led_control_registers_update_required[index] = false;
}
diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c
index 6a11d4791e..dfdf452190 100644
--- a/quantum/rgb_matrix/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix/rgb_matrix_drivers.c
@@ -65,6 +65,9 @@ static void init(void) {
# endif
# elif defined(IS31FL3737)
IS31FL3737_init(DRIVER_ADDR_1);
+# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
+ IS31FL3737_init(DRIVER_ADDR_2);
+# endif
# else
IS31FL3741_init(DRIVER_ADDR_1);
# endif
@@ -105,7 +108,10 @@ static void init(void) {
IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3);
# endif
# elif defined(IS31FL3737)
- IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
+ IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, 0);
+# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
+ IS31FL3737_update_led_control_registers(DRIVER_ADDR_2, 1);
+# endif
# else
IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0);
# endif
@@ -152,7 +158,12 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
.set_color_all = IS31FL3733_set_color_all,
};
# elif defined(IS31FL3737)
-static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
+static void flush(void) {
+ IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, 0);
+# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
+ IS31FL3737_update_pwm_buffers(DRIVER_ADDR_2, 1);
+# endif
+}
const rgb_matrix_driver_t rgb_matrix_driver = {
.init = init,
--
cgit v1.2.3
From f945c352e7db3fedb16c90f9f176b3df6e0b62ae Mon Sep 17 00:00:00 2001
From: Joel Challis
Date: Mon, 26 Jul 2021 03:14:58 +0100
Subject: Haptic: driver-> feature (#13713)
---
common_features.mk | 3 +-
drivers/haptic/haptic.c | 422 -------------------------------
drivers/haptic/haptic.h | 81 ------
quantum/haptic.c | 295 +++++++++++++++++++++
quantum/haptic.h | 77 ++++++
quantum/process_keycode/process_haptic.c | 147 +++++++++++
quantum/process_keycode/process_haptic.h | 21 ++
quantum/quantum.c | 4 +-
quantum/quantum.h | 1 +
9 files changed, 545 insertions(+), 506 deletions(-)
delete mode 100644 drivers/haptic/haptic.c
delete mode 100644 drivers/haptic/haptic.h
create mode 100644 quantum/haptic.c
create mode 100644 quantum/haptic.h
create mode 100644 quantum/process_keycode/process_haptic.c
create mode 100644 quantum/process_keycode/process_haptic.h
(limited to 'drivers')
diff --git a/common_features.mk b/common_features.mk
index f1414b4d09..a4991b05b0 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -580,8 +580,9 @@ endif
HAPTIC_ENABLE ?= no
ifneq ($(strip $(HAPTIC_ENABLE)),no)
COMMON_VPATH += $(DRIVER_PATH)/haptic
- SRC += haptic.c
OPT_DEFS += -DHAPTIC_ENABLE
+ SRC += $(QUANTUM_DIR)/haptic.c
+ SRC += $(QUANTUM_DIR)/process_keycode/process_haptic.c
endif
ifneq ($(filter DRV2605L, $(HAPTIC_ENABLE)), )
diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c
deleted file mode 100644
index 3fab1be1ae..0000000000
--- a/drivers/haptic/haptic.c
+++ /dev/null
@@ -1,422 +0,0 @@
-/* Copyright 2019 ishtob
- * Driver for haptic feedback written for QMK
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-#include "haptic.h"
-#include "eeconfig.h"
-#include "progmem.h"
-#include "debug.h"
-#ifdef DRV2605L
-# include "DRV2605L.h"
-#endif
-#ifdef SOLENOID_ENABLE
-# include "solenoid.h"
-#endif
-
-haptic_config_t haptic_config;
-
-void haptic_init(void) {
- debug_enable = 1; // Debug is ON!
- if (!eeconfig_is_enabled()) {
- eeconfig_init();
- }
- haptic_config.raw = eeconfig_read_haptic();
-#ifdef SOLENOID_ENABLE
- solenoid_set_dwell(haptic_config.dwell);
-#endif
- if ((haptic_config.raw == 0)
-#ifdef SOLENOID_ENABLE
- || (haptic_config.dwell == 0)
-#endif
- ) {
- // this will be called, if the eeprom is not corrupt,
- // but the previous firmware didn't have haptic enabled,
- // or the previous firmware didn't have solenoid enabled,
- // and the current one has solenoid enabled.
- haptic_reset();
- }
-#ifdef SOLENOID_ENABLE
- solenoid_setup();
- dprintf("Solenoid driver initialized\n");
-#endif
-#ifdef DRV2605L
- DRV_init();
- dprintf("DRV2605 driver initialized\n");
-#endif
- eeconfig_debug_haptic();
-}
-
-void haptic_task(void) {
-#ifdef SOLENOID_ENABLE
- solenoid_check();
-#endif
-}
-
-void eeconfig_debug_haptic(void) {
- dprintf("haptic_config eprom\n");
- dprintf("haptic_config.enable = %d\n", haptic_config.enable);
- dprintf("haptic_config.mode = %d\n", haptic_config.mode);
-}
-
-void haptic_enable(void) {
- haptic_config.enable = 1;
- xprintf("haptic_config.enable = %u\n", haptic_config.enable);
- eeconfig_update_haptic(haptic_config.raw);
-}
-
-void haptic_disable(void) {
- haptic_config.enable = 0;
- xprintf("haptic_config.enable = %u\n", haptic_config.enable);
- eeconfig_update_haptic(haptic_config.raw);
-}
-
-void haptic_toggle(void) {
- if (haptic_config.enable) {
- haptic_disable();
- } else {
- haptic_enable();
- }
- eeconfig_update_haptic(haptic_config.raw);
-}
-
-void haptic_feedback_toggle(void) {
- haptic_config.feedback++;
- if (haptic_config.feedback >= HAPTIC_FEEDBACK_MAX) haptic_config.feedback = KEY_PRESS;
- xprintf("haptic_config.feedback = %u\n", !haptic_config.feedback);
- eeconfig_update_haptic(haptic_config.raw);
-}
-
-void haptic_buzz_toggle(void) {
- bool buzz_stat = !haptic_config.buzz;
- haptic_config.buzz = buzz_stat;
- haptic_set_buzz(buzz_stat);
-}
-
-void haptic_mode_increase(void) {
- uint8_t mode = haptic_config.mode + 1;
-#ifdef DRV2605L
- if (haptic_config.mode >= drv_effect_max) {
- mode = 1;
- }
-#endif
- haptic_set_mode(mode);
-}
-
-void haptic_mode_decrease(void) {
- uint8_t mode = haptic_config.mode - 1;
-#ifdef DRV2605L
- if (haptic_config.mode < 1) {
- mode = (drv_effect_max - 1);
- }
-#endif
- haptic_set_mode(mode);
-}
-
-void haptic_dwell_increase(void) {
-#ifdef SOLENOID_ENABLE
- int16_t next_dwell = ((int16_t)haptic_config.dwell) + SOLENOID_DWELL_STEP_SIZE;
- if (haptic_config.dwell >= SOLENOID_MAX_DWELL) {
- // if it's already at max, we wrap back to min
- next_dwell = SOLENOID_MIN_DWELL;
- } else if (next_dwell > SOLENOID_MAX_DWELL) {
- // if we overshoot the max, then cap at max
- next_dwell = SOLENOID_MAX_DWELL;
- }
- solenoid_set_dwell(next_dwell);
-#else
- int16_t next_dwell = ((int16_t)haptic_config.dwell) + 1;
-#endif
- haptic_set_dwell(next_dwell);
-}
-
-void haptic_dwell_decrease(void) {
-#ifdef SOLENOID_ENABLE
- int16_t next_dwell = ((int16_t)haptic_config.dwell) - SOLENOID_DWELL_STEP_SIZE;
- if (haptic_config.dwell <= SOLENOID_MIN_DWELL) {
- // if it's already at min, we wrap to max
- next_dwell = SOLENOID_MAX_DWELL;
- } else if (next_dwell < SOLENOID_MIN_DWELL) {
- // if we go below min, then we cap to min
- next_dwell = SOLENOID_MIN_DWELL;
- }
- solenoid_set_dwell(next_dwell);
-#else
- int16_t next_dwell = ((int16_t)haptic_config.dwell) - 1;
-#endif
- haptic_set_dwell(next_dwell);
-}
-
-void haptic_reset(void) {
- haptic_config.enable = true;
- uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT;
- haptic_config.feedback = feedback;
-#ifdef DRV2605L
- uint8_t mode = HAPTIC_MODE_DEFAULT;
- haptic_config.mode = mode;
-#endif
-#ifdef SOLENOID_ENABLE
- uint8_t dwell = SOLENOID_DEFAULT_DWELL;
- haptic_config.dwell = dwell;
- haptic_config.buzz = SOLENOID_DEFAULT_BUZZ;
- solenoid_set_dwell(dwell);
-#else
- // This is to trigger haptic_reset again, if solenoid is enabled in the future.
- haptic_config.dwell = 0;
- haptic_config.buzz = 0;
-#endif
- eeconfig_update_haptic(haptic_config.raw);
- xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
- xprintf("haptic_config.mode = %u\n", haptic_config.mode);
-}
-
-void haptic_set_feedback(uint8_t feedback) {
- haptic_config.feedback = feedback;
- eeconfig_update_haptic(haptic_config.raw);
- xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
-}
-
-void haptic_set_mode(uint8_t mode) {
- haptic_config.mode = mode;
- eeconfig_update_haptic(haptic_config.raw);
- xprintf("haptic_config.mode = %u\n", haptic_config.mode);
-}
-
-void haptic_set_amplitude(uint8_t amp) {
- haptic_config.amplitude = amp;
- eeconfig_update_haptic(haptic_config.raw);
- xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude);
-#ifdef DRV2605L
- DRV_amplitude(amp);
-#endif
-}
-
-void haptic_set_buzz(uint8_t buzz) {
- haptic_config.buzz = buzz;
- eeconfig_update_haptic(haptic_config.raw);
- xprintf("haptic_config.buzz = %u\n", haptic_config.buzz);
-}
-
-void haptic_set_dwell(uint8_t dwell) {
- haptic_config.dwell = dwell;
- eeconfig_update_haptic(haptic_config.raw);
- xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
-}
-
-uint8_t haptic_get_mode(void) {
- if (!haptic_config.enable) {
- return false;
- }
- return haptic_config.mode;
-}
-
-uint8_t haptic_get_feedback(void) {
- if (!haptic_config.enable) {
- return false;
- }
- return haptic_config.feedback;
-}
-
-uint8_t haptic_get_dwell(void) {
- if (!haptic_config.enable) {
- return false;
- }
- return haptic_config.dwell;
-}
-
-void haptic_enable_continuous(void) {
- haptic_config.cont = 1;
- xprintf("haptic_config.cont = %u\n", haptic_config.cont);
- eeconfig_update_haptic(haptic_config.raw);
-#ifdef DRV2605L
- DRV_rtp_init();
-#endif
-}
-
-void haptic_disable_continuous(void) {
- haptic_config.cont = 0;
- xprintf("haptic_config.cont = %u\n", haptic_config.cont);
- eeconfig_update_haptic(haptic_config.raw);
-#ifdef DRV2605L
- DRV_write(DRV_MODE, 0x00);
-#endif
-}
-
-void haptic_toggle_continuous(void) {
-#ifdef DRV2605L
- if (haptic_config.cont) {
- haptic_disable_continuous();
- } else {
- haptic_enable_continuous();
- }
- eeconfig_update_haptic(haptic_config.raw);
-#endif
-}
-
-void haptic_cont_increase(void) {
- uint8_t amp = haptic_config.amplitude + 10;
- if (haptic_config.amplitude >= 120) {
- amp = 120;
- }
- haptic_set_amplitude(amp);
-}
-
-void haptic_cont_decrease(void) {
- uint8_t amp = haptic_config.amplitude - 10;
- if (haptic_config.amplitude < 20) {
- amp = 20;
- }
- haptic_set_amplitude(amp);
-}
-
-void haptic_play(void) {
-#ifdef DRV2605L
- uint8_t play_eff = 0;
- play_eff = haptic_config.mode;
- DRV_pulse(play_eff);
-#endif
-#ifdef SOLENOID_ENABLE
- solenoid_fire();
-#endif
-}
-
-__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
- switch(keycode) {
-# ifdef NO_HAPTIC_MOD
- case QK_MOD_TAP ... QK_MOD_TAP_MAX:
- if (record->tap.count == 0) return false;
- break;
- case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
- if (record->tap.count != TAPPING_TOGGLE) return false;
- break;
- case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
- if (record->tap.count == 0) return false;
- break;
- case KC_LCTRL ... KC_RGUI:
- case QK_MOMENTARY ... QK_MOMENTARY_MAX:
-# endif
-# ifdef NO_HAPTIC_FN
- case KC_FN0 ... KC_FN31:
-# endif
-# ifdef NO_HAPTIC_ALPHA
- case KC_A ... KC_Z:
-# endif
-# ifdef NO_HAPTIC_PUNCTUATION
- case KC_ENTER:
- case KC_ESCAPE:
- case KC_BSPACE:
- case KC_SPACE:
- case KC_MINUS:
- case KC_EQUAL:
- case KC_LBRACKET:
- case KC_RBRACKET:
- case KC_BSLASH:
- case KC_NONUS_HASH:
- case KC_SCOLON:
- case KC_QUOTE:
- case KC_GRAVE:
- case KC_COMMA:
- case KC_SLASH:
- case KC_DOT:
- case KC_NONUS_BSLASH:
-# endif
-# ifdef NO_HAPTIC_LOCKKEYS
- case KC_CAPSLOCK:
- case KC_SCROLLLOCK:
- case KC_NUMLOCK:
-# endif
-# ifdef NO_HAPTIC_NAV
- case KC_PSCREEN:
- case KC_PAUSE:
- case KC_INSERT:
- case KC_DELETE:
- case KC_PGDOWN:
- case KC_PGUP:
- case KC_LEFT:
- case KC_UP:
- case KC_RIGHT:
- case KC_DOWN:
- case KC_END:
- case KC_HOME:
-# endif
-# ifdef NO_HAPTIC_NUMERIC
- case KC_1 ... KC_0:
-# endif
- return false;
- }
- return true;
-}
-
-bool process_haptic(uint16_t keycode, keyrecord_t *record) {
- if (keycode == HPT_ON && record->event.pressed) {
- haptic_enable();
- }
- if (keycode == HPT_OFF && record->event.pressed) {
- haptic_disable();
- }
- if (keycode == HPT_TOG && record->event.pressed) {
- haptic_toggle();
- }
- if (keycode == HPT_RST && record->event.pressed) {
- haptic_reset();
- }
- if (keycode == HPT_FBK && record->event.pressed) {
- haptic_feedback_toggle();
- }
- if (keycode == HPT_BUZ && record->event.pressed) {
- haptic_buzz_toggle();
- }
- if (keycode == HPT_MODI && record->event.pressed) {
- haptic_mode_increase();
- }
- if (keycode == HPT_MODD && record->event.pressed) {
- haptic_mode_decrease();
- }
- if (keycode == HPT_DWLI && record->event.pressed) {
- haptic_dwell_increase();
- }
- if (keycode == HPT_DWLD && record->event.pressed) {
- haptic_dwell_decrease();
- }
- if (keycode == HPT_CONT && record->event.pressed) {
- haptic_toggle_continuous();
- }
- if (keycode == HPT_CONI && record->event.pressed) {
- haptic_cont_increase();
- }
- if (keycode == HPT_COND && record->event.pressed) {
- haptic_cont_decrease();
- }
-
- if (haptic_config.enable) {
- if (record->event.pressed) {
- // keypress
- if (haptic_config.feedback < 2 && get_haptic_enabled_key(keycode, record)) {
- haptic_play();
- }
- } else {
- // keyrelease
- if (haptic_config.feedback > 0 && get_haptic_enabled_key(keycode, record)) {
- haptic_play();
- }
- }
- }
- return true;
-}
-
-void haptic_shutdown(void) {
-#ifdef SOLENOID_ENABLE
- solenoid_shutdown();
-#endif
-}
diff --git a/drivers/haptic/haptic.h b/drivers/haptic/haptic.h
deleted file mode 100644
index ba8e0d20be..0000000000
--- a/drivers/haptic/haptic.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Copyright 2019 ishtob
- * Driver for haptic feedback written for QMK
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-#include
-#include
-#include "quantum.h"
-#ifdef DRV2605L
-# include "DRV2605L.h"
-#endif
-
-#ifndef HAPTIC_FEEDBACK_DEFAULT
-# define HAPTIC_FEEDBACK_DEFAULT 0
-#endif
-#ifndef HAPTIC_MODE_DEFAULT
-# define HAPTIC_MODE_DEFAULT DRV_MODE_DEFAULT
-#endif
-
-/* EEPROM config settings */
-typedef union {
- uint32_t raw;
- struct {
- bool enable : 1;
- uint8_t feedback : 2;
- uint8_t mode : 7;
- bool buzz : 1;
- uint8_t dwell : 7;
- bool cont : 1;
- uint8_t amplitude : 8;
- uint8_t reserved : 5;
- };
-} haptic_config_t;
-
-typedef enum HAPTIC_FEEDBACK {
- KEY_PRESS,
- KEY_PRESS_RELEASE,
- KEY_RELEASE,
- HAPTIC_FEEDBACK_MAX,
-} HAPTIC_FEEDBACK;
-
-bool process_haptic(uint16_t keycode, keyrecord_t *record);
-void haptic_init(void);
-void haptic_task(void);
-void eeconfig_debug_haptic(void);
-void haptic_enable(void);
-void haptic_disable(void);
-void haptic_toggle(void);
-void haptic_feedback_toggle(void);
-void haptic_mode_increase(void);
-void haptic_mode_decrease(void);
-void haptic_mode(uint8_t mode);
-void haptic_reset(void);
-void haptic_set_feedback(uint8_t feedback);
-void haptic_set_mode(uint8_t mode);
-void haptic_set_dwell(uint8_t dwell);
-void haptic_set_buzz(uint8_t buzz);
-void haptic_buzz_toggle(void);
-uint8_t haptic_get_mode(void);
-uint8_t haptic_get_feedback(void);
-void haptic_dwell_increase(void);
-void haptic_dwell_decrease(void);
-void haptic_toggle_continuous(void);
-void haptic_cont_increase(void);
-void haptic_cont_decrease(void);
-
-void haptic_play(void);
-void haptic_shutdown(void);
diff --git a/quantum/haptic.c b/quantum/haptic.c
new file mode 100644
index 0000000000..65abcc15fa
--- /dev/null
+++ b/quantum/haptic.c
@@ -0,0 +1,295 @@
+/* Copyright 2019 ishtob
+ * Driver for haptic feedback written for QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#include "haptic.h"
+#include "eeconfig.h"
+#include "debug.h"
+#ifdef DRV2605L
+# include "DRV2605L.h"
+#endif
+#ifdef SOLENOID_ENABLE
+# include "solenoid.h"
+#endif
+
+haptic_config_t haptic_config;
+
+void haptic_init(void) {
+ if (!eeconfig_is_enabled()) {
+ eeconfig_init();
+ }
+ haptic_config.raw = eeconfig_read_haptic();
+#ifdef SOLENOID_ENABLE
+ solenoid_set_dwell(haptic_config.dwell);
+#endif
+ if ((haptic_config.raw == 0)
+#ifdef SOLENOID_ENABLE
+ || (haptic_config.dwell == 0)
+#endif
+ ) {
+ // this will be called, if the eeprom is not corrupt,
+ // but the previous firmware didn't have haptic enabled,
+ // or the previous firmware didn't have solenoid enabled,
+ // and the current one has solenoid enabled.
+ haptic_reset();
+ }
+#ifdef SOLENOID_ENABLE
+ solenoid_setup();
+ dprintf("Solenoid driver initialized\n");
+#endif
+#ifdef DRV2605L
+ DRV_init();
+ dprintf("DRV2605 driver initialized\n");
+#endif
+ eeconfig_debug_haptic();
+}
+
+void haptic_task(void) {
+#ifdef SOLENOID_ENABLE
+ solenoid_check();
+#endif
+}
+
+void eeconfig_debug_haptic(void) {
+ dprintf("haptic_config eeprom\n");
+ dprintf("haptic_config.enable = %d\n", haptic_config.enable);
+ dprintf("haptic_config.mode = %d\n", haptic_config.mode);
+}
+
+void haptic_enable(void) {
+ haptic_config.enable = 1;
+ xprintf("haptic_config.enable = %u\n", haptic_config.enable);
+ eeconfig_update_haptic(haptic_config.raw);
+}
+
+void haptic_disable(void) {
+ haptic_config.enable = 0;
+ xprintf("haptic_config.enable = %u\n", haptic_config.enable);
+ eeconfig_update_haptic(haptic_config.raw);
+}
+
+void haptic_toggle(void) {
+ if (haptic_config.enable) {
+ haptic_disable();
+ } else {
+ haptic_enable();
+ }
+ eeconfig_update_haptic(haptic_config.raw);
+}
+
+void haptic_feedback_toggle(void) {
+ haptic_config.feedback++;
+ if (haptic_config.feedback >= HAPTIC_FEEDBACK_MAX) haptic_config.feedback = KEY_PRESS;
+ xprintf("haptic_config.feedback = %u\n", !haptic_config.feedback);
+ eeconfig_update_haptic(haptic_config.raw);
+}
+
+void haptic_buzz_toggle(void) {
+ bool buzz_stat = !haptic_config.buzz;
+ haptic_config.buzz = buzz_stat;
+ haptic_set_buzz(buzz_stat);
+}
+
+void haptic_mode_increase(void) {
+ uint8_t mode = haptic_config.mode + 1;
+#ifdef DRV2605L
+ if (haptic_config.mode >= drv_effect_max) {
+ mode = 1;
+ }
+#endif
+ haptic_set_mode(mode);
+}
+
+void haptic_mode_decrease(void) {
+ uint8_t mode = haptic_config.mode - 1;
+#ifdef DRV2605L
+ if (haptic_config.mode < 1) {
+ mode = (drv_effect_max - 1);
+ }
+#endif
+ haptic_set_mode(mode);
+}
+
+void haptic_dwell_increase(void) {
+#ifdef SOLENOID_ENABLE
+ int16_t next_dwell = ((int16_t)haptic_config.dwell) + SOLENOID_DWELL_STEP_SIZE;
+ if (haptic_config.dwell >= SOLENOID_MAX_DWELL) {
+ // if it's already at max, we wrap back to min
+ next_dwell = SOLENOID_MIN_DWELL;
+ } else if (next_dwell > SOLENOID_MAX_DWELL) {
+ // if we overshoot the max, then cap at max
+ next_dwell = SOLENOID_MAX_DWELL;
+ }
+ solenoid_set_dwell(next_dwell);
+#else
+ int16_t next_dwell = ((int16_t)haptic_config.dwell) + 1;
+#endif
+ haptic_set_dwell(next_dwell);
+}
+
+void haptic_dwell_decrease(void) {
+#ifdef SOLENOID_ENABLE
+ int16_t next_dwell = ((int16_t)haptic_config.dwell) - SOLENOID_DWELL_STEP_SIZE;
+ if (haptic_config.dwell <= SOLENOID_MIN_DWELL) {
+ // if it's already at min, we wrap to max
+ next_dwell = SOLENOID_MAX_DWELL;
+ } else if (next_dwell < SOLENOID_MIN_DWELL) {
+ // if we go below min, then we cap to min
+ next_dwell = SOLENOID_MIN_DWELL;
+ }
+ solenoid_set_dwell(next_dwell);
+#else
+ int16_t next_dwell = ((int16_t)haptic_config.dwell) - 1;
+#endif
+ haptic_set_dwell(next_dwell);
+}
+
+void haptic_reset(void) {
+ haptic_config.enable = true;
+ uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT;
+ haptic_config.feedback = feedback;
+#ifdef DRV2605L
+ uint8_t mode = HAPTIC_MODE_DEFAULT;
+ haptic_config.mode = mode;
+#endif
+#ifdef SOLENOID_ENABLE
+ uint8_t dwell = SOLENOID_DEFAULT_DWELL;
+ haptic_config.dwell = dwell;
+ haptic_config.buzz = SOLENOID_DEFAULT_BUZZ;
+ solenoid_set_dwell(dwell);
+#else
+ // This is to trigger haptic_reset again, if solenoid is enabled in the future.
+ haptic_config.dwell = 0;
+ haptic_config.buzz = 0;
+#endif
+ eeconfig_update_haptic(haptic_config.raw);
+ xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
+ xprintf("haptic_config.mode = %u\n", haptic_config.mode);
+}
+
+void haptic_set_feedback(uint8_t feedback) {
+ haptic_config.feedback = feedback;
+ eeconfig_update_haptic(haptic_config.raw);
+ xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
+}
+
+void haptic_set_mode(uint8_t mode) {
+ haptic_config.mode = mode;
+ eeconfig_update_haptic(haptic_config.raw);
+ xprintf("haptic_config.mode = %u\n", haptic_config.mode);
+}
+
+void haptic_set_amplitude(uint8_t amp) {
+ haptic_config.amplitude = amp;
+ eeconfig_update_haptic(haptic_config.raw);
+ xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude);
+#ifdef DRV2605L
+ DRV_amplitude(amp);
+#endif
+}
+
+void haptic_set_buzz(uint8_t buzz) {
+ haptic_config.buzz = buzz;
+ eeconfig_update_haptic(haptic_config.raw);
+ xprintf("haptic_config.buzz = %u\n", haptic_config.buzz);
+}
+
+void haptic_set_dwell(uint8_t dwell) {
+ haptic_config.dwell = dwell;
+ eeconfig_update_haptic(haptic_config.raw);
+ xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
+}
+
+uint8_t haptic_get_enable(void) { return haptic_config.enable; }
+
+uint8_t haptic_get_mode(void) {
+ if (!haptic_config.enable) {
+ return false;
+ }
+ return haptic_config.mode;
+}
+
+uint8_t haptic_get_feedback(void) {
+ if (!haptic_config.enable) {
+ return false;
+ }
+ return haptic_config.feedback;
+}
+
+uint8_t haptic_get_dwell(void) {
+ if (!haptic_config.enable) {
+ return false;
+ }
+ return haptic_config.dwell;
+}
+
+void haptic_enable_continuous(void) {
+ haptic_config.cont = 1;
+ xprintf("haptic_config.cont = %u\n", haptic_config.cont);
+ eeconfig_update_haptic(haptic_config.raw);
+#ifdef DRV2605L
+ DRV_rtp_init();
+#endif
+}
+
+void haptic_disable_continuous(void) {
+ haptic_config.cont = 0;
+ xprintf("haptic_config.cont = %u\n", haptic_config.cont);
+ eeconfig_update_haptic(haptic_config.raw);
+#ifdef DRV2605L
+ DRV_write(DRV_MODE, 0x00);
+#endif
+}
+
+void haptic_toggle_continuous(void) {
+ if (haptic_config.cont) {
+ haptic_disable_continuous();
+ } else {
+ haptic_enable_continuous();
+ }
+}
+
+void haptic_cont_increase(void) {
+ uint8_t amp = haptic_config.amplitude + 10;
+ if (haptic_config.amplitude >= 120) {
+ amp = 120;
+ }
+ haptic_set_amplitude(amp);
+}
+
+void haptic_cont_decrease(void) {
+ uint8_t amp = haptic_config.amplitude - 10;
+ if (haptic_config.amplitude < 20) {
+ amp = 20;
+ }
+ haptic_set_amplitude(amp);
+}
+
+void haptic_play(void) {
+#ifdef DRV2605L
+ uint8_t play_eff = 0;
+ play_eff = haptic_config.mode;
+ DRV_pulse(play_eff);
+#endif
+#ifdef SOLENOID_ENABLE
+ solenoid_fire();
+#endif
+}
+
+void haptic_shutdown(void) {
+#ifdef SOLENOID_ENABLE
+ solenoid_shutdown();
+#endif
+}
diff --git a/quantum/haptic.h b/quantum/haptic.h
new file mode 100644
index 0000000000..fc7ca2f3e6
--- /dev/null
+++ b/quantum/haptic.h
@@ -0,0 +1,77 @@
+/* Copyright 2019 ishtob
+ * Driver for haptic feedback written for QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+#include
+#include
+
+#ifndef HAPTIC_FEEDBACK_DEFAULT
+# define HAPTIC_FEEDBACK_DEFAULT 0
+#endif
+#ifndef HAPTIC_MODE_DEFAULT
+# define HAPTIC_MODE_DEFAULT DRV_MODE_DEFAULT
+#endif
+
+/* EEPROM config settings */
+typedef union {
+ uint32_t raw;
+ struct {
+ bool enable : 1;
+ uint8_t feedback : 2;
+ uint8_t mode : 7;
+ bool buzz : 1;
+ uint8_t dwell : 7;
+ bool cont : 1;
+ uint8_t amplitude : 8;
+ uint8_t reserved : 5;
+ };
+} haptic_config_t;
+
+typedef enum HAPTIC_FEEDBACK {
+ KEY_PRESS,
+ KEY_PRESS_RELEASE,
+ KEY_RELEASE,
+ HAPTIC_FEEDBACK_MAX,
+} HAPTIC_FEEDBACK;
+
+void haptic_init(void);
+void haptic_task(void);
+void eeconfig_debug_haptic(void);
+void haptic_enable(void);
+void haptic_disable(void);
+void haptic_toggle(void);
+void haptic_feedback_toggle(void);
+void haptic_mode_increase(void);
+void haptic_mode_decrease(void);
+void haptic_mode(uint8_t mode);
+void haptic_reset(void);
+void haptic_set_feedback(uint8_t feedback);
+void haptic_set_mode(uint8_t mode);
+void haptic_set_dwell(uint8_t dwell);
+void haptic_set_buzz(uint8_t buzz);
+void haptic_buzz_toggle(void);
+uint8_t haptic_get_enable(void);
+uint8_t haptic_get_mode(void);
+uint8_t haptic_get_feedback(void);
+void haptic_dwell_increase(void);
+void haptic_dwell_decrease(void);
+void haptic_toggle_continuous(void);
+void haptic_cont_increase(void);
+void haptic_cont_decrease(void);
+
+void haptic_play(void);
+void haptic_shutdown(void);
diff --git a/quantum/process_keycode/process_haptic.c b/quantum/process_keycode/process_haptic.c
new file mode 100644
index 0000000000..29a4ffd10a
--- /dev/null
+++ b/quantum/process_keycode/process_haptic.c
@@ -0,0 +1,147 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#include "haptic.h"
+#include "process_haptic.h"
+#include "quantum_keycodes.h"
+
+__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
+ switch (keycode) {
+#ifdef NO_HAPTIC_MOD
+ case QK_MOD_TAP ... QK_MOD_TAP_MAX:
+ if (record->tap.count == 0) return false;
+ break;
+ case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
+ if (record->tap.count != TAPPING_TOGGLE) return false;
+ break;
+ case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
+ if (record->tap.count == 0) return false;
+ break;
+ case KC_LCTRL ... KC_RGUI:
+ case QK_MOMENTARY ... QK_MOMENTARY_MAX:
+#endif
+#ifdef NO_HAPTIC_FN
+ case KC_FN0 ... KC_FN31:
+#endif
+#ifdef NO_HAPTIC_ALPHA
+ case KC_A ... KC_Z:
+#endif
+#ifdef NO_HAPTIC_PUNCTUATION
+ case KC_ENTER:
+ case KC_ESCAPE:
+ case KC_BSPACE:
+ case KC_SPACE:
+ case KC_MINUS:
+ case KC_EQUAL:
+ case KC_LBRACKET:
+ case KC_RBRACKET:
+ case KC_BSLASH:
+ case KC_NONUS_HASH:
+ case KC_SCOLON:
+ case KC_QUOTE:
+ case KC_GRAVE:
+ case KC_COMMA:
+ case KC_SLASH:
+ case KC_DOT:
+ case KC_NONUS_BSLASH:
+#endif
+#ifdef NO_HAPTIC_LOCKKEYS
+ case KC_CAPSLOCK:
+ case KC_SCROLLLOCK:
+ case KC_NUMLOCK:
+#endif
+#ifdef NO_HAPTIC_NAV
+ case KC_PSCREEN:
+ case KC_PAUSE:
+ case KC_INSERT:
+ case KC_DELETE:
+ case KC_PGDOWN:
+ case KC_PGUP:
+ case KC_LEFT:
+ case KC_UP:
+ case KC_RIGHT:
+ case KC_DOWN:
+ case KC_END:
+ case KC_HOME:
+#endif
+#ifdef NO_HAPTIC_NUMERIC
+ case KC_1 ... KC_0:
+#endif
+ return false;
+ }
+ return true;
+}
+
+bool process_haptic(uint16_t keycode, keyrecord_t *record) {
+ if (record->event.pressed) {
+ switch (keycode) {
+ case HPT_ON:
+ haptic_enable();
+ break;
+ case HPT_OFF:
+ haptic_disable();
+ break;
+ case HPT_TOG:
+ haptic_toggle();
+ break;
+ case HPT_RST:
+ haptic_reset();
+ break;
+ case HPT_FBK:
+ haptic_feedback_toggle();
+ break;
+ case HPT_BUZ:
+ haptic_buzz_toggle();
+ break;
+ case HPT_MODI:
+ haptic_mode_increase();
+ break;
+ case HPT_MODD:
+ haptic_mode_decrease();
+ break;
+ case HPT_DWLI:
+ haptic_dwell_increase();
+ break;
+ case HPT_DWLD:
+ haptic_dwell_decrease();
+ break;
+ case HPT_CONT:
+ haptic_toggle_continuous();
+ break;
+ case HPT_CONI:
+ haptic_cont_increase();
+ break;
+ case HPT_COND:
+ haptic_cont_decrease();
+ break;
+ }
+ }
+
+ if (haptic_get_enable()) {
+ if (record->event.pressed) {
+ // keypress
+ if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, record)) {
+ haptic_play();
+ }
+ } else {
+ // keyrelease
+ if (haptic_get_feedback() > 0 && get_haptic_enabled_key(keycode, record)) {
+ haptic_play();
+ }
+ }
+ }
+
+ return true;
+}
diff --git a/quantum/process_keycode/process_haptic.h b/quantum/process_keycode/process_haptic.h
new file mode 100644
index 0000000000..6dbb0f014d
--- /dev/null
+++ b/quantum/process_keycode/process_haptic.h
@@ -0,0 +1,21 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#pragma once
+
+#include
+#include "action.h"
+
+bool process_haptic(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 56ceec5db8..f430a521b3 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -220,10 +220,10 @@ bool process_record_quantum(keyrecord_t *record) {
#endif
#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
process_clicky(keycode, record) &&
-#endif // AUDIO_CLICKY
+#endif
#ifdef HAPTIC_ENABLE
process_haptic(keycode, record) &&
-#endif // HAPTIC_ENABLE
+#endif
#if defined(VIA_ENABLE)
process_record_via(keycode, record) &&
#endif
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 756a5603c1..72970a6496 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -161,6 +161,7 @@ extern layer_state_t layer_state;
#ifdef HAPTIC_ENABLE
# include "haptic.h"
+# include "process_haptic.h"
#endif
#ifdef OLED_DRIVER_ENABLE
--
cgit v1.2.3
From 9e782e4f1415e25b0f8349d51400fdfe29ebb0c1 Mon Sep 17 00:00:00 2001
From: Drashna Jaelre
Date: Sun, 25 Jul 2021 21:24:47 -0700
Subject: [Bug] Include gpio.h in solenoid driver for GPIO Control functions
(#13716)
---
drivers/haptic/solenoid.c | 1 +
1 file changed, 1 insertion(+)
(limited to 'drivers')
diff --git a/drivers/haptic/solenoid.c b/drivers/haptic/solenoid.c
index 3e61d5a171..25cf344655 100644
--- a/drivers/haptic/solenoid.c
+++ b/drivers/haptic/solenoid.c
@@ -18,6 +18,7 @@
#include "timer.h"
#include "solenoid.h"
#include "haptic.h"
+#include "gpio.h"
bool solenoid_on = false;
bool solenoid_buzzing = false;
--
cgit v1.2.3
From 3858a784c702d75d207e62c6cdf4449eed41c789 Mon Sep 17 00:00:00 2001
From: Joel Challis
Date: Tue, 27 Jul 2021 23:55:51 +0100
Subject: Align AW20216 driver (#13712)
* Align AW20216 driver
* Update drivers/awinic/aw20216.h
Co-authored-by: Ryan
* Review comments
* formatting fixes
* stop if start failed?
* review comments
Co-authored-by: Ryan ---
drivers/awinic/aw20216.c | 131 +++++++++++---------------------
drivers/awinic/aw20216.h | 5 +-
quantum/rgb_matrix/rgb_matrix_drivers.c | 12 ++-
3 files changed, 58 insertions(+), 90 deletions(-)
(limited to 'drivers')
diff --git a/drivers/awinic/aw20216.c b/drivers/awinic/aw20216.c
index 776653fa6c..c608c0ab44 100644
--- a/drivers/awinic/aw20216.c
+++ b/drivers/awinic/aw20216.c
@@ -45,8 +45,6 @@
#define AW_PWM_REGISTER_COUNT 216
-#define AW_SPI_START(PIN) spi_start(PIN, false, 0, AW_SPI_DIVISOR)
-
#ifndef AW_SCALING_MAX
# define AW_SCALING_MAX 150
#endif
@@ -55,128 +53,89 @@
# define AW_GLOBAL_CURRENT_MAX 150
#endif
-#ifndef DRIVER_1_CS
-# define DRIVER_1_CS B13
-#endif
-
-#ifndef DRIVER_1_EN
-# define DRIVER_1_EN C13
-#endif
-
#ifndef AW_SPI_DIVISOR
# define AW_SPI_DIVISOR 4
#endif
-uint8_t g_spi_transfer_buffer[3] = {0};
uint8_t g_pwm_buffer[DRIVER_COUNT][AW_PWM_REGISTER_COUNT];
bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
-bool AW20216_write_register(pin_t slave_pin, uint8_t page, uint8_t reg, uint8_t data) {
- // Do we need to call spi_stop() if this fails?
- if (!AW_SPI_START(slave_pin)) {
+bool AW20216_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8_t len) {
+ static uint8_t s_spi_transfer_buffer[2] = {0};
+
+ if (!spi_start(cs_pin, false, 0, AW_SPI_DIVISOR)) {
+ spi_stop();
return false;
}
- g_spi_transfer_buffer[0] = (AWINIC_ID | page | AW_WRITE);
- g_spi_transfer_buffer[1] = reg;
- g_spi_transfer_buffer[2] = data;
+ s_spi_transfer_buffer[0] = (AWINIC_ID | page | AW_WRITE);
+ s_spi_transfer_buffer[1] = reg;
- if (spi_transmit(g_spi_transfer_buffer, 3) != SPI_STATUS_SUCCESS) {
+ if (spi_transmit(s_spi_transfer_buffer, 2) != SPI_STATUS_SUCCESS) {
spi_stop();
return false;
}
+
+ if (spi_transmit(data, len) != SPI_STATUS_SUCCESS) {
+ spi_stop();
+ return false;
+ }
+
spi_stop();
return true;
}
-bool AW20216_init_scaling(void) {
+static inline bool AW20216_write_register(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t value) {
+ // Little wrapper so callers need not care about sending a buffer
+ return AW20216_write(cs_pin, page, reg, &value, 1);
+}
+
+static void AW20216_init_scaling(pin_t cs_pin) {
// Set constant current to the max, control brightness with PWM
- aw_led led;
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- led = g_aw_leds[i];
- if (led.driver == 0) {
- AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.r, AW_SCALING_MAX);
- AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.g, AW_SCALING_MAX);
- AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.b, AW_SCALING_MAX);
- }
-#ifdef DRIVER_2_CS
- else if (led.driver == 1) {
- AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.r, AW_SCALING_MAX);
- AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.g, AW_SCALING_MAX);
- AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.b, AW_SCALING_MAX);
- }
-#endif
+ for (uint8_t i = 0; i < AW_PWM_REGISTER_COUNT; i++) {
+ AW20216_write_register(cs_pin, AW_PAGE_SCALING, i, AW_SCALING_MAX);
}
- return true;
}
-bool AW20216_soft_enable(void) {
- AW20216_write_register(DRIVER_1_CS, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN);
-#ifdef DRIVER_2_CS
- AW20216_write_register(DRIVER_2_CS, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN);
-#endif
- return true;
+static inline void AW20216_init_current_limit(pin_t cs_pin) {
+ // Push config
+ AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX);
}
-void AW20216_update_pwm(int index, uint8_t red, uint8_t green, uint8_t blue) {
- aw_led led = g_aw_leds[index];
- if (led.driver == 0) {
- AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.r, red);
- AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.g, green);
- AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.b, blue);
- }
-#ifdef DRIVER_2_CS
- else if (led.driver == 1) {
- AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.r, red);
- AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.g, green);
- AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.b, blue);
- }
-#endif
- return;
+static inline void AW20216_soft_enable(pin_t cs_pin) {
+ // Push config
+ AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN);
}
-void AW20216_init(void) {
- // All LEDs should start with all scaling and PWM registers as off
- setPinOutput(DRIVER_1_EN);
- writePinHigh(DRIVER_1_EN);
- AW20216_write_register(DRIVER_1_CS, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX);
-#ifdef DRIVER_2_EN
- setPinOutput(DRIVER_2_EN);
- writePinHigh(DRIVER_2_EN);
- AW20216_write_register(DRIVER_2_CS, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX);
-#endif
- AW20216_init_scaling();
- AW20216_soft_enable();
- return;
+void AW20216_init(pin_t cs_pin, pin_t en_pin) {
+ setPinOutput(en_pin);
+ writePinHigh(en_pin);
+
+ // Drivers should start with all scaling and PWM registers as off
+ AW20216_init_current_limit(cs_pin);
+ AW20216_init_scaling(cs_pin);
+
+ AW20216_soft_enable(cs_pin);
}
void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- aw_led led = g_aw_leds[index];
+ aw_led led = g_aw_leds[index];
+
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue;
g_pwm_buffer_update_required[led.driver] = true;
- return;
}
+
void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
AW20216_set_color(i, red, green, blue);
}
- return;
-}
-
-void AW20216_write_pwm_buffer(pin_t slave_pin, uint8_t buffer_idx) {
- AW_SPI_START(slave_pin);
- spi_write((AWINIC_ID | AW_PAGE_PWM | AW_WRITE));
- spi_write(0);
- spi_transmit(g_pwm_buffer[buffer_idx], AW_PWM_REGISTER_COUNT);
- spi_stop();
}
-void AW20216_update_pwm_buffers(void) {
- AW20216_write_pwm_buffer(DRIVER_1_CS, 0);
-#ifdef DRIVER_2_CS
- AW20216_write_pwm_buffer(DRIVER_2_CS, 1);
-#endif
- return;
+void AW20216_update_pwm_buffers(pin_t cs_pin, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ AW20216_write(cs_pin, AW_PAGE_PWM, 0, g_pwm_buffer[index], AW_PWM_REGISTER_COUNT);
+ }
+ g_pwm_buffer_update_required[index] = false;
}
diff --git a/drivers/awinic/aw20216.h b/drivers/awinic/aw20216.h
index 9c6865cc82..c55d9605fc 100644
--- a/drivers/awinic/aw20216.h
+++ b/drivers/awinic/aw20216.h
@@ -18,6 +18,7 @@
#include
#include
+#include "gpio.h"
typedef struct aw_led {
uint8_t driver : 2;
@@ -28,10 +29,10 @@ typedef struct aw_led {
extern const aw_led g_aw_leds[DRIVER_LED_TOTAL];
-void AW20216_init(void);
+void AW20216_init(pin_t cs_pin, pin_t en_pin);
void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-void AW20216_update_pwm_buffers(void);
+void AW20216_update_pwm_buffers(pin_t cs_pin, uint8_t index);
#define CS1_SW1 0x00
#define CS2_SW1 0x01
diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c
index dfdf452190..bfaedaa4a0 100644
--- a/quantum/rgb_matrix/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix/rgb_matrix_drivers.c
@@ -186,10 +186,18 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
# include "spi_master.h"
static void init(void) {
spi_init();
- AW20216_init();
+ AW20216_init(DRIVER_1_CS, DRIVER_1_EN);
+# ifdef DRIVER_2_CS
+ AW20216_init(DRIVER_2_CS, DRIVER_2_EN);
+# endif
}
-static void flush(void) { AW20216_update_pwm_buffers(); }
+static void flush(void) {
+ AW20216_update_pwm_buffers(DRIVER_1_CS, 0);
+# ifdef DRIVER_2_CS
+ AW20216_update_pwm_buffers(DRIVER_2_CS, 1);
+# endif
+}
const rgb_matrix_driver_t rgb_matrix_driver = {
.init = init,
--
cgit v1.2.3
From aeb252435d0c161ebd22bd8210765609813fc632 Mon Sep 17 00:00:00 2001
From: Dasky
Date: Sat, 31 Jul 2021 14:12:19 +0100
Subject: [develop] Fix pimoroni trackball read address (#13810)
---
drivers/sensors/pimoroni_trackball.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'drivers')
diff --git a/drivers/sensors/pimoroni_trackball.h b/drivers/sensors/pimoroni_trackball.h
index a30fb0bb8c..9e3c64c19c 100644
--- a/drivers/sensors/pimoroni_trackball.h
+++ b/drivers/sensors/pimoroni_trackball.h
@@ -23,7 +23,7 @@
# define TRACKBALL_ADDRESS 0x0A
#endif
#define TRACKBALL_WRITE ((TRACKBALL_ADDRESS << 1) | I2C_WRITE)
-#define TRACKBALL_READ ((TRACKBALL_ADDRESS << 1) | I2C_READ)
+#define TRACKBALL_READ (TRACKBALL_ADDRESS << 1)
void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white);
void trackball_check_click(bool pressed, report_mouse_t *mouse);
--
cgit v1.2.3
From 206a995ccd53b0843e72da606abebe06f39c9c28 Mon Sep 17 00:00:00 2001
From: Joel Challis
Date: Sat, 31 Jul 2021 14:31:09 +0100
Subject: Move some led drivers to common folder (#13749)
* Move some led drivers to common folder---
common_features.mk | 14 +-
docs/feature_led_matrix.md | 2 +-
docs/feature_rgb_matrix.md | 6 +-
docs/ja/feature_led_matrix.md | 2 +-
drivers/apa102/apa102.c | 151 ---------
drivers/apa102/apa102.h | 41 ---
drivers/awinic/aw20216.c | 141 --------
drivers/awinic/aw20216.h | 252 --------------
drivers/issi/is31fl3218.c | 96 ------
drivers/issi/is31fl3218.h | 25 --
drivers/issi/is31fl3731-simple.c | 233 -------------
drivers/issi/is31fl3731-simple.h | 207 ------------
drivers/issi/is31fl3731.c | 237 -------------
drivers/issi/is31fl3731.h | 208 ------------
drivers/issi/is31fl3733.c | 237 -------------
drivers/issi/is31fl3733.h | 251 --------------
drivers/issi/is31fl3736.c | 269 ---------------
drivers/issi/is31fl3736.h | 168 ----------
drivers/issi/is31fl3737.c | 227 -------------
drivers/issi/is31fl3737.h | 203 ------------
drivers/issi/is31fl3741.c | 255 --------------
drivers/issi/is31fl3741.h | 420 ------------------------
drivers/led/apa102.c | 151 +++++++++
drivers/led/apa102.h | 41 +++
drivers/led/aw20216.c | 141 ++++++++
drivers/led/aw20216.h | 252 ++++++++++++++
drivers/led/issi/is31fl3218.c | 96 ++++++
drivers/led/issi/is31fl3218.h | 25 ++
drivers/led/issi/is31fl3731-simple.c | 233 +++++++++++++
drivers/led/issi/is31fl3731-simple.h | 207 ++++++++++++
drivers/led/issi/is31fl3731.c | 237 +++++++++++++
drivers/led/issi/is31fl3731.h | 208 ++++++++++++
drivers/led/issi/is31fl3733.c | 237 +++++++++++++
drivers/led/issi/is31fl3733.h | 251 ++++++++++++++
drivers/led/issi/is31fl3736.c | 269 +++++++++++++++
drivers/led/issi/is31fl3736.h | 168 ++++++++++
drivers/led/issi/is31fl3737.c | 227 +++++++++++++
drivers/led/issi/is31fl3737.h | 203 ++++++++++++
drivers/led/issi/is31fl3741.c | 255 ++++++++++++++
drivers/led/issi/is31fl3741.h | 420 ++++++++++++++++++++++++
keyboards/fallacy/indicators.c | 2 +-
keyboards/fallacy/rules.mk | 2 +-
keyboards/hs60/v2/ansi/rules.mk | 2 +-
keyboards/hs60/v2/hhkb/rules.mk | 2 +-
keyboards/hs60/v2/iso/rules.mk | 2 +-
keyboards/keebwerk/mega/ansi/ansi.c | 2 +-
keyboards/keebwerk/mega/ansi/rules.mk | 2 +-
keyboards/nebula12/rules.mk | 2 +-
keyboards/nebula68/rules.mk | 2 +-
keyboards/nk65/nk65.c | 2 +-
keyboards/nk65/rules.mk | 2 +-
keyboards/nk87/nk87.c | 2 +-
keyboards/nk87/rules.mk | 2 +-
keyboards/tkc/portico/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_kara/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_koyu/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_m10_c/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_m50_a/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_m60_a/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_m65_b/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_m65_bx/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_m6_b/rules.mk | 2 +-
keyboards/wilba_tech/rama_works_u80_a/rules.mk | 2 +-
keyboards/wilba_tech/wt60_a/rules.mk | 2 +-
keyboards/wilba_tech/wt60_b/rules.mk | 2 +-
keyboards/wilba_tech/wt60_bx/rules.mk | 2 +-
keyboards/wilba_tech/wt60_c/rules.mk | 2 +-
keyboards/wilba_tech/wt65_a/rules.mk | 2 +-
keyboards/wilba_tech/wt65_b/rules.mk | 2 +-
keyboards/wilba_tech/wt75_a/rules.mk | 2 +-
keyboards/wilba_tech/wt75_b/rules.mk | 2 +-
keyboards/wilba_tech/wt75_c/rules.mk | 2 +-
keyboards/wilba_tech/wt80_a/rules.mk | 2 +-
keyboards/wilba_tech/wt_mono_backlight.c | 2 +-
keyboards/wilba_tech/wt_rgb_backlight.c | 10 +-
keyboards/wilba_tech/zeal60/rules.mk | 2 +-
keyboards/wilba_tech/zeal65/rules.mk | 2 +-
keyboards/xelus/dawn60/rev1/rules.mk | 2 +-
keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c | 2 +-
keyboards/xelus/dawn60/rev1_qmk/rules.mk | 2 +-
keyboards/xelus/pachi/rgb/rgb.c | 2 +-
keyboards/xelus/pachi/rgb/rules.mk | 2 +-
82 files changed, 3679 insertions(+), 3679 deletions(-)
delete mode 100644 drivers/apa102/apa102.c
delete mode 100644 drivers/apa102/apa102.h
delete mode 100644 drivers/awinic/aw20216.c
delete mode 100644 drivers/awinic/aw20216.h
delete mode 100644 drivers/issi/is31fl3218.c
delete mode 100644 drivers/issi/is31fl3218.h
delete mode 100644 drivers/issi/is31fl3731-simple.c
delete mode 100644 drivers/issi/is31fl3731-simple.h
delete mode 100644 drivers/issi/is31fl3731.c
delete mode 100644 drivers/issi/is31fl3731.h
delete mode 100644 drivers/issi/is31fl3733.c
delete mode 100644 drivers/issi/is31fl3733.h
delete mode 100644 drivers/issi/is31fl3736.c
delete mode 100644 drivers/issi/is31fl3736.h
delete mode 100644 drivers/issi/is31fl3737.c
delete mode 100644 drivers/issi/is31fl3737.h
delete mode 100644 drivers/issi/is31fl3741.c
delete mode 100644 drivers/issi/is31fl3741.h
create mode 100644 drivers/led/apa102.c
create mode 100644 drivers/led/apa102.h
create mode 100644 drivers/led/aw20216.c
create mode 100644 drivers/led/aw20216.h
create mode 100644 drivers/led/issi/is31fl3218.c
create mode 100644 drivers/led/issi/is31fl3218.h
create mode 100644 drivers/led/issi/is31fl3731-simple.c
create mode 100644 drivers/led/issi/is31fl3731-simple.h
create mode 100644 drivers/led/issi/is31fl3731.c
create mode 100644 drivers/led/issi/is31fl3731.h
create mode 100644 drivers/led/issi/is31fl3733.c
create mode 100644 drivers/led/issi/is31fl3733.h
create mode 100644 drivers/led/issi/is31fl3736.c
create mode 100644 drivers/led/issi/is31fl3736.h
create mode 100644 drivers/led/issi/is31fl3737.c
create mode 100644 drivers/led/issi/is31fl3737.h
create mode 100644 drivers/led/issi/is31fl3741.c
create mode 100644 drivers/led/issi/is31fl3741.h
(limited to 'drivers')
diff --git a/common_features.mk b/common_features.mk
index d8dce8a631..75a9e1f2eb 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -242,7 +242,7 @@ endif
ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3731)
OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE
- COMMON_VPATH += $(DRIVER_PATH)/issi
+ COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31fl3731-simple.c
QUANTUM_LIB_SRC += i2c_master.c
endif
@@ -272,35 +272,35 @@ endif
ifeq ($(strip $(RGB_MATRIX_DRIVER)), AW20216)
OPT_DEFS += -DAW20216 -DSTM32_SPI -DHAL_USE_SPI=TRUE
- COMMON_VPATH += $(DRIVER_PATH)/awinic
+ COMMON_VPATH += $(DRIVER_PATH)/led
SRC += aw20216.c
QUANTUM_LIB_SRC += spi_master.c
endif
ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3731)
OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE
- COMMON_VPATH += $(DRIVER_PATH)/issi
+ COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31fl3731.c
QUANTUM_LIB_SRC += i2c_master.c
endif
ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3733)
OPT_DEFS += -DIS31FL3733 -DSTM32_I2C -DHAL_USE_I2C=TRUE
- COMMON_VPATH += $(DRIVER_PATH)/issi
+ COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31fl3733.c
QUANTUM_LIB_SRC += i2c_master.c
endif
ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3737)
OPT_DEFS += -DIS31FL3737 -DSTM32_I2C -DHAL_USE_I2C=TRUE
- COMMON_VPATH += $(DRIVER_PATH)/issi
+ COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31fl3737.c
QUANTUM_LIB_SRC += i2c_master.c
endif
ifeq ($(strip $(RGB_MATRIX_DRIVER)), IS31FL3741)
OPT_DEFS += -DIS31FL3741 -DSTM32_I2C -DHAL_USE_I2C=TRUE
- COMMON_VPATH += $(DRIVER_PATH)/issi
+ COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31fl3741.c
QUANTUM_LIB_SRC += i2c_master.c
endif
@@ -417,7 +417,7 @@ ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes)
endif
ifeq ($(strip $(APA102_DRIVER_REQUIRED)), yes)
- COMMON_VPATH += $(DRIVER_PATH)/apa102
+ COMMON_VPATH += $(DRIVER_PATH)/led
SRC += apa102.c
endif
diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md
index 018da43dd1..afa11e7232 100644
--- a/docs/feature_led_matrix.md
+++ b/docs/feature_led_matrix.md
@@ -63,7 +63,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
}
```
-Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731-simple.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` ).
+Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/led/issi/is31fl3731-simple.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` ).
---
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index bd47fb6d39..18e38955ec 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -64,7 +64,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
}
```
-Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3`).
+Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/led/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3`).
---
### IS31FL3733 :id=is31fl3733
@@ -134,7 +134,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
}
```
-Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` for now).
+Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/led/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` for now).
---
### IS31FL3737 :id=is31fl3737
@@ -198,7 +198,7 @@ const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
}
```
-Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3737.pdf) and the header file `drivers/issi/is31fl3737.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0`, `1` for now).
+Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3737.pdf) and the header file `drivers/led/issi/is31fl3737.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0`, `1` for now).
---
diff --git a/docs/ja/feature_led_matrix.md b/docs/ja/feature_led_matrix.md
index 62e22859fb..f132d716f6 100644
--- a/docs/ja/feature_led_matrix.md
+++ b/docs/ja/feature_led_matrix.md
@@ -61,7 +61,7 @@ I2C IS31FL3731 RGB コントローラを使ったアドレス指定可能な LED
....
}
-ここで、`Cx_y` は[データシート](https://www.issi.com/WW/pdf/31FL3731.pdf)およびヘッダファイル `drivers/issi/is31fl3731-simple.h` で定義されるマトリックス内の LED の位置です。`driver` は `config.h` で定義したドライバのインデックス(`0`、`1`、`2`、`3`のいずれか)です。
+ここで、`Cx_y` は[データシート](https://www.issi.com/WW/pdf/31FL3731.pdf)およびヘッダファイル `drivers/led/issi/is31fl3731-simple.h` で定義されるマトリックス内の LED の位置です。`driver` は `config.h` で定義したドライバのインデックス(`0`、`1`、`2`、`3`のいずれか)です。
## キーコード
diff --git a/drivers/apa102/apa102.c b/drivers/apa102/apa102.c
deleted file mode 100644
index 7396dc3c55..0000000000
--- a/drivers/apa102/apa102.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/* Copyright 2020 Aldehir Rojas
- * Copyright 2017 Mikkel (Duckle29)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "apa102.h"
-#include "quantum.h"
-
-#ifndef APA102_NOPS
-# if defined(__AVR__)
-# define APA102_NOPS 0 // AVR at 16 MHz already spends 62.5 ns per clock, so no extra delay is needed
-# elif defined(PROTOCOL_CHIBIOS)
-
-# include "hal.h"
-# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX)
-# define APA102_NOPS (100 / (1000000000L / (STM32_SYSCLK / 4))) // This calculates how many loops of 4 nops to run to delay 100 ns
-# else
-# error("APA102_NOPS configuration required")
-# define APA102_NOPS 0 // this just pleases the compile so the above error is easier to spot
-# endif
-# endif
-#endif
-
-#define io_wait \
- do { \
- for (int i = 0; i < APA102_NOPS; i++) { \
- __asm__ volatile("nop\n\t" \
- "nop\n\t" \
- "nop\n\t" \
- "nop\n\t"); \
- } \
- } while (0)
-
-#define APA102_SEND_BIT(byte, bit) \
- do { \
- writePin(RGB_DI_PIN, (byte >> bit) & 1); \
- io_wait; \
- writePinHigh(RGB_CI_PIN); \
- io_wait; \
- writePinLow(RGB_CI_PIN); \
- io_wait; \
- } while (0)
-
-uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS;
-
-void static apa102_start_frame(void);
-void static apa102_end_frame(uint16_t num_leds);
-
-void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness);
-void static apa102_send_byte(uint8_t byte);
-
-void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds) {
- LED_TYPE *end = start_led + num_leds;
-
- apa102_start_frame();
- for (LED_TYPE *led = start_led; led < end; led++) {
- apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness);
- }
- apa102_end_frame(num_leds);
-}
-
-// Overwrite the default rgblight_call_driver to use apa102 driver
-void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { apa102_setleds(start_led, num_leds); }
-
-void static apa102_init(void) {
- setPinOutput(RGB_DI_PIN);
- setPinOutput(RGB_CI_PIN);
-
- writePinLow(RGB_DI_PIN);
- writePinLow(RGB_CI_PIN);
-}
-
-void apa102_set_brightness(uint8_t brightness) {
- if (brightness > APA102_MAX_BRIGHTNESS) {
- apa102_led_brightness = APA102_MAX_BRIGHTNESS;
- } else if (brightness < 0) {
- apa102_led_brightness = 0;
- } else {
- apa102_led_brightness = brightness;
- }
-}
-
-void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness) {
- apa102_send_byte(0b11100000 | brightness);
- apa102_send_byte(blue);
- apa102_send_byte(green);
- apa102_send_byte(red);
-}
-
-void static apa102_start_frame(void) {
- apa102_init();
- for (uint16_t i = 0; i < 4; i++) {
- apa102_send_byte(0);
- }
-}
-
-void static apa102_end_frame(uint16_t num_leds) {
- // This function has been taken from: https://github.com/pololu/apa102-arduino/blob/master/APA102.h
- // and adapted. The code is MIT licensed. I think thats compatible?
- //
- // The data stream seen by the last LED in the chain will be delayed by
- // (count - 1) clock edges, because each LED before it inverts the clock
- // line and delays the data by one clock edge. Therefore, to make sure
- // the last LED actually receives the data we wrote, the number of extra
- // edges we send at the end of the frame must be at least (count - 1).
- //
- // Assuming we only want to send these edges in groups of size K, the
- // C/C++ expression for the minimum number of groups to send is:
- //
- // ((count - 1) + (K - 1)) / K
- //
- // The C/C++ expression above is just (count - 1) divided by K,
- // rounded up to the nearest whole number if there is a remainder.
- //
- // We set K to 16 and use the formula above as the number of frame-end
- // bytes to transfer. Each byte has 16 clock edges.
- //
- // We are ignoring the specification for the end frame in the APA102
- // datasheet, which says to send 0xFF four times, because it does not work
- // when you have 66 LEDs or more, and also it results in unwanted white
- // pixels if you try to update fewer LEDs than are on your LED strip.
- uint16_t iterations = (num_leds + 14) / 16;
- for (uint16_t i = 0; i < iterations; i++) {
- apa102_send_byte(0);
- }
-
- apa102_init();
-}
-
-void static apa102_send_byte(uint8_t byte) {
- APA102_SEND_BIT(byte, 7);
- APA102_SEND_BIT(byte, 6);
- APA102_SEND_BIT(byte, 5);
- APA102_SEND_BIT(byte, 4);
- APA102_SEND_BIT(byte, 3);
- APA102_SEND_BIT(byte, 2);
- APA102_SEND_BIT(byte, 1);
- APA102_SEND_BIT(byte, 0);
-}
diff --git a/drivers/apa102/apa102.h b/drivers/apa102/apa102.h
deleted file mode 100644
index 58cf020c1e..0000000000
--- a/drivers/apa102/apa102.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Copyright 2020 Aldehir Rojas
- * Copyright 2017 Mikkel (Duckle29)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include "color.h"
-
-#ifndef APA102_DEFAULT_BRIGHTNESS
-# define APA102_DEFAULT_BRIGHTNESS 31
-#endif
-
-#define APA102_MAX_BRIGHTNESS 31
-
-extern uint8_t apa102_led_brightness;
-
-/* User Interface
- *
- * Input:
- * start_led: An array of GRB data describing the LED colors
- * num_leds: The number of LEDs to write
- *
- * The functions will perform the following actions:
- * - Set the data-out pin as output
- * - Send out the LED data
- */
-void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds);
-void apa102_set_brightness(uint8_t brightness);
diff --git a/drivers/awinic/aw20216.c b/drivers/awinic/aw20216.c
deleted file mode 100644
index c608c0ab44..0000000000
--- a/drivers/awinic/aw20216.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/* Copyright 2021 Jasper Chan
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "aw20216.h"
-#include "spi_master.h"
-
-/* The AW20216 appears to be somewhat similar to the IS31FL743, although quite
- * a few things are different, such as the command byte format and page ordering.
- * The LED addresses start from 0x00 instead of 0x01.
- */
-#define AWINIC_ID 0b1010 << 4
-
-#define AW_PAGE_FUNCTION 0x00 << 1 // PG0, Function registers
-#define AW_PAGE_PWM 0x01 << 1 // PG1, LED PWM control
-#define AW_PAGE_SCALING 0x02 << 1 // PG2, LED current scaling control
-#define AW_PAGE_PATCHOICE 0x03 << 1 // PG3, Pattern choice?
-#define AW_PAGE_PWMSCALING 0x04 << 1 // PG4, LED PWM + Scaling control?
-
-#define AW_WRITE 0
-#define AW_READ 1
-
-#define AW_REG_CONFIGURATION 0x00 // PG0
-#define AW_REG_GLOBALCURRENT 0x01 // PG0
-
-// Default value of AW_REG_CONFIGURATION
-// D7:D4 = 1011, SWSEL (SW1~SW12 active)
-// D3 = 0?, reserved (apparently this should be 1 but it doesn't seem to matter)
-// D2:D1 = 00, OSDE (open/short detection enable)
-// D0 = 0, CHIPEN (write 1 to enable LEDs when hardware enable pulled high)
-#define AW_CONFIG_DEFAULT 0b10110000
-#define AW_CHIPEN 1
-
-#define AW_PWM_REGISTER_COUNT 216
-
-#ifndef AW_SCALING_MAX
-# define AW_SCALING_MAX 150
-#endif
-
-#ifndef AW_GLOBAL_CURRENT_MAX
-# define AW_GLOBAL_CURRENT_MAX 150
-#endif
-
-#ifndef AW_SPI_DIVISOR
-# define AW_SPI_DIVISOR 4
-#endif
-
-uint8_t g_pwm_buffer[DRIVER_COUNT][AW_PWM_REGISTER_COUNT];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
-
-bool AW20216_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8_t len) {
- static uint8_t s_spi_transfer_buffer[2] = {0};
-
- if (!spi_start(cs_pin, false, 0, AW_SPI_DIVISOR)) {
- spi_stop();
- return false;
- }
-
- s_spi_transfer_buffer[0] = (AWINIC_ID | page | AW_WRITE);
- s_spi_transfer_buffer[1] = reg;
-
- if (spi_transmit(s_spi_transfer_buffer, 2) != SPI_STATUS_SUCCESS) {
- spi_stop();
- return false;
- }
-
- if (spi_transmit(data, len) != SPI_STATUS_SUCCESS) {
- spi_stop();
- return false;
- }
-
- spi_stop();
- return true;
-}
-
-static inline bool AW20216_write_register(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t value) {
- // Little wrapper so callers need not care about sending a buffer
- return AW20216_write(cs_pin, page, reg, &value, 1);
-}
-
-static void AW20216_init_scaling(pin_t cs_pin) {
- // Set constant current to the max, control brightness with PWM
- for (uint8_t i = 0; i < AW_PWM_REGISTER_COUNT; i++) {
- AW20216_write_register(cs_pin, AW_PAGE_SCALING, i, AW_SCALING_MAX);
- }
-}
-
-static inline void AW20216_init_current_limit(pin_t cs_pin) {
- // Push config
- AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX);
-}
-
-static inline void AW20216_soft_enable(pin_t cs_pin) {
- // Push config
- AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN);
-}
-
-void AW20216_init(pin_t cs_pin, pin_t en_pin) {
- setPinOutput(en_pin);
- writePinHigh(en_pin);
-
- // Drivers should start with all scaling and PWM registers as off
- AW20216_init_current_limit(cs_pin);
- AW20216_init_scaling(cs_pin);
-
- AW20216_soft_enable(cs_pin);
-}
-
-void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- aw_led led = g_aw_leds[index];
-
- g_pwm_buffer[led.driver][led.r] = red;
- g_pwm_buffer[led.driver][led.g] = green;
- g_pwm_buffer[led.driver][led.b] = blue;
- g_pwm_buffer_update_required[led.driver] = true;
-}
-
-void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- AW20216_set_color(i, red, green, blue);
- }
-}
-
-void AW20216_update_pwm_buffers(pin_t cs_pin, uint8_t index) {
- if (g_pwm_buffer_update_required[index]) {
- AW20216_write(cs_pin, AW_PAGE_PWM, 0, g_pwm_buffer[index], AW_PWM_REGISTER_COUNT);
- }
- g_pwm_buffer_update_required[index] = false;
-}
diff --git a/drivers/awinic/aw20216.h b/drivers/awinic/aw20216.h
deleted file mode 100644
index c55d9605fc..0000000000
--- a/drivers/awinic/aw20216.h
+++ /dev/null
@@ -1,252 +0,0 @@
-/* Copyright 2021 Jasper Chan (Gigahawk)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-#include "gpio.h"
-
-typedef struct aw_led {
- uint8_t driver : 2;
- uint8_t r;
- uint8_t g;
- uint8_t b;
-} aw_led;
-
-extern const aw_led g_aw_leds[DRIVER_LED_TOTAL];
-
-void AW20216_init(pin_t cs_pin, pin_t en_pin);
-void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
-void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-void AW20216_update_pwm_buffers(pin_t cs_pin, uint8_t index);
-
-#define CS1_SW1 0x00
-#define CS2_SW1 0x01
-#define CS3_SW1 0x02
-#define CS4_SW1 0x03
-#define CS5_SW1 0x04
-#define CS6_SW1 0x05
-#define CS7_SW1 0x06
-#define CS8_SW1 0x07
-#define CS9_SW1 0x08
-#define CS10_SW1 0x09
-#define CS11_SW1 0x0A
-#define CS12_SW1 0x0B
-#define CS13_SW1 0x0C
-#define CS14_SW1 0x0D
-#define CS15_SW1 0x0E
-#define CS16_SW1 0x0F
-#define CS17_SW1 0x10
-#define CS18_SW1 0x11
-#define CS1_SW2 0x12
-#define CS2_SW2 0x13
-#define CS3_SW2 0x14
-#define CS4_SW2 0x15
-#define CS5_SW2 0x16
-#define CS6_SW2 0x17
-#define CS7_SW2 0x18
-#define CS8_SW2 0x19
-#define CS9_SW2 0x1A
-#define CS10_SW2 0x1B
-#define CS11_SW2 0x1C
-#define CS12_SW2 0x1D
-#define CS13_SW2 0x1E
-#define CS14_SW2 0x1F
-#define CS15_SW2 0x20
-#define CS16_SW2 0x21
-#define CS17_SW2 0x22
-#define CS18_SW2 0x23
-#define CS1_SW3 0x24
-#define CS2_SW3 0x25
-#define CS3_SW3 0x26
-#define CS4_SW3 0x27
-#define CS5_SW3 0x28
-#define CS6_SW3 0x29
-#define CS7_SW3 0x2A
-#define CS8_SW3 0x2B
-#define CS9_SW3 0x2C
-#define CS10_SW3 0x2D
-#define CS11_SW3 0x2E
-#define CS12_SW3 0x2F
-#define CS13_SW3 0x30
-#define CS14_SW3 0x31
-#define CS15_SW3 0x32
-#define CS16_SW3 0x33
-#define CS17_SW3 0x34
-#define CS18_SW3 0x35
-#define CS1_SW4 0x36
-#define CS2_SW4 0x37
-#define CS3_SW4 0x38
-#define CS4_SW4 0x39
-#define CS5_SW4 0x3A
-#define CS6_SW4 0x3B
-#define CS7_SW4 0x3C
-#define CS8_SW4 0x3D
-#define CS9_SW4 0x3E
-#define CS10_SW4 0x3F
-#define CS11_SW4 0x40
-#define CS12_SW4 0x41
-#define CS13_SW4 0x42
-#define CS14_SW4 0x43
-#define CS15_SW4 0x44
-#define CS16_SW4 0x45
-#define CS17_SW4 0x46
-#define CS18_SW4 0x47
-#define CS1_SW5 0x48
-#define CS2_SW5 0x49
-#define CS3_SW5 0x4A
-#define CS4_SW5 0x4B
-#define CS5_SW5 0x4C
-#define CS6_SW5 0x4D
-#define CS7_SW5 0x4E
-#define CS8_SW5 0x4F
-#define CS9_SW5 0x50
-#define CS10_SW5 0x51
-#define CS11_SW5 0x52
-#define CS12_SW5 0x53
-#define CS13_SW5 0x54
-#define CS14_SW5 0x55
-#define CS15_SW5 0x56
-#define CS16_SW5 0x57
-#define CS17_SW5 0x58
-#define CS18_SW5 0x59
-#define CS1_SW6 0x5A
-#define CS2_SW6 0x5B
-#define CS3_SW6 0x5C
-#define CS4_SW6 0x5D
-#define CS5_SW6 0x5E
-#define CS6_SW6 0x5F
-#define CS7_SW6 0x60
-#define CS8_SW6 0x61
-#define CS9_SW6 0x62
-#define CS10_SW6 0x63
-#define CS11_SW6 0x64
-#define CS12_SW6 0x65
-#define CS13_SW6 0x66
-#define CS14_SW6 0x67
-#define CS15_SW6 0x68
-#define CS16_SW6 0x69
-#define CS17_SW6 0x6A
-#define CS18_SW6 0x6B
-#define CS1_SW7 0x6C
-#define CS2_SW7 0x6D
-#define CS3_SW7 0x6E
-#define CS4_SW7 0x6F
-#define CS5_SW7 0x70
-#define CS6_SW7 0x71
-#define CS7_SW7 0x72
-#define CS8_SW7 0x73
-#define CS9_SW7 0x74
-#define CS10_SW7 0x75
-#define CS11_SW7 0x76
-#define CS12_SW7 0x77
-#define CS13_SW7 0x78
-#define CS14_SW7 0x79
-#define CS15_SW7 0x7A
-#define CS16_SW7 0x7B
-#define CS17_SW7 0x7C
-#define CS18_SW7 0x7D
-#define CS1_SW8 0x7E
-#define CS2_SW8 0x7F
-#define CS3_SW8 0x80
-#define CS4_SW8 0x81
-#define CS5_SW8 0x82
-#define CS6_SW8 0x83
-#define CS7_SW8 0x84
-#define CS8_SW8 0x85
-#define CS9_SW8 0x86
-#define CS10_SW8 0x87
-#define CS11_SW8 0x88
-#define CS12_SW8 0x89
-#define CS13_SW8 0x8A
-#define CS14_SW8 0x8B
-#define CS15_SW8 0x8C
-#define CS16_SW8 0x8D
-#define CS17_SW8 0x8E
-#define CS18_SW8 0x8F
-#define CS1_SW9 0x90
-#define CS2_SW9 0x91
-#define CS3_SW9 0x92
-#define CS4_SW9 0x93
-#define CS5_SW9 0x94
-#define CS6_SW9 0x95
-#define CS7_SW9 0x96
-#define CS8_SW9 0x97
-#define CS9_SW9 0x98
-#define CS10_SW9 0x99
-#define CS11_SW9 0x9A
-#define CS12_SW9 0x9B
-#define CS13_SW9 0x9C
-#define CS14_SW9 0x9D
-#define CS15_SW9 0x9E
-#define CS16_SW9 0x9F
-#define CS17_SW9 0xA0
-#define CS18_SW9 0xA1
-#define CS1_SW10 0xA2
-#define CS2_SW10 0xA3
-#define CS3_SW10 0xA4
-#define CS4_SW10 0xA5
-#define CS5_SW10 0xA6
-#define CS6_SW10 0xA7
-#define CS7_SW10 0xA8
-#define CS8_SW10 0xA9
-#define CS9_SW10 0xAA
-#define CS10_SW10 0xAB
-#define CS11_SW10 0xAC
-#define CS12_SW10 0xAD
-#define CS13_SW10 0xAE
-#define CS14_SW10 0xAF
-#define CS15_SW10 0xB0
-#define CS16_SW10 0xB1
-#define CS17_SW10 0xB2
-#define CS18_SW10 0xB3
-#define CS1_SW11 0xB4
-#define CS2_SW11 0xB5
-#define CS3_SW11 0xB6
-#define CS4_SW11 0xB7
-#define CS5_SW11 0xB8
-#define CS6_SW11 0xB9
-#define CS7_SW11 0xBA
-#define CS8_SW11 0xBB
-#define CS9_SW11 0xBC
-#define CS10_SW11 0xBD
-#define CS11_SW11 0xBE
-#define CS12_SW11 0xBF
-#define CS13_SW11 0xC0
-#define CS14_SW11 0xC1
-#define CS15_SW11 0xC2
-#define CS16_SW11 0xC3
-#define CS17_SW11 0xC4
-#define CS18_SW11 0xC5
-#define CS1_SW12 0xC6
-#define CS2_SW12 0xC7
-#define CS3_SW12 0xC8
-#define CS4_SW12 0xC9
-#define CS5_SW12 0xCA
-#define CS6_SW12 0xCB
-#define CS7_SW12 0xCC
-#define CS8_SW12 0xCD
-#define CS9_SW12 0xCE
-#define CS10_SW12 0xCF
-#define CS11_SW12 0xD0
-#define CS12_SW12 0xD1
-#define CS13_SW12 0xD2
-#define CS14_SW12 0xD3
-#define CS15_SW12 0xD4
-#define CS16_SW12 0xD5
-#define CS17_SW12 0xD6
-#define CS18_SW12 0xD7
diff --git a/drivers/issi/is31fl3218.c b/drivers/issi/is31fl3218.c
deleted file mode 100644
index d43863ac4b..0000000000
--- a/drivers/issi/is31fl3218.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Copyright 2018 Jason Williams (Wilba)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-#include "is31fl3218.h"
-#include "i2c_master.h"
-
-// This is the full 8-bit address
-#define ISSI_ADDRESS 0b10101000
-
-// These are the register addresses
-#define ISSI_REG_SHUTDOWN 0x00
-#define ISSI_REG_PWM 0x01
-#define ISSI_REG_CONTROL 0x13
-#define ISSI_REG_UPDATE 0x16
-#define ISSI_REG_RESET 0x17
-
-// Default timeout if no I2C response
-#define ISSI_TIMEOUT 100
-
-// Reusable buffer for transfers
-uint8_t g_twi_transfer_buffer[20];
-
-// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
-// If used as RGB LED driver, LEDs are assigned RGB,RGB,RGB,RGB,RGB,RGB
-uint8_t g_pwm_buffer[18];
-bool g_pwm_buffer_update_required = false;
-
-void IS31FL3218_write_register(uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
- i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-}
-
-void IS31FL3218_write_pwm_buffer(uint8_t *pwm_buffer) {
- g_twi_transfer_buffer[0] = ISSI_REG_PWM;
- for (int i = 0; i < 18; i++) {
- g_twi_transfer_buffer[1 + i] = pwm_buffer[i];
- }
-
- i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT);
-}
-
-void IS31FL3218_init(void) {
- // In case we ever want to reinitialize (?)
- IS31FL3218_write_register(ISSI_REG_RESET, 0x00);
-
- // Turn off software shutdown
- IS31FL3218_write_register(ISSI_REG_SHUTDOWN, 0x01);
-
- // Set all PWM values to zero
- for (uint8_t i = 0; i < 18; i++) {
- IS31FL3218_write_register(ISSI_REG_PWM + i, 0x00);
- }
-
- // Enable all channels
- for (uint8_t i = 0; i < 3; i++) {
- IS31FL3218_write_register(ISSI_REG_CONTROL + i, 0b00111111);
- }
-
- // Load PWM registers and LED Control register data
- IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01);
-}
-
-void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- g_pwm_buffer[index * 3 + 0] = red;
- g_pwm_buffer[index * 3 + 1] = green;
- g_pwm_buffer[index * 3 + 2] = blue;
- g_pwm_buffer_update_required = true;
-}
-
-void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
- for (int i = 0; i < 6; i++) {
- IS31FL3218_set_color(i, red, green, blue);
- }
-}
-
-void IS31FL3218_update_pwm_buffers(void) {
- if (g_pwm_buffer_update_required) {
- IS31FL3218_write_pwm_buffer(g_pwm_buffer);
- // Load PWM registers and LED Control register data
- IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01);
- }
- g_pwm_buffer_update_required = false;
-}
diff --git a/drivers/issi/is31fl3218.h b/drivers/issi/is31fl3218.h
deleted file mode 100644
index fa760da191..0000000000
--- a/drivers/issi/is31fl3218.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Copyright 2018 Jason Williams (Wilba)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-
-void IS31FL3218_init(void);
-void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL3218_update_pwm_buffers(void);
diff --git a/drivers/issi/is31fl3731-simple.c b/drivers/issi/is31fl3731-simple.c
deleted file mode 100644
index d295772f5e..0000000000
--- a/drivers/issi/is31fl3731-simple.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2019 Clueboard
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "is31fl3731-simple.h"
-#include "i2c_master.h"
-#include "wait.h"
-
-// This is a 7-bit address, that gets left-shifted and bit 0
-// set to 0 for write, 1 for read (as per I2C protocol)
-// The address will vary depending on your wiring:
-// 0b1110100 AD <-> GND
-// 0b1110111 AD <-> VCC
-// 0b1110101 AD <-> SCL
-// 0b1110110 AD <-> SDA
-#define ISSI_ADDR_DEFAULT 0x74
-
-#define ISSI_REG_CONFIG 0x00
-#define ISSI_REG_CONFIG_PICTUREMODE 0x00
-#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08
-#define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18
-
-#define ISSI_CONF_PICTUREMODE 0x00
-#define ISSI_CONF_AUTOFRAMEMODE 0x04
-#define ISSI_CONF_AUDIOMODE 0x08
-
-#define ISSI_REG_PICTUREFRAME 0x01
-
-#define ISSI_REG_SHUTDOWN 0x0A
-#define ISSI_REG_AUDIOSYNC 0x06
-
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
-
-#ifndef ISSI_TIMEOUT
-# define ISSI_TIMEOUT 100
-#endif
-
-#ifndef ISSI_PERSISTENCE
-# define ISSI_PERSISTENCE 0
-#endif
-
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
-// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
-// Storing them like this is optimal for I2C transfers to the registers.
-// We could optimize this and take out the unused registers from these
-// buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's
-// probably not worth the extra complexity.
-uint8_t g_pwm_buffer[LED_DRIVER_COUNT][144];
-bool g_pwm_buffer_update_required[LED_DRIVER_COUNT] = {false};
-
-/* There's probably a better way to init this... */
-#if LED_DRIVER_COUNT == 1
-uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}};
-#elif LED_DRIVER_COUNT == 2
-uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}};
-#elif LED_DRIVER_COUNT == 3
-uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}};
-#elif LED_DRIVER_COUNT == 4
-uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}, {0}};
-#endif
-bool g_led_control_registers_update_required[LED_DRIVER_COUNT] = {false};
-
-// This is the bit pattern in the LED control registers
-// (for matrix A, add one to register for matrix B)
-//
-// reg - b7 b6 b5 b4 b3 b2 b1 b0
-// 0x00 - R08,R07,R06,R05,R04,R03,R02,R01
-// 0x02 - G08,G07,G06,G05,G04,G03,G02,R00
-// 0x04 - B08,B07,B06,B05,B04,B03,G01,G00
-// 0x06 - - , - , - , - , - ,B02,B01,B00
-// 0x08 - - , - , - , - , - , - , - , -
-// 0x0A - B17,B16,B15, - , - , - , - , -
-// 0x0C - G17,G16,B14,B13,B12,B11,B10,B09
-// 0x0E - R17,G15,G14,G13,G12,G11,G10,G09
-// 0x10 - R16,R15,R14,R13,R12,R11,R10,R09
-
-void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) {
- break;
- }
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-#endif
-}
-
-void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes bank is already selected
-
- // transmit PWM registers in 9 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
-
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < 144; i += 16) {
- // set the first register, e.g. 0x24, 0x34, 0x44, etc.
- g_twi_transfer_buffer[0] = 0x24 + i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer
- for (int j = 0; j < 16; j++) {
- g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
- }
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-#endif
- }
-}
-
-void IS31FL3731_init(uint8_t addr) {
- // In order to avoid the LEDs being driven with garbage data
- // in the LED driver's PWM registers, first enable software shutdown,
- // then set up the mode and other settings, clear the PWM registers,
- // then disable software shutdown.
-
- // select "function register" bank
- IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
-
- // enable software shutdown
- IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00);
-
- // this delay was copied from other drivers, might not be needed
- wait_ms(10);
-
- // picture mode
- IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE);
- // display frame 0
- IS31FL3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00);
- // audio sync off
- IS31FL3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00);
-
- // select bank 0
- IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
-
- // turn off all LEDs in the LED control register
- for (int i = 0x00; i <= 0x11; i++) {
- IS31FL3731_write_register(addr, i, 0x00);
- }
-
- // turn off all LEDs in the blink control register (not really needed)
- for (int i = 0x12; i <= 0x23; i++) {
- IS31FL3731_write_register(addr, i, 0x00);
- }
-
- // set PWM on all LEDs to 0
- for (int i = 0x24; i <= 0xB3; i++) {
- IS31FL3731_write_register(addr, i, 0x00);
- }
-
- // select "function register" bank
- IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
-
- // disable software shutdown
- IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01);
-
- // select bank 0 and leave it selected.
- // most usage after initialization is just writing PWM buffers in bank 0
- // as there's not much point in double-buffering
- IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
-}
-
-void IS31FL3731_set_value(int index, uint8_t value) {
- if (index >= 0 && index < DRIVER_LED_TOTAL) {
- is31_led led = g_is31_leds[index];
-
- // Subtract 0x24 to get the second index of g_pwm_buffer
- g_pwm_buffer[led.driver][led.v - 0x24] = value;
- g_pwm_buffer_update_required[led.driver] = true;
- }
-}
-
-void IS31FL3731_set_value_all(uint8_t value) {
- for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
- IS31FL3731_set_value(i, value);
- }
-}
-
-void IS31FL3731_set_led_control_register(uint8_t index, bool value) {
- is31_led led = g_is31_leds[index];
-
- uint8_t control_register = (led.v - 0x24) / 8;
- uint8_t bit_value = (led.v - 0x24) % 8;
-
- if (value) {
- g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
- } else {
- g_led_control_registers[led.driver][control_register] &= ~(1 << bit_value);
- }
-
- g_led_control_registers_update_required[led.driver] = true;
-}
-
-void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
- if (g_pwm_buffer_update_required[index]) {
- IS31FL3731_write_pwm_buffer(addr, g_pwm_buffer[index]);
- g_pwm_buffer_update_required[index] = false;
- }
-}
-
-void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index) {
- if (g_led_control_registers_update_required[index]) {
- for (int i = 0; i < 18; i++) {
- IS31FL3731_write_register(addr, i, g_led_control_registers[index][i]);
- }
- g_led_control_registers_update_required[index] = false;
- }
-}
diff --git a/drivers/issi/is31fl3731-simple.h b/drivers/issi/is31fl3731-simple.h
deleted file mode 100644
index 9665d6ed35..0000000000
--- a/drivers/issi/is31fl3731-simple.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2019 Clueboard
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-
-typedef struct is31_led {
- uint8_t driver : 2;
- uint8_t v;
-} __attribute__((packed)) is31_led;
-
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
-
-void IS31FL3731_init(uint8_t addr);
-void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
-
-void IS31FL3731_set_value(int index, uint8_t value);
-void IS31FL3731_set_value_all(uint8_t value);
-
-void IS31FL3731_set_led_control_register(uint8_t index, bool value);
-
-// This should not be called from an interrupt
-// (eg. from a timer interrupt).
-// Call this while idle (in between matrix scans).
-// If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index);
-void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
-
-#define C1_1 0x24
-#define C1_2 0x25
-#define C1_3 0x26
-#define C1_4 0x27
-#define C1_5 0x28
-#define C1_6 0x29
-#define C1_7 0x2A
-#define C1_8 0x2B
-
-#define C1_9 0x2C
-#define C1_10 0x2D
-#define C1_11 0x2E
-#define C1_12 0x2F
-#define C1_13 0x30
-#define C1_14 0x31
-#define C1_15 0x32
-#define C1_16 0x33
-
-#define C2_1 0x34
-#define C2_2 0x35
-#define C2_3 0x36
-#define C2_4 0x37
-#define C2_5 0x38
-#define C2_6 0x39
-#define C2_7 0x3A
-#define C2_8 0x3B
-
-#define C2_9 0x3C
-#define C2_10 0x3D
-#define C2_11 0x3E
-#define C2_12 0x3F
-#define C2_13 0x40
-#define C2_14 0x41
-#define C2_15 0x42
-#define C2_16 0x43
-
-#define C3_1 0x44
-#define C3_2 0x45
-#define C3_3 0x46
-#define C3_4 0x47
-#define C3_5 0x48
-#define C3_6 0x49
-#define C3_7 0x4A
-#define C3_8 0x4B
-
-#define C3_9 0x4C
-#define C3_10 0x4D
-#define C3_11 0x4E
-#define C3_12 0x4F
-#define C3_13 0x50
-#define C3_14 0x51
-#define C3_15 0x52
-#define C3_16 0x53
-
-#define C4_1 0x54
-#define C4_2 0x55
-#define C4_3 0x56
-#define C4_4 0x57
-#define C4_5 0x58
-#define C4_6 0x59
-#define C4_7 0x5A
-#define C4_8 0x5B
-
-#define C4_9 0x5C
-#define C4_10 0x5D
-#define C4_11 0x5E
-#define C4_12 0x5F
-#define C4_13 0x60
-#define C4_14 0x61
-#define C4_15 0x62
-#define C4_16 0x63
-
-#define C5_1 0x64
-#define C5_2 0x65
-#define C5_3 0x66
-#define C5_4 0x67
-#define C5_5 0x68
-#define C5_6 0x69
-#define C5_7 0x6A
-#define C5_8 0x6B
-
-#define C5_9 0x6C
-#define C5_10 0x6D
-#define C5_11 0x6E
-#define C5_12 0x6F
-#define C5_13 0x70
-#define C5_14 0x71
-#define C5_15 0x72
-#define C5_16 0x73
-
-#define C6_1 0x74
-#define C6_2 0x75
-#define C6_3 0x76
-#define C6_4 0x77
-#define C6_5 0x78
-#define C6_6 0x79
-#define C6_7 0x7A
-#define C6_8 0x7B
-
-#define C6_9 0x7C
-#define C6_10 0x7D
-#define C6_11 0x7E
-#define C6_12 0x7F
-#define C6_13 0x80
-#define C6_14 0x81
-#define C6_15 0x82
-#define C6_16 0x83
-
-#define C7_1 0x84
-#define C7_2 0x85
-#define C7_3 0x86
-#define C7_4 0x87
-#define C7_5 0x88
-#define C7_6 0x89
-#define C7_7 0x8A
-#define C7_8 0x8B
-
-#define C7_9 0x8C
-#define C7_10 0x8D
-#define C7_11 0x8E
-#define C7_12 0x8F
-#define C7_13 0x90
-#define C7_14 0x91
-#define C7_15 0x92
-#define C7_16 0x93
-
-#define C8_1 0x94
-#define C8_2 0x95
-#define C8_3 0x96
-#define C8_4 0x97
-#define C8_5 0x98
-#define C8_6 0x99
-#define C8_7 0x9A
-#define C8_8 0x9B
-
-#define C8_9 0x9C
-#define C8_10 0x9D
-#define C8_11 0x9E
-#define C8_12 0x9F
-#define C8_13 0xA0
-#define C8_14 0xA1
-#define C8_15 0xA2
-#define C8_16 0xA3
-
-#define C9_1 0xA4
-#define C9_2 0xA5
-#define C9_3 0xA6
-#define C9_4 0xA7
-#define C9_5 0xA8
-#define C9_6 0xA9
-#define C9_7 0xAA
-#define C9_8 0xAB
-
-#define C9_9 0xAC
-#define C9_10 0xAD
-#define C9_11 0xAE
-#define C9_12 0xAF
-#define C9_13 0xB0
-#define C9_14 0xB1
-#define C9_15 0xB2
-#define C9_16 0xB3
diff --git a/drivers/issi/is31fl3731.c b/drivers/issi/is31fl3731.c
deleted file mode 100644
index 110bdc1be4..0000000000
--- a/drivers/issi/is31fl3731.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "is31fl3731.h"
-#include "i2c_master.h"
-#include "wait.h"
-
-// This is a 7-bit address, that gets left-shifted and bit 0
-// set to 0 for write, 1 for read (as per I2C protocol)
-// The address will vary depending on your wiring:
-// 0b1110100 AD <-> GND
-// 0b1110111 AD <-> VCC
-// 0b1110101 AD <-> SCL
-// 0b1110110 AD <-> SDA
-#define ISSI_ADDR_DEFAULT 0x74
-
-#define ISSI_REG_CONFIG 0x00
-#define ISSI_REG_CONFIG_PICTUREMODE 0x00
-#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08
-#define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18
-
-#define ISSI_CONF_PICTUREMODE 0x00
-#define ISSI_CONF_AUTOFRAMEMODE 0x04
-#define ISSI_CONF_AUDIOMODE 0x08
-
-#define ISSI_REG_PICTUREFRAME 0x01
-
-#define ISSI_REG_SHUTDOWN 0x0A
-#define ISSI_REG_AUDIOSYNC 0x06
-
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
-
-#ifndef ISSI_TIMEOUT
-# define ISSI_TIMEOUT 100
-#endif
-
-#ifndef ISSI_PERSISTENCE
-# define ISSI_PERSISTENCE 0
-#endif
-
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
-// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
-// Storing them like this is optimal for I2C transfers to the registers.
-// We could optimize this and take out the unused registers from these
-// buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's
-// probably not worth the extra complexity.
-uint8_t g_pwm_buffer[DRIVER_COUNT][144];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
-
-uint8_t g_led_control_registers[DRIVER_COUNT][18] = {{0}};
-bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
-
-// This is the bit pattern in the LED control registers
-// (for matrix A, add one to register for matrix B)
-//
-// reg - b7 b6 b5 b4 b3 b2 b1 b0
-// 0x00 - R08,R07,R06,R05,R04,R03,R02,R01
-// 0x02 - G08,G07,G06,G05,G04,G03,G02,R00
-// 0x04 - B08,B07,B06,B05,B04,B03,G01,G00
-// 0x06 - - , - , - , - , - ,B02,B01,B00
-// 0x08 - - , - , - , - , - , - , - , -
-// 0x0A - B17,B16,B15, - , - , - , - , -
-// 0x0C - G17,G16,B14,B13,B12,B11,B10,B09
-// 0x0E - R17,G15,G14,G13,G12,G11,G10,G09
-// 0x10 - R16,R15,R14,R13,R12,R11,R10,R09
-
-void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-#endif
-}
-
-void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes bank is already selected
-
- // transmit PWM registers in 9 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
-
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < 144; i += 16) {
- // set the first register, e.g. 0x24, 0x34, 0x44, etc.
- g_twi_transfer_buffer[0] = 0x24 + i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer
- for (int j = 0; j < 16; j++) {
- g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
- }
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-#endif
- }
-}
-
-void IS31FL3731_init(uint8_t addr) {
- // In order to avoid the LEDs being driven with garbage data
- // in the LED driver's PWM registers, first enable software shutdown,
- // then set up the mode and other settings, clear the PWM registers,
- // then disable software shutdown.
-
- // select "function register" bank
- IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
-
- // enable software shutdown
- IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00);
-
- // this delay was copied from other drivers, might not be needed
- wait_ms(10);
-
- // picture mode
- IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE);
- // display frame 0
- IS31FL3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00);
- // audio sync off
- IS31FL3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00);
-
- // select bank 0
- IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
-
- // turn off all LEDs in the LED control register
- for (int i = 0x00; i <= 0x11; i++) {
- IS31FL3731_write_register(addr, i, 0x00);
- }
-
- // turn off all LEDs in the blink control register (not really needed)
- for (int i = 0x12; i <= 0x23; i++) {
- IS31FL3731_write_register(addr, i, 0x00);
- }
-
- // set PWM on all LEDs to 0
- for (int i = 0x24; i <= 0xB3; i++) {
- IS31FL3731_write_register(addr, i, 0x00);
- }
-
- // select "function register" bank
- IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
-
- // disable software shutdown
- IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01);
-
- // select bank 0 and leave it selected.
- // most usage after initialization is just writing PWM buffers in bank 0
- // as there's not much point in double-buffering
- IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
-}
-
-void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- if (index >= 0 && index < DRIVER_LED_TOTAL) {
- is31_led led = g_is31_leds[index];
-
- // Subtract 0x24 to get the second index of g_pwm_buffer
- g_pwm_buffer[led.driver][led.r - 0x24] = red;
- g_pwm_buffer[led.driver][led.g - 0x24] = green;
- g_pwm_buffer[led.driver][led.b - 0x24] = blue;
- g_pwm_buffer_update_required[led.driver] = true;
- }
-}
-
-void IS31FL3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
- for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
- IS31FL3731_set_color(i, red, green, blue);
- }
-}
-
-void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
- is31_led led = g_is31_leds[index];
-
- uint8_t control_register_r = (led.r - 0x24) / 8;
- uint8_t control_register_g = (led.g - 0x24) / 8;
- uint8_t control_register_b = (led.b - 0x24) / 8;
- uint8_t bit_r = (led.r - 0x24) % 8;
- uint8_t bit_g = (led.g - 0x24) % 8;
- uint8_t bit_b = (led.b - 0x24) % 8;
-
- if (red) {
- g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
- } else {
- g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
- }
- if (green) {
- g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
- } else {
- g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
- }
- if (blue) {
- g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
- } else {
- g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
- }
-
- g_led_control_registers_update_required[led.driver] = true;
-}
-
-void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
- if (g_pwm_buffer_update_required[index]) {
- IS31FL3731_write_pwm_buffer(addr, g_pwm_buffer[index]);
- }
- g_pwm_buffer_update_required[index] = false;
-}
-
-void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index) {
- if (g_led_control_registers_update_required[index]) {
- for (int i = 0; i < 18; i++) {
- IS31FL3731_write_register(addr, i, g_led_control_registers[index][i]);
- }
- }
- g_led_control_registers_update_required[index] = false;
-}
diff --git a/drivers/issi/is31fl3731.h b/drivers/issi/is31fl3731.h
deleted file mode 100644
index 19e8e6251f..0000000000
--- a/drivers/issi/is31fl3731.h
+++ /dev/null
@@ -1,208 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-
-typedef struct is31_led {
- uint8_t driver : 2;
- uint8_t r;
- uint8_t g;
- uint8_t b;
-} __attribute__((packed)) is31_led;
-
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
-
-void IS31FL3731_init(uint8_t addr);
-void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
-
-void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-
-void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
-
-// This should not be called from an interrupt
-// (eg. from a timer interrupt).
-// Call this while idle (in between matrix scans).
-// If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index);
-void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
-
-#define C1_1 0x24
-#define C1_2 0x25
-#define C1_3 0x26
-#define C1_4 0x27
-#define C1_5 0x28
-#define C1_6 0x29
-#define C1_7 0x2A
-#define C1_8 0x2B
-
-#define C1_9 0x2C
-#define C1_10 0x2D
-#define C1_11 0x2E
-#define C1_12 0x2F
-#define C1_13 0x30
-#define C1_14 0x31
-#define C1_15 0x32
-#define C1_16 0x33
-
-#define C2_1 0x34
-#define C2_2 0x35
-#define C2_3 0x36
-#define C2_4 0x37
-#define C2_5 0x38
-#define C2_6 0x39
-#define C2_7 0x3A
-#define C2_8 0x3B
-
-#define C2_9 0x3C
-#define C2_10 0x3D
-#define C2_11 0x3E
-#define C2_12 0x3F
-#define C2_13 0x40
-#define C2_14 0x41
-#define C2_15 0x42
-#define C2_16 0x43
-
-#define C3_1 0x44
-#define C3_2 0x45
-#define C3_3 0x46
-#define C3_4 0x47
-#define C3_5 0x48
-#define C3_6 0x49
-#define C3_7 0x4A
-#define C3_8 0x4B
-
-#define C3_9 0x4C
-#define C3_10 0x4D
-#define C3_11 0x4E
-#define C3_12 0x4F
-#define C3_13 0x50
-#define C3_14 0x51
-#define C3_15 0x52
-#define C3_16 0x53
-
-#define C4_1 0x54
-#define C4_2 0x55
-#define C4_3 0x56
-#define C4_4 0x57
-#define C4_5 0x58
-#define C4_6 0x59
-#define C4_7 0x5A
-#define C4_8 0x5B
-
-#define C4_9 0x5C
-#define C4_10 0x5D
-#define C4_11 0x5E
-#define C4_12 0x5F
-#define C4_13 0x60
-#define C4_14 0x61
-#define C4_15 0x62
-#define C4_16 0x63
-
-#define C5_1 0x64
-#define C5_2 0x65
-#define C5_3 0x66
-#define C5_4 0x67
-#define C5_5 0x68
-#define C5_6 0x69
-#define C5_7 0x6A
-#define C5_8 0x6B
-
-#define C5_9 0x6C
-#define C5_10 0x6D
-#define C5_11 0x6E
-#define C5_12 0x6F
-#define C5_13 0x70
-#define C5_14 0x71
-#define C5_15 0x72
-#define C5_16 0x73
-
-#define C6_1 0x74
-#define C6_2 0x75
-#define C6_3 0x76
-#define C6_4 0x77
-#define C6_5 0x78
-#define C6_6 0x79
-#define C6_7 0x7A
-#define C6_8 0x7B
-
-#define C6_9 0x7C
-#define C6_10 0x7D
-#define C6_11 0x7E
-#define C6_12 0x7F
-#define C6_13 0x80
-#define C6_14 0x81
-#define C6_15 0x82
-#define C6_16 0x83
-
-#define C7_1 0x84
-#define C7_2 0x85
-#define C7_3 0x86
-#define C7_4 0x87
-#define C7_5 0x88
-#define C7_6 0x89
-#define C7_7 0x8A
-#define C7_8 0x8B
-
-#define C7_9 0x8C
-#define C7_10 0x8D
-#define C7_11 0x8E
-#define C7_12 0x8F
-#define C7_13 0x90
-#define C7_14 0x91
-#define C7_15 0x92
-#define C7_16 0x93
-
-#define C8_1 0x94
-#define C8_2 0x95
-#define C8_3 0x96
-#define C8_4 0x97
-#define C8_5 0x98
-#define C8_6 0x99
-#define C8_7 0x9A
-#define C8_8 0x9B
-
-#define C8_9 0x9C
-#define C8_10 0x9D
-#define C8_11 0x9E
-#define C8_12 0x9F
-#define C8_13 0xA0
-#define C8_14 0xA1
-#define C8_15 0xA2
-#define C8_16 0xA3
-
-#define C9_1 0xA4
-#define C9_2 0xA5
-#define C9_3 0xA6
-#define C9_4 0xA7
-#define C9_5 0xA8
-#define C9_6 0xA9
-#define C9_7 0xAA
-#define C9_8 0xAB
-
-#define C9_9 0xAC
-#define C9_10 0xAD
-#define C9_11 0xAE
-#define C9_12 0xAF
-#define C9_13 0xB0
-#define C9_14 0xB1
-#define C9_15 0xB2
-#define C9_16 0xB3
diff --git a/drivers/issi/is31fl3733.c b/drivers/issi/is31fl3733.c
deleted file mode 100644
index d99e5339c9..0000000000
--- a/drivers/issi/is31fl3733.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "is31fl3733.h"
-#include "i2c_master.h"
-#include "wait.h"
-
-// This is a 7-bit address, that gets left-shifted and bit 0
-// set to 0 for write, 1 for read (as per I2C protocol)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR1 represents A1:A0 of the 7-bit address.
-// ADDR2 represents A3:A2 of the 7-bit address.
-// The result is: 0b101(ADDR2)(ADDR1)
-#define ISSI_ADDR_DEFAULT 0x50
-
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_INTERRUPTMASKREGISTER 0xF0
-#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
-
-#define ISSI_PAGE_LEDCONTROL 0x00 // PG0
-#define ISSI_PAGE_PWM 0x01 // PG1
-#define ISSI_PAGE_AUTOBREATH 0x02 // PG2
-#define ISSI_PAGE_FUNCTION 0x03 // PG3
-
-#define ISSI_REG_CONFIGURATION 0x00 // PG3
-#define ISSI_REG_GLOBALCURRENT 0x01 // PG3
-#define ISSI_REG_RESET 0x11 // PG3
-#define ISSI_REG_SWPULLUP 0x0F // PG3
-#define ISSI_REG_CSPULLUP 0x10 // PG3
-
-#ifndef ISSI_TIMEOUT
-# define ISSI_TIMEOUT 100
-#endif
-
-#ifndef ISSI_PERSISTENCE
-# define ISSI_PERSISTENCE 0
-#endif
-
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
-// These buffers match the IS31FL3733 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
-// Storing them like this is optimal for I2C transfers to the registers.
-// We could optimize this and take out the unused registers from these
-// buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's
-// probably not worth the extra complexity.
-uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
-
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
-bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
-
-bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- // If the transaction fails function returns false.
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) {
- return false;
- }
- }
-#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) {
- return false;
- }
-#endif
- return true;
-}
-
-bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // Assumes PG1 is already selected.
- // If any of the transactions fails function returns false.
- // Transmit PWM registers in 12 transfers of 16 bytes.
- // g_twi_transfer_buffer[] is 20 bytes
-
- // Iterate over the pwm_buffer contents at 16 byte intervals.
- for (int i = 0; i < 192; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // Copy the data from i to i+15.
- // Device will auto-increment register for data after the first byte
- // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
- for (int j = 0; j < 16; j++) {
- g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
- }
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) {
- return false;
- }
- }
-#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) {
- return false;
- }
-#endif
- }
- return true;
-}
-
-void IS31FL3733_init(uint8_t addr, uint8_t sync) {
- // In order to avoid the LEDs being driven with garbage data
- // in the LED driver's PWM registers, shutdown is enabled last.
- // Set up the mode and other settings, clear the PWM registers,
- // then disable software shutdown.
- // Sync is passed so set it according to the datasheet.
-
- // Unlock the command register.
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG0
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
- // Turn off all LEDs.
- for (int i = 0x00; i <= 0x17; i++) {
- IS31FL3733_write_register(addr, i, 0x00);
- }
-
- // Unlock the command register.
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG1
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
- // Set PWM on all LEDs to 0
- // No need to setup Breath registers to PWM as that is the default.
- for (int i = 0x00; i <= 0xBF; i++) {
- IS31FL3733_write_register(addr, i, 0x00);
- }
-
- // Unlock the command register.
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG3
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
- // Set global current to maximum.
- IS31FL3733_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
- // Disable software shutdown.
- IS31FL3733_write_register(addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01);
-
- // Wait 10ms to ensure the device has woken up.
- wait_ms(10);
-}
-
-void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- if (index >= 0 && index < DRIVER_LED_TOTAL) {
- is31_led led = g_is31_leds[index];
-
- g_pwm_buffer[led.driver][led.r] = red;
- g_pwm_buffer[led.driver][led.g] = green;
- g_pwm_buffer[led.driver][led.b] = blue;
- g_pwm_buffer_update_required[led.driver] = true;
- }
-}
-
-void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
- for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
- IS31FL3733_set_color(i, red, green, blue);
- }
-}
-
-void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
- is31_led led = g_is31_leds[index];
-
- uint8_t control_register_r = led.r / 8;
- uint8_t control_register_g = led.g / 8;
- uint8_t control_register_b = led.b / 8;
- uint8_t bit_r = led.r % 8;
- uint8_t bit_g = led.g % 8;
- uint8_t bit_b = led.b % 8;
-
- if (red) {
- g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
- } else {
- g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
- }
- if (green) {
- g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
- } else {
- g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
- }
- if (blue) {
- g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
- } else {
- g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
- }
-
- g_led_control_registers_update_required[led.driver] = true;
-}
-
-void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
- if (g_pwm_buffer_update_required[index]) {
- // Firstly we need to unlock the command register and select PG1.
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
-
- // If any of the transactions fail we risk writing dirty PG0,
- // refresh page 0 just in case.
- if (!IS31FL3733_write_pwm_buffer(addr, g_pwm_buffer[index])) {
- g_led_control_registers_update_required[index] = true;
- }
- }
- g_pwm_buffer_update_required[index] = false;
-}
-
-void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index) {
- if (g_led_control_registers_update_required[index]) {
- // Firstly we need to unlock the command register and select PG0
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
- for (int i = 0; i < 24; i++) {
- IS31FL3733_write_register(addr, i, g_led_control_registers[index][i]);
- }
- }
- g_led_control_registers_update_required[index] = false;
-}
diff --git a/drivers/issi/is31fl3733.h b/drivers/issi/is31fl3733.h
deleted file mode 100644
index 603d505a13..0000000000
--- a/drivers/issi/is31fl3733.h
+++ /dev/null
@@ -1,251 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-
-typedef struct is31_led {
- uint8_t driver : 2;
- uint8_t r;
- uint8_t g;
- uint8_t b;
-} __attribute__((packed)) is31_led;
-
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
-
-void IS31FL3733_init(uint8_t addr, uint8_t sync);
-bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
-
-void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-
-void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
-
-// This should not be called from an interrupt
-// (eg. from a timer interrupt).
-// Call this while idle (in between matrix scans).
-// If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index);
-void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index);
-
-#define A_1 0x00
-#define A_2 0x01
-#define A_3 0x02
-#define A_4 0x03
-#define A_5 0x04
-#define A_6 0x05
-#define A_7 0x06
-#define A_8 0x07
-#define A_9 0x08
-#define A_10 0x09
-#define A_11 0x0A
-#define A_12 0x0B
-#define A_13 0x0C
-#define A_14 0x0D
-#define A_15 0x0E
-#define A_16 0x0F
-
-#define B_1 0x10
-#define B_2 0x11
-#define B_3 0x12
-#define B_4 0x13
-#define B_5 0x14
-#define B_6 0x15
-#define B_7 0x16
-#define B_8 0x17
-#define B_9 0x18
-#define B_10 0x19
-#define B_11 0x1A
-#define B_12 0x1B
-#define B_13 0x1C
-#define B_14 0x1D
-#define B_15 0x1E
-#define B_16 0x1F
-
-#define C_1 0x20
-#define C_2 0x21
-#define C_3 0x22
-#define C_4 0x23
-#define C_5 0x24
-#define C_6 0x25
-#define C_7 0x26
-#define C_8 0x27
-#define C_9 0x28
-#define C_10 0x29
-#define C_11 0x2A
-#define C_12 0x2B
-#define C_13 0x2C
-#define C_14 0x2D
-#define C_15 0x2E
-#define C_16 0x2F
-
-#define D_1 0x30
-#define D_2 0x31
-#define D_3 0x32
-#define D_4 0x33
-#define D_5 0x34
-#define D_6 0x35
-#define D_7 0x36
-#define D_8 0x37
-#define D_9 0x38
-#define D_10 0x39
-#define D_11 0x3A
-#define D_12 0x3B
-#define D_13 0x3C
-#define D_14 0x3D
-#define D_15 0x3E
-#define D_16 0x3F
-
-#define E_1 0x40
-#define E_2 0x41
-#define E_3 0x42
-#define E_4 0x43
-#define E_5 0x44
-#define E_6 0x45
-#define E_7 0x46
-#define E_8 0x47
-#define E_9 0x48
-#define E_10 0x49
-#define E_11 0x4A
-#define E_12 0x4B
-#define E_13 0x4C
-#define E_14 0x4D
-#define E_15 0x4E
-#define E_16 0x4F
-
-#define F_1 0x50
-#define F_2 0x51
-#define F_3 0x52
-#define F_4 0x53
-#define F_5 0x54
-#define F_6 0x55
-#define F_7 0x56
-#define F_8 0x57
-#define F_9 0x58
-#define F_10 0x59
-#define F_11 0x5A
-#define F_12 0x5B
-#define F_13 0x5C
-#define F_14 0x5D
-#define F_15 0x5E
-#define F_16 0x5F
-
-#define G_1 0x60
-#define G_2 0x61
-#define G_3 0x62
-#define G_4 0x63
-#define G_5 0x64
-#define G_6 0x65
-#define G_7 0x66
-#define G_8 0x67
-#define G_9 0x68
-#define G_10 0x69
-#define G_11 0x6A
-#define G_12 0x6B
-#define G_13 0x6C
-#define G_14 0x6D
-#define G_15 0x6E
-#define G_16 0x6F
-
-#define H_1 0x70
-#define H_2 0x71
-#define H_3 0x72
-#define H_4 0x73
-#define H_5 0x74
-#define H_6 0x75
-#define H_7 0x76
-#define H_8 0x77
-#define H_9 0x78
-#define H_10 0x79
-#define H_11 0x7A
-#define H_12 0x7B
-#define H_13 0x7C
-#define H_14 0x7D
-#define H_15 0x7E
-#define H_16 0x7F
-
-#define I_1 0x80
-#define I_2 0x81
-#define I_3 0x82
-#define I_4 0x83
-#define I_5 0x84
-#define I_6 0x85
-#define I_7 0x86
-#define I_8 0x87
-#define I_9 0x88
-#define I_10 0x89
-#define I_11 0x8A
-#define I_12 0x8B
-#define I_13 0x8C
-#define I_14 0x8D
-#define I_15 0x8E
-#define I_16 0x8F
-
-#define J_1 0x90
-#define J_2 0x91
-#define J_3 0x92
-#define J_4 0x93
-#define J_5 0x94
-#define J_6 0x95
-#define J_7 0x96
-#define J_8 0x97
-#define J_9 0x98
-#define J_10 0x99
-#define J_11 0x9A
-#define J_12 0x9B
-#define J_13 0x9C
-#define J_14 0x9D
-#define J_15 0x9E
-#define J_16 0x9F
-
-#define K_1 0xA0
-#define K_2 0xA1
-#define K_3 0xA2
-#define K_4 0xA3
-#define K_5 0xA4
-#define K_6 0xA5
-#define K_7 0xA6
-#define K_8 0xA7
-#define K_9 0xA8
-#define K_10 0xA9
-#define K_11 0xAA
-#define K_12 0xAB
-#define K_13 0xAC
-#define K_14 0xAD
-#define K_15 0xAE
-#define K_16 0xAF
-
-#define L_1 0xB0
-#define L_2 0xB1
-#define L_3 0xB2
-#define L_4 0xB3
-#define L_5 0xB4
-#define L_6 0xB5
-#define L_7 0xB6
-#define L_8 0xB7
-#define L_9 0xB8
-#define L_10 0xB9
-#define L_11 0xBA
-#define L_12 0xBB
-#define L_13 0xBC
-#define L_14 0xBD
-#define L_15 0xBE
-#define L_16 0xBF
diff --git a/drivers/issi/is31fl3736.c b/drivers/issi/is31fl3736.c
deleted file mode 100644
index 7dece1b1eb..0000000000
--- a/drivers/issi/is31fl3736.c
+++ /dev/null
@@ -1,269 +0,0 @@
-/* Copyright 2018 Jason Williams (Wilba)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "is31fl3736.h"
-#include "i2c_master.h"
-#include "wait.h"
-
-// This is a 7-bit address, that gets left-shifted and bit 0
-// set to 0 for write, 1 for read (as per I2C protocol)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR1 represents A1:A0 of the 7-bit address.
-// ADDR2 represents A3:A2 of the 7-bit address.
-// The result is: 0b101(ADDR2)(ADDR1)
-#define ISSI_ADDR_DEFAULT 0x50
-
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_INTERRUPTMASKREGISTER 0xF0
-#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
-
-#define ISSI_PAGE_LEDCONTROL 0x00 // PG0
-#define ISSI_PAGE_PWM 0x01 // PG1
-#define ISSI_PAGE_AUTOBREATH 0x02 // PG2
-#define ISSI_PAGE_FUNCTION 0x03 // PG3
-
-#define ISSI_REG_CONFIGURATION 0x00 // PG3
-#define ISSI_REG_GLOBALCURRENT 0x01 // PG3
-#define ISSI_REG_RESET 0x11 // PG3
-#define ISSI_REG_SWPULLUP 0x0F // PG3
-#define ISSI_REG_CSPULLUP 0x10 // PG3
-
-#ifndef ISSI_TIMEOUT
-# define ISSI_TIMEOUT 100
-#endif
-
-#ifndef ISSI_PERSISTENCE
-# define ISSI_PERSISTENCE 0
-#endif
-
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
-// These buffers match the IS31FL3736 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
-// Storing them like this is optimal for I2C transfers to the registers.
-// We could optimize this and take out the unused registers from these
-// buffers and the transfers in IS31FL3736_write_pwm_buffer() but it's
-// probably not worth the extra complexity.
-uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required = false;
-
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}};
-bool g_led_control_registers_update_required = false;
-
-void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-#endif
-}
-
-void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes PG1 is already selected
-
- // transmit PWM registers in 12 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
-
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < 192; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
- for (int j = 0; j < 16; j++) {
- g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
- }
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-#endif
- }
-}
-
-void IS31FL3736_init(uint8_t addr) {
- // In order to avoid the LEDs being driven with garbage data
- // in the LED driver's PWM registers, shutdown is enabled last.
- // Set up the mode and other settings, clear the PWM registers,
- // then disable software shutdown.
-
- // Unlock the command register.
- IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG0
- IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
- // Turn off all LEDs.
- for (int i = 0x00; i <= 0x17; i++) {
- IS31FL3736_write_register(addr, i, 0x00);
- }
-
- // Unlock the command register.
- IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG1
- IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
- // Set PWM on all LEDs to 0
- // No need to setup Breath registers to PWM as that is the default.
- for (int i = 0x00; i <= 0xBF; i++) {
- IS31FL3736_write_register(addr, i, 0x00);
- }
-
- // Unlock the command register.
- IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG3
- IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
- // Set global current to maximum.
- IS31FL3736_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
- // Disable software shutdown.
- IS31FL3736_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
-
- // Wait 10ms to ensure the device has woken up.
- wait_ms(10);
-}
-
-void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- if (index >= 0 && index < DRIVER_LED_TOTAL) {
- is31_led led = g_is31_leds[index];
-
- g_pwm_buffer[led.driver][led.r] = red;
- g_pwm_buffer[led.driver][led.g] = green;
- g_pwm_buffer[led.driver][led.b] = blue;
- g_pwm_buffer_update_required = true;
- }
-}
-
-void IS31FL3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
- for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
- IS31FL3736_set_color(i, red, green, blue);
- }
-}
-
-void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
- is31_led led = g_is31_leds[index];
-
- // IS31FL3733
- // The PWM register for a matrix position (0x00 to 0xBF) can be
- // divided by 8 to get the LED control register (0x00 to 0x17),
- // then mod 8 to get the bit position within that register.
-
- // IS31FL3736
- // The PWM register for a matrix position (0x00 to 0xBF) is interleaved, so:
- // A1=0x00 A2=0x02 A3=0x04 A4=0x06 A5=0x08 A6=0x0A A7=0x0C A8=0x0E
- // B1=0x10 B2=0x12 B3=0x14
- // But also, the LED control registers (0x00 to 0x17) are also interleaved, so:
- // A1-A4=0x00 A5-A8=0x01
- // So, the same math applies.
-
- uint8_t control_register_r = led.r / 8;
- uint8_t control_register_g = led.g / 8;
- uint8_t control_register_b = led.b / 8;
-
- uint8_t bit_r = led.r % 8;
- uint8_t bit_g = led.g % 8;
- uint8_t bit_b = led.b % 8;
-
- if (red) {
- g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
- } else {
- g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
- }
- if (green) {
- g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
- } else {
- g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
- }
- if (blue) {
- g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
- } else {
- g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
- }
-
- g_led_control_registers_update_required = true;
-}
-
-void IS31FL3736_mono_set_brightness(int index, uint8_t value) {
- if (index >= 0 && index < 96) {
- // Index in range 0..95 -> A1..A8, B1..B8, etc.
- // Map index 0..95 to registers 0x00..0xBE (interleaved)
- uint8_t pwm_register = index * 2;
- g_pwm_buffer[0][pwm_register] = value;
- g_pwm_buffer_update_required = true;
- }
-}
-
-void IS31FL3736_mono_set_brightness_all(uint8_t value) {
- for (int i = 0; i < 96; i++) {
- IS31FL3736_mono_set_brightness(i, value);
- }
-}
-
-void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled) {
- // Index in range 0..95 -> A1..A8, B1..B8, etc.
-
- // Map index 0..95 to registers 0x00..0xBE (interleaved)
- uint8_t pwm_register = index * 2;
- // Map register 0x00..0xBE (interleaved) into control register and bit
- uint8_t control_register = pwm_register / 8;
- uint8_t bit = pwm_register % 8;
-
- if (enabled) {
- g_led_control_registers[0][control_register] |= (1 << bit);
- } else {
- g_led_control_registers[0][control_register] &= ~(1 << bit);
- }
-
- g_led_control_registers_update_required = true;
-}
-
-void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
- if (g_pwm_buffer_update_required) {
- // Firstly we need to unlock the command register and select PG1
- IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
-
- IS31FL3736_write_pwm_buffer(addr1, g_pwm_buffer[0]);
- // IS31FL3736_write_pwm_buffer(addr2, g_pwm_buffer[1]);
- }
- g_pwm_buffer_update_required = false;
-}
-
-void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2) {
- if (g_led_control_registers_update_required) {
- // Firstly we need to unlock the command register and select PG0
- IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
- for (int i = 0; i < 24; i++) {
- IS31FL3736_write_register(addr1, i, g_led_control_registers[0][i]);
- // IS31FL3736_write_register(addr2, i, g_led_control_registers[1][i]);
- }
- g_led_control_registers_update_required = false;
- }
-}
diff --git a/drivers/issi/is31fl3736.h b/drivers/issi/is31fl3736.h
deleted file mode 100644
index e48e31c279..0000000000
--- a/drivers/issi/is31fl3736.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/* Copyright 2018 Jason Williams (Wilba)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-
-// Simple interface option.
-// If these aren't defined, just define them to make it compile
-
-#ifndef DRIVER_COUNT
-# define DRIVER_COUNT 2
-#endif
-
-#ifndef DRIVER_LED_TOTAL
-# define DRIVER_LED_TOTAL 96
-#endif
-
-typedef struct is31_led {
- uint8_t driver : 2;
- uint8_t r;
- uint8_t g;
- uint8_t b;
-} __attribute__((packed)) is31_led;
-
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
-
-void IS31FL3736_init(uint8_t addr);
-void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
-
-void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-
-void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
-
-void IS31FL3736_mono_set_brightness(int index, uint8_t value);
-void IS31FL3736_mono_set_brightness_all(uint8_t value);
-void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled);
-
-// This should not be called from an interrupt
-// (eg. from a timer interrupt).
-// Call this while idle (in between matrix scans).
-// If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2);
-void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2);
-
-#define A_1 0x00
-#define A_2 0x02
-#define A_3 0x04
-#define A_4 0x06
-#define A_5 0x08
-#define A_6 0x0A
-#define A_7 0x0C
-#define A_8 0x0E
-
-#define B_1 0x10
-#define B_2 0x12
-#define B_3 0x14
-#define B_4 0x16
-#define B_5 0x18
-#define B_6 0x1A
-#define B_7 0x1C
-#define B_8 0x1E
-
-#define C_1 0x20
-#define C_2 0x22
-#define C_3 0x24
-#define C_4 0x26
-#define C_5 0x28
-#define C_6 0x2A
-#define C_7 0x2C
-#define C_8 0x2E
-
-#define D_1 0x30
-#define D_2 0x32
-#define D_3 0x34
-#define D_4 0x36
-#define D_5 0x38
-#define D_6 0x3A
-#define D_7 0x3C
-#define D_8 0x3E
-
-#define E_1 0x40
-#define E_2 0x42
-#define E_3 0x44
-#define E_4 0x46
-#define E_5 0x48
-#define E_6 0x4A
-#define E_7 0x4C
-#define E_8 0x4E
-
-#define F_1 0x50
-#define F_2 0x52
-#define F_3 0x54
-#define F_4 0x56
-#define F_5 0x58
-#define F_6 0x5A
-#define F_7 0x5C
-#define F_8 0x5E
-
-#define G_1 0x60
-#define G_2 0x62
-#define G_3 0x64
-#define G_4 0x66
-#define G_5 0x68
-#define G_6 0x6A
-#define G_7 0x6C
-#define G_8 0x6E
-
-#define H_1 0x70
-#define H_2 0x72
-#define H_3 0x74
-#define H_4 0x76
-#define H_5 0x78
-#define H_6 0x7A
-#define H_7 0x7C
-#define H_8 0x7E
-
-#define I_1 0x80
-#define I_2 0x82
-#define I_3 0x84
-#define I_4 0x86
-#define I_5 0x88
-#define I_6 0x8A
-#define I_7 0x8C
-#define I_8 0x8E
-
-#define J_1 0x90
-#define J_2 0x92
-#define J_3 0x94
-#define J_4 0x96
-#define J_5 0x98
-#define J_6 0x9A
-#define J_7 0x9C
-#define J_8 0x9E
-
-#define K_1 0xA0
-#define K_2 0xA2
-#define K_3 0xA4
-#define K_4 0xA6
-#define K_5 0xA8
-#define K_6 0xAA
-#define K_7 0xAC
-#define K_8 0xAE
-
-#define L_1 0xB0
-#define L_2 0xB2
-#define L_3 0xB4
-#define L_4 0xB6
-#define L_5 0xB8
-#define L_6 0xBA
-#define L_7 0xBC
-#define L_8 0xBE
diff --git a/drivers/issi/is31fl3737.c b/drivers/issi/is31fl3737.c
deleted file mode 100644
index 30906b4840..0000000000
--- a/drivers/issi/is31fl3737.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "is31fl3737.h"
-#include "i2c_master.h"
-#include "wait.h"
-#include "progmem.h"
-
-// This is a 7-bit address, that gets left-shifted and bit 0
-// set to 0 for write, 1 for read (as per I2C protocol)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR1 represents A1:A0 of the 7-bit address.
-// ADDR2 represents A3:A2 of the 7-bit address.
-// The result is: 0b101(ADDR2)(ADDR1)
-#define ISSI_ADDR_DEFAULT 0x50
-
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_INTERRUPTMASKREGISTER 0xF0
-#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
-
-#define ISSI_PAGE_LEDCONTROL 0x00 // PG0
-#define ISSI_PAGE_PWM 0x01 // PG1
-#define ISSI_PAGE_AUTOBREATH 0x02 // PG2
-#define ISSI_PAGE_FUNCTION 0x03 // PG3
-
-#define ISSI_REG_CONFIGURATION 0x00 // PG3
-#define ISSI_REG_GLOBALCURRENT 0x01 // PG3
-#define ISSI_REG_RESET 0x11 // PG3
-#define ISSI_REG_SWPULLUP 0x0F // PG3
-#define ISSI_REG_CSPULLUP 0x10 // PG3
-
-#ifndef ISSI_TIMEOUT
-# define ISSI_TIMEOUT 100
-#endif
-
-#ifndef ISSI_PERSISTENCE
-# define ISSI_PERSISTENCE 0
-#endif
-
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20];
-
-// These buffers match the IS31FL3737 PWM registers.
-// The control buffers match the PG0 LED On/Off registers.
-// Storing them like this is optimal for I2C transfers to the registers.
-// We could optimize this and take out the unused registers from these
-// buffers and the transfers in IS31FL3737_write_pwm_buffer() but it's
-// probably not worth the extra complexity.
-
-uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
-
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
-bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
-
-void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-#endif
-}
-
-void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // assumes PG1 is already selected
-
- // transmit PWM registers in 12 transfers of 16 bytes
- // g_twi_transfer_buffer[] is 20 bytes
-
- // iterate over the pwm_buffer contents at 16 byte intervals
- for (int i = 0; i < 192; i += 16) {
- g_twi_transfer_buffer[0] = i;
- // copy the data from i to i+15
- // device will auto-increment register for data after the first byte
- // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
- for (int j = 0; j < 16; j++) {
- g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
- }
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
-#endif
- }
-}
-
-void IS31FL3737_init(uint8_t addr) {
- // In order to avoid the LEDs being driven with garbage data
- // in the LED driver's PWM registers, shutdown is enabled last.
- // Set up the mode and other settings, clear the PWM registers,
- // then disable software shutdown.
-
- // Unlock the command register.
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG0
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
- // Turn off all LEDs.
- for (int i = 0x00; i <= 0x17; i++) {
- IS31FL3737_write_register(addr, i, 0x00);
- }
-
- // Unlock the command register.
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG1
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
- // Set PWM on all LEDs to 0
- // No need to setup Breath registers to PWM as that is the default.
- for (int i = 0x00; i <= 0xBF; i++) {
- IS31FL3737_write_register(addr, i, 0x00);
- }
-
- // Unlock the command register.
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG3
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
- // Set global current to maximum.
- IS31FL3737_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
- // Disable software shutdown.
- IS31FL3737_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
-
- // Wait 10ms to ensure the device has woken up.
- wait_ms(10);
-}
-
-void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- if (index >= 0 && index < DRIVER_LED_TOTAL) {
- // copy the led config from progmem to SRAM
- is31_led led;
- memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
-
- g_pwm_buffer[led.driver][led.r] = red;
- g_pwm_buffer[led.driver][led.g] = green;
- g_pwm_buffer[led.driver][led.b] = blue;
- g_pwm_buffer_update_required[led.driver] = true;
- }
-}
-
-void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
- for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
- IS31FL3737_set_color(i, red, green, blue);
- }
-}
-
-void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
- // copy the led config from progmem to SRAM
- is31_led led;
- memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
-
- uint8_t control_register_r = led.r / 8;
- uint8_t control_register_g = led.g / 8;
- uint8_t control_register_b = led.b / 8;
- uint8_t bit_r = led.r % 8;
- uint8_t bit_g = led.g % 8;
- uint8_t bit_b = led.b % 8;
-
- if (red) {
- g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
- } else {
- g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
- }
- if (green) {
- g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
- } else {
- g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
- }
- if (blue) {
- g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
- } else {
- g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
- }
-
- g_led_control_registers_update_required[led.driver] = true;
-}
-
-void IS31FL3737_update_pwm_buffers(uint8_t addr, uint8_t index) {
- if (g_pwm_buffer_update_required[index]) {
- // Firstly we need to unlock the command register and select PG1
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
-
- IS31FL3737_write_pwm_buffer(addr, g_pwm_buffer[index]);
- }
- g_pwm_buffer_update_required[index] = false;
-}
-
-void IS31FL3737_update_led_control_registers(uint8_t addr, uint8_t index) {
- if (g_led_control_registers_update_required[index]) {
- // Firstly we need to unlock the command register and select PG0
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
- for (int i = 0; i < 24; i++) {
- IS31FL3737_write_register(addr, i, g_led_control_registers[index][i]);
- }
- }
- g_led_control_registers_update_required[index] = false;
-}
diff --git a/drivers/issi/is31fl3737.h b/drivers/issi/is31fl3737.h
deleted file mode 100644
index a1d2281778..0000000000
--- a/drivers/issi/is31fl3737.h
+++ /dev/null
@@ -1,203 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-
-typedef struct is31_led {
- uint8_t driver : 2;
- uint8_t r;
- uint8_t g;
- uint8_t b;
-} __attribute__((packed)) is31_led;
-
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
-
-void IS31FL3737_init(uint8_t addr);
-void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
-
-void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-
-void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
-
-// This should not be called from an interrupt
-// (eg. from a timer interrupt).
-// Call this while idle (in between matrix scans).
-// If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3737_update_pwm_buffers(uint8_t addr1, uint8_t addr2);
-void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2);
-
-#define A_1 0x00
-#define A_2 0x01
-#define A_3 0x02
-#define A_4 0x03
-#define A_5 0x04
-#define A_6 0x05
-#define A_7 0x08
-#define A_8 0x09
-#define A_9 0x0A
-#define A_10 0x0B
-#define A_11 0x0C
-#define A_12 0x0D
-
-#define B_1 0x10
-#define B_2 0x11
-#define B_3 0x12
-#define B_4 0x13
-#define B_5 0x14
-#define B_6 0x15
-#define B_7 0x18
-#define B_8 0x19
-#define B_9 0x1A
-#define B_10 0x1B
-#define B_11 0x1C
-#define B_12 0x1D
-
-#define C_1 0x20
-#define C_2 0x21
-#define C_3 0x22
-#define C_4 0x23
-#define C_5 0x24
-#define C_6 0x25
-#define C_7 0x28
-#define C_8 0x29
-#define C_9 0x2A
-#define C_10 0x2B
-#define C_11 0x2C
-#define C_12 0x2D
-
-#define D_1 0x30
-#define D_2 0x31
-#define D_3 0x32
-#define D_4 0x33
-#define D_5 0x34
-#define D_6 0x35
-#define D_7 0x38
-#define D_8 0x39
-#define D_9 0x3A
-#define D_10 0x3B
-#define D_11 0x3C
-#define D_12 0x3D
-
-#define E_1 0x40
-#define E_2 0x41
-#define E_3 0x42
-#define E_4 0x43
-#define E_5 0x44
-#define E_6 0x45
-#define E_7 0x48
-#define E_8 0x49
-#define E_9 0x4A
-#define E_10 0x4B
-#define E_11 0x4C
-#define E_12 0x4D
-
-#define F_1 0x50
-#define F_2 0x51
-#define F_3 0x52
-#define F_4 0x53
-#define F_5 0x54
-#define F_6 0x55
-#define F_7 0x58
-#define F_8 0x59
-#define F_9 0x5A
-#define F_10 0x5B
-#define F_11 0x5C
-#define F_12 0x5D
-
-#define G_1 0x60
-#define G_2 0x61
-#define G_3 0x62
-#define G_4 0x63
-#define G_5 0x64
-#define G_6 0x65
-#define G_7 0x68
-#define G_8 0x69
-#define G_9 0x6A
-#define G_10 0x6B
-#define G_11 0x6C
-#define G_12 0x6D
-
-#define H_1 0x70
-#define H_2 0x71
-#define H_3 0x72
-#define H_4 0x73
-#define H_5 0x74
-#define H_6 0x75
-#define H_7 0x78
-#define H_8 0x79
-#define H_9 0x7A
-#define H_10 0x7B
-#define H_11 0x7C
-#define H_12 0x7D
-
-#define I_1 0x80
-#define I_2 0x81
-#define I_3 0x82
-#define I_4 0x83
-#define I_5 0x84
-#define I_6 0x85
-#define I_7 0x88
-#define I_8 0x89
-#define I_9 0x8A
-#define I_10 0x8B
-#define I_11 0x8C
-#define I_12 0x8D
-
-#define J_1 0x90
-#define J_2 0x91
-#define J_3 0x92
-#define J_4 0x93
-#define J_5 0x94
-#define J_6 0x95
-#define J_7 0x98
-#define J_8 0x99
-#define J_9 0x9A
-#define J_10 0x9B
-#define J_11 0x9C
-#define J_12 0x9D
-
-#define K_1 0xA0
-#define K_2 0xA1
-#define K_3 0xA2
-#define K_4 0xA3
-#define K_5 0xA4
-#define K_6 0xA5
-#define K_7 0xA8
-#define K_8 0xA9
-#define K_9 0xAA
-#define K_10 0xAB
-#define K_11 0xAC
-#define K_12 0xAD
-
-#define L_1 0xB0
-#define L_2 0xB1
-#define L_3 0xB2
-#define L_4 0xB3
-#define L_5 0xB4
-#define L_6 0xB5
-#define L_7 0xB8
-#define L_8 0xB9
-#define L_9 0xBA
-#define L_10 0xBB
-#define L_11 0xBC
-#define L_12 0xBD
diff --git a/drivers/issi/is31fl3741.c b/drivers/issi/is31fl3741.c
deleted file mode 100644
index 1b533c9b6a..0000000000
--- a/drivers/issi/is31fl3741.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- * Copyright 2020 MelGeek
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "wait.h"
-
-#include "is31fl3741.h"
-#include
-#include "i2c_master.h"
-#include "progmem.h"
-
-// This is a 7-bit address, that gets left-shifted and bit 0
-// set to 0 for write, 1 for read (as per I2C protocol)
-// The address will vary depending on your wiring:
-// 00 <-> GND
-// 01 <-> SCL
-// 10 <-> SDA
-// 11 <-> VCC
-// ADDR1 represents A1:A0 of the 7-bit address.
-// ADDR2 represents A3:A2 of the 7-bit address.
-// The result is: 0b101(ADDR2)(ADDR1)
-#define ISSI_ADDR_DEFAULT 0x60
-
-#define ISSI_COMMANDREGISTER 0xFD
-#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
-#define ISSI_INTERRUPTMASKREGISTER 0xF0
-#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
-#define ISSI_IDREGISTER 0xFC
-
-#define ISSI_PAGE_PWM0 0x00 // PG0
-#define ISSI_PAGE_PWM1 0x01 // PG1
-#define ISSI_PAGE_SCALING_0 0x02 // PG2
-#define ISSI_PAGE_SCALING_1 0x03 // PG3
-#define ISSI_PAGE_FUNCTION 0x04 // PG4
-
-#define ISSI_REG_CONFIGURATION 0x00 // PG4
-#define ISSI_REG_GLOBALCURRENT 0x01 // PG4
-#define ISSI_REG_PULLDOWNUP 0x02 // PG4
-#define ISSI_REG_RESET 0x3F // PG4
-
-#ifndef ISSI_TIMEOUT
-# define ISSI_TIMEOUT 100
-#endif
-
-#ifndef ISSI_PERSISTENCE
-# define ISSI_PERSISTENCE 0
-#endif
-
-#define ISSI_MAX_LEDS 351
-
-// Transfer buffer for TWITransmitData()
-uint8_t g_twi_transfer_buffer[20] = {0xFF};
-
-// These buffers match the IS31FL3741 and IS31FL3741A PWM registers.
-// The scaling buffers match the PG2 and PG3 LED On/Off registers.
-// Storing them like this is optimal for I2C transfers to the registers.
-// We could optimize this and take out the unused registers from these
-// buffers and the transfers in IS31FL3741_write_pwm_buffer() but it's
-// probably not worth the extra complexity.
-uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS];
-bool g_pwm_buffer_update_required = false;
-bool g_scaling_registers_update_required[DRIVER_COUNT] = {false};
-
-uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_LEDS];
-
-void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
- g_twi_transfer_buffer[0] = reg;
- g_twi_transfer_buffer[1] = data;
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
- }
-#else
- i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
-#endif
-}
-
-bool IS31FL3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
- // unlock the command register and select PG2
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM0);
-
- for (int i = 0; i < 342; i += 18) {
- if (i == 180) {
- // unlock the command register and select PG2
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM1);
- }
-
- g_twi_transfer_buffer[0] = i % 180;
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 18);
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, ISSI_TIMEOUT) != 0) {
- return false;
- }
- }
-#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, ISSI_TIMEOUT) != 0) {
- return false;
- }
-#endif
- }
-
- // transfer the left cause the total number is 351
- g_twi_transfer_buffer[0] = 162;
- memcpy(g_twi_transfer_buffer + 1, pwm_buffer + 342, 9);
-
-#if ISSI_PERSISTENCE > 0
- for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, ISSI_TIMEOUT) != 0) {
- return false;
- }
- }
-#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, ISSI_TIMEOUT) != 0) {
- return false;
- }
-#endif
-
- return true;
-}
-
-void IS31FL3741_init(uint8_t addr) {
- // In order to avoid the LEDs being driven with garbage data
- // in the LED driver's PWM registers, shutdown is enabled last.
- // Set up the mode and other settings, clear the PWM registers,
- // then disable software shutdown.
- // Unlock the command register.
-
- // Unlock the command register.
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
-
- // Select PG4
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
-
- // Set to Normal operation
- IS31FL3741_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
-
- // Set Golbal Current Control Register
- IS31FL3741_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
- // Set Pull up & Down for SWx CSy
- IS31FL3741_write_register(addr, ISSI_REG_PULLDOWNUP, 0x77);
-
- // IS31FL3741_update_led_scaling_registers(addr, 0xFF, 0xFF, 0xFF);
-
- // Wait 10ms to ensure the device has woken up.
- wait_ms(10);
-}
-
-void IS31FL3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
- if (index >= 0 && index < DRIVER_LED_TOTAL) {
- is31_led led = g_is31_leds[index];
-
- g_pwm_buffer[led.driver][led.r] = red;
- g_pwm_buffer[led.driver][led.g] = green;
- g_pwm_buffer[led.driver][led.b] = blue;
- g_pwm_buffer_update_required = true;
- }
-}
-
-void IS31FL3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
- for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
- IS31FL3741_set_color(i, red, green, blue);
- }
-}
-
-void IS31FL3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
- is31_led led = g_is31_leds[index];
-
- if (red) {
- g_scaling_registers[led.driver][led.r] = 0xFF;
- } else {
- g_scaling_registers[led.driver][led.r] = 0x00;
- }
-
- if (green) {
- g_scaling_registers[led.driver][led.g] = 0xFF;
- } else {
- g_scaling_registers[led.driver][led.g] = 0x00;
- }
-
- if (blue) {
- g_scaling_registers[led.driver][led.b] = 0xFF;
- } else {
- g_scaling_registers[led.driver][led.b] = 0x00;
- }
-
- g_scaling_registers_update_required[led.driver] = true;
-}
-
-void IS31FL3741_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
- if (g_pwm_buffer_update_required) {
- IS31FL3741_write_pwm_buffer(addr1, g_pwm_buffer[0]);
- }
-
- g_pwm_buffer_update_required = false;
-}
-
-void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) {
- g_pwm_buffer[pled->driver][pled->r] = red;
- g_pwm_buffer[pled->driver][pled->g] = green;
- g_pwm_buffer[pled->driver][pled->b] = blue;
-
- g_pwm_buffer_update_required = true;
-}
-
-void IS31FL3741_update_led_control_registers(uint8_t addr, uint8_t index) {
- if (g_scaling_registers_update_required[index]) {
- // unlock the command register and select PG2
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_0);
-
- // CS1_SW1 to CS30_SW6 are on PG2
- for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
- IS31FL3741_write_register(addr, i, g_scaling_registers[0][i]);
- }
-
- // unlock the command register and select PG3
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
- IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_1);
-
- // CS1_SW7 to CS39_SW9 are on PG3
- for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
- IS31FL3741_write_register(addr, i - CS1_SW7, g_scaling_registers[0][i]);
- }
-
- g_scaling_registers_update_required[index] = false;
- }
-}
-
-void IS31FL3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) {
- g_scaling_registers[pled->driver][pled->r] = red;
- g_scaling_registers[pled->driver][pled->g] = green;
- g_scaling_registers[pled->driver][pled->b] = blue;
-
- g_scaling_registers_update_required[pled->driver] = true;
-}
diff --git a/drivers/issi/is31fl3741.h b/drivers/issi/is31fl3741.h
deleted file mode 100644
index 2df0c5b1a7..0000000000
--- a/drivers/issi/is31fl3741.h
+++ /dev/null
@@ -1,420 +0,0 @@
-/* Copyright 2017 Jason Williams
- * Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- * Copyright 2020 MelGeek
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-
-typedef struct is31_led {
- uint32_t driver : 2;
- uint32_t r : 10;
- uint32_t g : 10;
- uint32_t b : 10;
-} __attribute__((packed)) is31_led;
-
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
-
-void IS31FL3741_init(uint8_t addr);
-void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
-bool IS31FL3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
-
-void IS31FL3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
-void IS31FL3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
-
-void IS31FL3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
-
-// This should not be called from an interrupt
-// (eg. from a timer interrupt).
-// Call this while idle (in between matrix scans).
-// If the buffer is dirty, it will update the driver with the buffer.
-void IS31FL3741_update_pwm_buffers(uint8_t addr1, uint8_t addr2);
-void IS31FL3741_update_led_control_registers(uint8_t addr1, uint8_t addr2);
-void IS31FL3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue);
-
-void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue);
-
-#define CS1_SW1 0x00
-#define CS2_SW1 0x01
-#define CS3_SW1 0x02
-#define CS4_SW1 0x03
-#define CS5_SW1 0x04
-#define CS6_SW1 0x05
-#define CS7_SW1 0x06
-#define CS8_SW1 0x07
-#define CS9_SW1 0x08
-#define CS10_SW1 0x09
-#define CS11_SW1 0x0A
-#define CS12_SW1 0x0B
-#define CS13_SW1 0x0C
-#define CS14_SW1 0x0D
-#define CS15_SW1 0x0E
-#define CS16_SW1 0x0F
-#define CS17_SW1 0x10
-#define CS18_SW1 0x11
-#define CS19_SW1 0x12
-#define CS20_SW1 0x13
-#define CS21_SW1 0x14
-#define CS22_SW1 0x15
-#define CS23_SW1 0x16
-#define CS24_SW1 0x17
-#define CS25_SW1 0x18
-#define CS26_SW1 0x19
-#define CS27_SW1 0x1A
-#define CS28_SW1 0x1B
-#define CS29_SW1 0x1C
-#define CS30_SW1 0x1D
-
-#define CS1_SW2 0x1E
-#define CS2_SW2 0x1F
-#define CS3_SW2 0x20
-#define CS4_SW2 0x21
-#define CS5_SW2 0x22
-#define CS6_SW2 0x23
-#define CS7_SW2 0x24
-#define CS8_SW2 0x25
-#define CS9_SW2 0x26
-#define CS10_SW2 0x27
-#define CS11_SW2 0x28
-#define CS12_SW2 0x29
-#define CS13_SW2 0x2A
-#define CS14_SW2 0x2B
-#define CS15_SW2 0x2C
-#define CS16_SW2 0x2D
-#define CS17_SW2 0x2E
-#define CS18_SW2 0x2F
-#define CS19_SW2 0x30
-#define CS20_SW2 0x31
-#define CS21_SW2 0x32
-#define CS22_SW2 0x33
-#define CS23_SW2 0x34
-#define CS24_SW2 0x35
-#define CS25_SW2 0x36
-#define CS26_SW2 0x37
-#define CS27_SW2 0x38
-#define CS28_SW2 0x39
-#define CS29_SW2 0x3A
-#define CS30_SW2 0x3B
-
-#define CS1_SW3 0x3C
-#define CS2_SW3 0x3D
-#define CS3_SW3 0x3E
-#define CS4_SW3 0x3F
-#define CS5_SW3 0x40
-#define CS6_SW3 0x41
-#define CS7_SW3 0x42
-#define CS8_SW3 0x43
-#define CS9_SW3 0x44
-#define CS10_SW3 0x45
-#define CS11_SW3 0x46
-#define CS12_SW3 0x47
-#define CS13_SW3 0x48
-#define CS14_SW3 0x49
-#define CS15_SW3 0x4A
-#define CS16_SW3 0x4B
-#define CS17_SW3 0x4C
-#define CS18_SW3 0x4D
-#define CS19_SW3 0x4E
-#define CS20_SW3 0x4F
-#define CS21_SW3 0x50
-#define CS22_SW3 0x51
-#define CS23_SW3 0x52
-#define CS24_SW3 0x53
-#define CS25_SW3 0x54
-#define CS26_SW3 0x55
-#define CS27_SW3 0x56
-#define CS28_SW3 0x57
-#define CS29_SW3 0x58
-#define CS30_SW3 0x59
-
-#define CS1_SW4 0x5A
-#define CS2_SW4 0x5B
-#define CS3_SW4 0x5C
-#define CS4_SW4 0x5D
-#define CS5_SW4 0x5E
-#define CS6_SW4 0x5F
-#define CS7_SW4 0x60
-#define CS8_SW4 0x61
-#define CS9_SW4 0x62
-#define CS10_SW4 0x63
-#define CS11_SW4 0x64
-#define CS12_SW4 0x65
-#define CS13_SW4 0x66
-#define CS14_SW4 0x67
-#define CS15_SW4 0x68
-#define CS16_SW4 0x69
-#define CS17_SW4 0x6A
-#define CS18_SW4 0x6B
-#define CS19_SW4 0x6C
-#define CS20_SW4 0x6D
-#define CS21_SW4 0x6E
-#define CS22_SW4 0x6F
-#define CS23_SW4 0x70
-#define CS24_SW4 0x71
-#define CS25_SW4 0x72
-#define CS26_SW4 0x73
-#define CS27_SW4 0x74
-#define CS28_SW4 0x75
-#define CS29_SW4 0x76
-#define CS30_SW4 0x77
-
-#define CS1_SW5 0x78
-#define CS2_SW5 0x79
-#define CS3_SW5 0x7A
-#define CS4_SW5 0x7B
-#define CS5_SW5 0x7C
-#define CS6_SW5 0x7D
-#define CS7_SW5 0x7E
-#define CS8_SW5 0x7F
-#define CS9_SW5 0x80
-#define CS10_SW5 0x81
-#define CS11_SW5 0x82
-#define CS12_SW5 0x83
-#define CS13_SW5 0x84
-#define CS14_SW5 0x85
-#define CS15_SW5 0x86
-#define CS16_SW5 0x87
-#define CS17_SW5 0x88
-#define CS18_SW5 0x89
-#define CS19_SW5 0x8A
-#define CS20_SW5 0x8B
-#define CS21_SW5 0x8C
-#define CS22_SW5 0x8D
-#define CS23_SW5 0x8E
-#define CS24_SW5 0x8F
-#define CS25_SW5 0x90
-#define CS26_SW5 0x91
-#define CS27_SW5 0x92
-#define CS28_SW5 0x93
-#define CS29_SW5 0x94
-#define CS30_SW5 0x95
-
-#define CS1_SW6 0x96
-#define CS2_SW6 0x97
-#define CS3_SW6 0x98
-#define CS4_SW6 0x99
-#define CS5_SW6 0x9A
-#define CS6_SW6 0x9B
-#define CS7_SW6 0x9C
-#define CS8_SW6 0x9D
-#define CS9_SW6 0x9E
-#define CS10_SW6 0x9F
-#define CS11_SW6 0xA0
-#define CS12_SW6 0xA1
-#define CS13_SW6 0xA2
-#define CS14_SW6 0xA3
-#define CS15_SW6 0xA4
-#define CS16_SW6 0xA5
-#define CS17_SW6 0xA6
-#define CS18_SW6 0xA7
-#define CS19_SW6 0xA8
-#define CS20_SW6 0xA9
-#define CS21_SW6 0xAA
-#define CS22_SW6 0xAB
-#define CS23_SW6 0xAC
-#define CS24_SW6 0xAD
-#define CS25_SW6 0xAE
-#define CS26_SW6 0xAF
-#define CS27_SW6 0xB0
-#define CS28_SW6 0xB1
-#define CS29_SW6 0xB2
-#define CS30_SW6 0xB3
-
-#define CS1_SW7 0xB4
-#define CS2_SW7 0xB5
-#define CS3_SW7 0xB6
-#define CS4_SW7 0xB7
-#define CS5_SW7 0xB8
-#define CS6_SW7 0xB9
-#define CS7_SW7 0xBA
-#define CS8_SW7 0xBB
-#define CS9_SW7 0xBC
-#define CS10_SW7 0xBD
-#define CS11_SW7 0xBE
-#define CS12_SW7 0xBF
-#define CS13_SW7 0xC0
-#define CS14_SW7 0xC1
-#define CS15_SW7 0xC2
-#define CS16_SW7 0xC3
-#define CS17_SW7 0xC4
-#define CS18_SW7 0xC5
-#define CS19_SW7 0xC6
-#define CS20_SW7 0xC7
-#define CS21_SW7 0xC8
-#define CS22_SW7 0xC9
-#define CS23_SW7 0xCA
-#define CS24_SW7 0xCB
-#define CS25_SW7 0xCC
-#define CS26_SW7 0xCD
-#define CS27_SW7 0xCE
-#define CS28_SW7 0xCF
-#define CS29_SW7 0xD0
-#define CS30_SW7 0xD1
-
-#define CS1_SW8 0xD2
-#define CS2_SW8 0xD3
-#define CS3_SW8 0xD4
-#define CS4_SW8 0xD5
-#define CS5_SW8 0xD6
-#define CS6_SW8 0xD7
-#define CS7_SW8 0xD8
-#define CS8_SW8 0xD9
-#define CS9_SW8 0xDA
-#define CS10_SW8 0xDB
-#define CS11_SW8 0xDC
-#define CS12_SW8 0xDD
-#define CS13_SW8 0xDE
-#define CS14_SW8 0xDF
-#define CS15_SW8 0xE0
-#define CS16_SW8 0xE1
-#define CS17_SW8 0xE2
-#define CS18_SW8 0xE3
-#define CS19_SW8 0xE4
-#define CS20_SW8 0xE5
-#define CS21_SW8 0xE6
-#define CS22_SW8 0xE7
-#define CS23_SW8 0xE8
-#define CS24_SW8 0xE9
-#define CS25_SW8 0xEA
-#define CS26_SW8 0xEB
-#define CS27_SW8 0xEC
-#define CS28_SW8 0xED
-#define CS29_SW8 0xEE
-#define CS30_SW8 0xEF
-
-#define CS1_SW9 0xF0
-#define CS2_SW9 0xF1
-#define CS3_SW9 0xF2
-#define CS4_SW9 0xF3
-#define CS5_SW9 0xF4
-#define CS6_SW9 0xF5
-#define CS7_SW9 0xF6
-#define CS8_SW9 0xF7
-#define CS9_SW9 0xF8
-#define CS10_SW9 0xF9
-#define CS11_SW9 0xFA
-#define CS12_SW9 0xFB
-#define CS13_SW9 0xFC
-#define CS14_SW9 0xFD
-#define CS15_SW9 0xFE
-#define CS16_SW9 0xFF
-#define CS17_SW9 0x100
-#define CS18_SW9 0x101
-#define CS19_SW9 0x102
-#define CS20_SW9 0x103
-#define CS21_SW9 0x104
-#define CS22_SW9 0x105
-#define CS23_SW9 0x106
-#define CS24_SW9 0x107
-#define CS25_SW9 0x108
-#define CS26_SW9 0x109
-#define CS27_SW9 0x10A
-#define CS28_SW9 0x10B
-#define CS29_SW9 0x10C
-#define CS30_SW9 0x10D
-
-#define CS31_SW1 0x10E
-#define CS32_SW1 0x10F
-#define CS33_SW1 0x110
-#define CS34_SW1 0x111
-#define CS35_SW1 0x112
-#define CS36_SW1 0x113
-#define CS37_SW1 0x114
-#define CS38_SW1 0x115
-#define CS39_SW1 0x116
-
-#define CS31_SW2 0x117
-#define CS32_SW2 0x118
-#define CS33_SW2 0x119
-#define CS34_SW2 0x11A
-#define CS35_SW2 0x11B
-#define CS36_SW2 0x11C
-#define CS37_SW2 0x11D
-#define CS38_SW2 0x11E
-#define CS39_SW2 0x11F
-
-#define CS31_SW3 0x120
-#define CS32_SW3 0x121
-#define CS33_SW3 0x122
-#define CS34_SW3 0x123
-#define CS35_SW3 0x124
-#define CS36_SW3 0x125
-#define CS37_SW3 0x126
-#define CS38_SW3 0x127
-#define CS39_SW3 0x128
-
-#define CS31_SW4 0x129
-#define CS32_SW4 0x12A
-#define CS33_SW4 0x12B
-#define CS34_SW4 0x12C
-#define CS35_SW4 0x12D
-#define CS36_SW4 0x12E
-#define CS37_SW4 0x12F
-#define CS38_SW4 0x130
-#define CS39_SW4 0x131
-
-#define CS31_SW5 0x132
-#define CS32_SW5 0x133
-#define CS33_SW5 0x134
-#define CS34_SW5 0x135
-#define CS35_SW5 0x136
-#define CS36_SW5 0x137
-#define CS37_SW5 0x138
-#define CS38_SW5 0x139
-#define CS39_SW5 0x13A
-
-#define CS31_SW6 0x13B
-#define CS32_SW6 0x13C
-#define CS33_SW6 0x13D
-#define CS34_SW6 0x13E
-#define CS35_SW6 0x13F
-#define CS36_SW6 0x140
-#define CS37_SW6 0x141
-#define CS38_SW6 0x142
-#define CS39_SW6 0x143
-
-#define CS31_SW7 0x144
-#define CS32_SW7 0x145
-#define CS33_SW7 0x146
-#define CS34_SW7 0x147
-#define CS35_SW7 0x148
-#define CS36_SW7 0x149
-#define CS37_SW7 0x14A
-#define CS38_SW7 0x14B
-#define CS39_SW7 0x14C
-
-#define CS31_SW8 0x14D
-#define CS32_SW8 0x14E
-#define CS33_SW8 0x14F
-#define CS34_SW8 0x150
-#define CS35_SW8 0x151
-#define CS36_SW8 0x152
-#define CS37_SW8 0x153
-#define CS38_SW8 0x154
-#define CS39_SW8 0x155
-
-#define CS31_SW9 0x156
-#define CS32_SW9 0x157
-#define CS33_SW9 0x158
-#define CS34_SW9 0x159
-#define CS35_SW9 0x15A
-#define CS36_SW9 0x15B
-#define CS37_SW9 0x15C
-#define CS38_SW9 0x15D
-#define CS39_SW9 0x15E
diff --git a/drivers/led/apa102.c b/drivers/led/apa102.c
new file mode 100644
index 0000000000..7396dc3c55
--- /dev/null
+++ b/drivers/led/apa102.c
@@ -0,0 +1,151 @@
+/* Copyright 2020 Aldehir Rojas
+ * Copyright 2017 Mikkel (Duckle29)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "apa102.h"
+#include "quantum.h"
+
+#ifndef APA102_NOPS
+# if defined(__AVR__)
+# define APA102_NOPS 0 // AVR at 16 MHz already spends 62.5 ns per clock, so no extra delay is needed
+# elif defined(PROTOCOL_CHIBIOS)
+
+# include "hal.h"
+# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX)
+# define APA102_NOPS (100 / (1000000000L / (STM32_SYSCLK / 4))) // This calculates how many loops of 4 nops to run to delay 100 ns
+# else
+# error("APA102_NOPS configuration required")
+# define APA102_NOPS 0 // this just pleases the compile so the above error is easier to spot
+# endif
+# endif
+#endif
+
+#define io_wait \
+ do { \
+ for (int i = 0; i < APA102_NOPS; i++) { \
+ __asm__ volatile("nop\n\t" \
+ "nop\n\t" \
+ "nop\n\t" \
+ "nop\n\t"); \
+ } \
+ } while (0)
+
+#define APA102_SEND_BIT(byte, bit) \
+ do { \
+ writePin(RGB_DI_PIN, (byte >> bit) & 1); \
+ io_wait; \
+ writePinHigh(RGB_CI_PIN); \
+ io_wait; \
+ writePinLow(RGB_CI_PIN); \
+ io_wait; \
+ } while (0)
+
+uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS;
+
+void static apa102_start_frame(void);
+void static apa102_end_frame(uint16_t num_leds);
+
+void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness);
+void static apa102_send_byte(uint8_t byte);
+
+void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds) {
+ LED_TYPE *end = start_led + num_leds;
+
+ apa102_start_frame();
+ for (LED_TYPE *led = start_led; led < end; led++) {
+ apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness);
+ }
+ apa102_end_frame(num_leds);
+}
+
+// Overwrite the default rgblight_call_driver to use apa102 driver
+void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { apa102_setleds(start_led, num_leds); }
+
+void static apa102_init(void) {
+ setPinOutput(RGB_DI_PIN);
+ setPinOutput(RGB_CI_PIN);
+
+ writePinLow(RGB_DI_PIN);
+ writePinLow(RGB_CI_PIN);
+}
+
+void apa102_set_brightness(uint8_t brightness) {
+ if (brightness > APA102_MAX_BRIGHTNESS) {
+ apa102_led_brightness = APA102_MAX_BRIGHTNESS;
+ } else if (brightness < 0) {
+ apa102_led_brightness = 0;
+ } else {
+ apa102_led_brightness = brightness;
+ }
+}
+
+void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness) {
+ apa102_send_byte(0b11100000 | brightness);
+ apa102_send_byte(blue);
+ apa102_send_byte(green);
+ apa102_send_byte(red);
+}
+
+void static apa102_start_frame(void) {
+ apa102_init();
+ for (uint16_t i = 0; i < 4; i++) {
+ apa102_send_byte(0);
+ }
+}
+
+void static apa102_end_frame(uint16_t num_leds) {
+ // This function has been taken from: https://github.com/pololu/apa102-arduino/blob/master/APA102.h
+ // and adapted. The code is MIT licensed. I think thats compatible?
+ //
+ // The data stream seen by the last LED in the chain will be delayed by
+ // (count - 1) clock edges, because each LED before it inverts the clock
+ // line and delays the data by one clock edge. Therefore, to make sure
+ // the last LED actually receives the data we wrote, the number of extra
+ // edges we send at the end of the frame must be at least (count - 1).
+ //
+ // Assuming we only want to send these edges in groups of size K, the
+ // C/C++ expression for the minimum number of groups to send is:
+ //
+ // ((count - 1) + (K - 1)) / K
+ //
+ // The C/C++ expression above is just (count - 1) divided by K,
+ // rounded up to the nearest whole number if there is a remainder.
+ //
+ // We set K to 16 and use the formula above as the number of frame-end
+ // bytes to transfer. Each byte has 16 clock edges.
+ //
+ // We are ignoring the specification for the end frame in the APA102
+ // datasheet, which says to send 0xFF four times, because it does not work
+ // when you have 66 LEDs or more, and also it results in unwanted white
+ // pixels if you try to update fewer LEDs than are on your LED strip.
+ uint16_t iterations = (num_leds + 14) / 16;
+ for (uint16_t i = 0; i < iterations; i++) {
+ apa102_send_byte(0);
+ }
+
+ apa102_init();
+}
+
+void static apa102_send_byte(uint8_t byte) {
+ APA102_SEND_BIT(byte, 7);
+ APA102_SEND_BIT(byte, 6);
+ APA102_SEND_BIT(byte, 5);
+ APA102_SEND_BIT(byte, 4);
+ APA102_SEND_BIT(byte, 3);
+ APA102_SEND_BIT(byte, 2);
+ APA102_SEND_BIT(byte, 1);
+ APA102_SEND_BIT(byte, 0);
+}
diff --git a/drivers/led/apa102.h b/drivers/led/apa102.h
new file mode 100644
index 0000000000..58cf020c1e
--- /dev/null
+++ b/drivers/led/apa102.h
@@ -0,0 +1,41 @@
+/* Copyright 2020 Aldehir Rojas
+ * Copyright 2017 Mikkel (Duckle29)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include "color.h"
+
+#ifndef APA102_DEFAULT_BRIGHTNESS
+# define APA102_DEFAULT_BRIGHTNESS 31
+#endif
+
+#define APA102_MAX_BRIGHTNESS 31
+
+extern uint8_t apa102_led_brightness;
+
+/* User Interface
+ *
+ * Input:
+ * start_led: An array of GRB data describing the LED colors
+ * num_leds: The number of LEDs to write
+ *
+ * The functions will perform the following actions:
+ * - Set the data-out pin as output
+ * - Send out the LED data
+ */
+void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds);
+void apa102_set_brightness(uint8_t brightness);
diff --git a/drivers/led/aw20216.c b/drivers/led/aw20216.c
new file mode 100644
index 0000000000..c608c0ab44
--- /dev/null
+++ b/drivers/led/aw20216.c
@@ -0,0 +1,141 @@
+/* Copyright 2021 Jasper Chan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "aw20216.h"
+#include "spi_master.h"
+
+/* The AW20216 appears to be somewhat similar to the IS31FL743, although quite
+ * a few things are different, such as the command byte format and page ordering.
+ * The LED addresses start from 0x00 instead of 0x01.
+ */
+#define AWINIC_ID 0b1010 << 4
+
+#define AW_PAGE_FUNCTION 0x00 << 1 // PG0, Function registers
+#define AW_PAGE_PWM 0x01 << 1 // PG1, LED PWM control
+#define AW_PAGE_SCALING 0x02 << 1 // PG2, LED current scaling control
+#define AW_PAGE_PATCHOICE 0x03 << 1 // PG3, Pattern choice?
+#define AW_PAGE_PWMSCALING 0x04 << 1 // PG4, LED PWM + Scaling control?
+
+#define AW_WRITE 0
+#define AW_READ 1
+
+#define AW_REG_CONFIGURATION 0x00 // PG0
+#define AW_REG_GLOBALCURRENT 0x01 // PG0
+
+// Default value of AW_REG_CONFIGURATION
+// D7:D4 = 1011, SWSEL (SW1~SW12 active)
+// D3 = 0?, reserved (apparently this should be 1 but it doesn't seem to matter)
+// D2:D1 = 00, OSDE (open/short detection enable)
+// D0 = 0, CHIPEN (write 1 to enable LEDs when hardware enable pulled high)
+#define AW_CONFIG_DEFAULT 0b10110000
+#define AW_CHIPEN 1
+
+#define AW_PWM_REGISTER_COUNT 216
+
+#ifndef AW_SCALING_MAX
+# define AW_SCALING_MAX 150
+#endif
+
+#ifndef AW_GLOBAL_CURRENT_MAX
+# define AW_GLOBAL_CURRENT_MAX 150
+#endif
+
+#ifndef AW_SPI_DIVISOR
+# define AW_SPI_DIVISOR 4
+#endif
+
+uint8_t g_pwm_buffer[DRIVER_COUNT][AW_PWM_REGISTER_COUNT];
+bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
+
+bool AW20216_write(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t* data, uint8_t len) {
+ static uint8_t s_spi_transfer_buffer[2] = {0};
+
+ if (!spi_start(cs_pin, false, 0, AW_SPI_DIVISOR)) {
+ spi_stop();
+ return false;
+ }
+
+ s_spi_transfer_buffer[0] = (AWINIC_ID | page | AW_WRITE);
+ s_spi_transfer_buffer[1] = reg;
+
+ if (spi_transmit(s_spi_transfer_buffer, 2) != SPI_STATUS_SUCCESS) {
+ spi_stop();
+ return false;
+ }
+
+ if (spi_transmit(data, len) != SPI_STATUS_SUCCESS) {
+ spi_stop();
+ return false;
+ }
+
+ spi_stop();
+ return true;
+}
+
+static inline bool AW20216_write_register(pin_t cs_pin, uint8_t page, uint8_t reg, uint8_t value) {
+ // Little wrapper so callers need not care about sending a buffer
+ return AW20216_write(cs_pin, page, reg, &value, 1);
+}
+
+static void AW20216_init_scaling(pin_t cs_pin) {
+ // Set constant current to the max, control brightness with PWM
+ for (uint8_t i = 0; i < AW_PWM_REGISTER_COUNT; i++) {
+ AW20216_write_register(cs_pin, AW_PAGE_SCALING, i, AW_SCALING_MAX);
+ }
+}
+
+static inline void AW20216_init_current_limit(pin_t cs_pin) {
+ // Push config
+ AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX);
+}
+
+static inline void AW20216_soft_enable(pin_t cs_pin) {
+ // Push config
+ AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN);
+}
+
+void AW20216_init(pin_t cs_pin, pin_t en_pin) {
+ setPinOutput(en_pin);
+ writePinHigh(en_pin);
+
+ // Drivers should start with all scaling and PWM registers as off
+ AW20216_init_current_limit(cs_pin);
+ AW20216_init_scaling(cs_pin);
+
+ AW20216_soft_enable(cs_pin);
+}
+
+void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ aw_led led = g_aw_leds[index];
+
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ g_pwm_buffer_update_required[led.driver] = true;
+}
+
+void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
+ AW20216_set_color(i, red, green, blue);
+ }
+}
+
+void AW20216_update_pwm_buffers(pin_t cs_pin, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ AW20216_write(cs_pin, AW_PAGE_PWM, 0, g_pwm_buffer[index], AW_PWM_REGISTER_COUNT);
+ }
+ g_pwm_buffer_update_required[index] = false;
+}
diff --git a/drivers/led/aw20216.h b/drivers/led/aw20216.h
new file mode 100644
index 0000000000..c55d9605fc
--- /dev/null
+++ b/drivers/led/aw20216.h
@@ -0,0 +1,252 @@
+/* Copyright 2021 Jasper Chan (Gigahawk)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+#include "gpio.h"
+
+typedef struct aw_led {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} aw_led;
+
+extern const aw_led g_aw_leds[DRIVER_LED_TOTAL];
+
+void AW20216_init(pin_t cs_pin, pin_t en_pin);
+void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+void AW20216_update_pwm_buffers(pin_t cs_pin, uint8_t index);
+
+#define CS1_SW1 0x00
+#define CS2_SW1 0x01
+#define CS3_SW1 0x02
+#define CS4_SW1 0x03
+#define CS5_SW1 0x04
+#define CS6_SW1 0x05
+#define CS7_SW1 0x06
+#define CS8_SW1 0x07
+#define CS9_SW1 0x08
+#define CS10_SW1 0x09
+#define CS11_SW1 0x0A
+#define CS12_SW1 0x0B
+#define CS13_SW1 0x0C
+#define CS14_SW1 0x0D
+#define CS15_SW1 0x0E
+#define CS16_SW1 0x0F
+#define CS17_SW1 0x10
+#define CS18_SW1 0x11
+#define CS1_SW2 0x12
+#define CS2_SW2 0x13
+#define CS3_SW2 0x14
+#define CS4_SW2 0x15
+#define CS5_SW2 0x16
+#define CS6_SW2 0x17
+#define CS7_SW2 0x18
+#define CS8_SW2 0x19
+#define CS9_SW2 0x1A
+#define CS10_SW2 0x1B
+#define CS11_SW2 0x1C
+#define CS12_SW2 0x1D
+#define CS13_SW2 0x1E
+#define CS14_SW2 0x1F
+#define CS15_SW2 0x20
+#define CS16_SW2 0x21
+#define CS17_SW2 0x22
+#define CS18_SW2 0x23
+#define CS1_SW3 0x24
+#define CS2_SW3 0x25
+#define CS3_SW3 0x26
+#define CS4_SW3 0x27
+#define CS5_SW3 0x28
+#define CS6_SW3 0x29
+#define CS7_SW3 0x2A
+#define CS8_SW3 0x2B
+#define CS9_SW3 0x2C
+#define CS10_SW3 0x2D
+#define CS11_SW3 0x2E
+#define CS12_SW3 0x2F
+#define CS13_SW3 0x30
+#define CS14_SW3 0x31
+#define CS15_SW3 0x32
+#define CS16_SW3 0x33
+#define CS17_SW3 0x34
+#define CS18_SW3 0x35
+#define CS1_SW4 0x36
+#define CS2_SW4 0x37
+#define CS3_SW4 0x38
+#define CS4_SW4 0x39
+#define CS5_SW4 0x3A
+#define CS6_SW4 0x3B
+#define CS7_SW4 0x3C
+#define CS8_SW4 0x3D
+#define CS9_SW4 0x3E
+#define CS10_SW4 0x3F
+#define CS11_SW4 0x40
+#define CS12_SW4 0x41
+#define CS13_SW4 0x42
+#define CS14_SW4 0x43
+#define CS15_SW4 0x44
+#define CS16_SW4 0x45
+#define CS17_SW4 0x46
+#define CS18_SW4 0x47
+#define CS1_SW5 0x48
+#define CS2_SW5 0x49
+#define CS3_SW5 0x4A
+#define CS4_SW5 0x4B
+#define CS5_SW5 0x4C
+#define CS6_SW5 0x4D
+#define CS7_SW5 0x4E
+#define CS8_SW5 0x4F
+#define CS9_SW5 0x50
+#define CS10_SW5 0x51
+#define CS11_SW5 0x52
+#define CS12_SW5 0x53
+#define CS13_SW5 0x54
+#define CS14_SW5 0x55
+#define CS15_SW5 0x56
+#define CS16_SW5 0x57
+#define CS17_SW5 0x58
+#define CS18_SW5 0x59
+#define CS1_SW6 0x5A
+#define CS2_SW6 0x5B
+#define CS3_SW6 0x5C
+#define CS4_SW6 0x5D
+#define CS5_SW6 0x5E
+#define CS6_SW6 0x5F
+#define CS7_SW6 0x60
+#define CS8_SW6 0x61
+#define CS9_SW6 0x62
+#define CS10_SW6 0x63
+#define CS11_SW6 0x64
+#define CS12_SW6 0x65
+#define CS13_SW6 0x66
+#define CS14_SW6 0x67
+#define CS15_SW6 0x68
+#define CS16_SW6 0x69
+#define CS17_SW6 0x6A
+#define CS18_SW6 0x6B
+#define CS1_SW7 0x6C
+#define CS2_SW7 0x6D
+#define CS3_SW7 0x6E
+#define CS4_SW7 0x6F
+#define CS5_SW7 0x70
+#define CS6_SW7 0x71
+#define CS7_SW7 0x72
+#define CS8_SW7 0x73
+#define CS9_SW7 0x74
+#define CS10_SW7 0x75
+#define CS11_SW7 0x76
+#define CS12_SW7 0x77
+#define CS13_SW7 0x78
+#define CS14_SW7 0x79
+#define CS15_SW7 0x7A
+#define CS16_SW7 0x7B
+#define CS17_SW7 0x7C
+#define CS18_SW7 0x7D
+#define CS1_SW8 0x7E
+#define CS2_SW8 0x7F
+#define CS3_SW8 0x80
+#define CS4_SW8 0x81
+#define CS5_SW8 0x82
+#define CS6_SW8 0x83
+#define CS7_SW8 0x84
+#define CS8_SW8 0x85
+#define CS9_SW8 0x86
+#define CS10_SW8 0x87
+#define CS11_SW8 0x88
+#define CS12_SW8 0x89
+#define CS13_SW8 0x8A
+#define CS14_SW8 0x8B
+#define CS15_SW8 0x8C
+#define CS16_SW8 0x8D
+#define CS17_SW8 0x8E
+#define CS18_SW8 0x8F
+#define CS1_SW9 0x90
+#define CS2_SW9 0x91
+#define CS3_SW9 0x92
+#define CS4_SW9 0x93
+#define CS5_SW9 0x94
+#define CS6_SW9 0x95
+#define CS7_SW9 0x96
+#define CS8_SW9 0x97
+#define CS9_SW9 0x98
+#define CS10_SW9 0x99
+#define CS11_SW9 0x9A
+#define CS12_SW9 0x9B
+#define CS13_SW9 0x9C
+#define CS14_SW9 0x9D
+#define CS15_SW9 0x9E
+#define CS16_SW9 0x9F
+#define CS17_SW9 0xA0
+#define CS18_SW9 0xA1
+#define CS1_SW10 0xA2
+#define CS2_SW10 0xA3
+#define CS3_SW10 0xA4
+#define CS4_SW10 0xA5
+#define CS5_SW10 0xA6
+#define CS6_SW10 0xA7
+#define CS7_SW10 0xA8
+#define CS8_SW10 0xA9
+#define CS9_SW10 0xAA
+#define CS10_SW10 0xAB
+#define CS11_SW10 0xAC
+#define CS12_SW10 0xAD
+#define CS13_SW10 0xAE
+#define CS14_SW10 0xAF
+#define CS15_SW10 0xB0
+#define CS16_SW10 0xB1
+#define CS17_SW10 0xB2
+#define CS18_SW10 0xB3
+#define CS1_SW11 0xB4
+#define CS2_SW11 0xB5
+#define CS3_SW11 0xB6
+#define CS4_SW11 0xB7
+#define CS5_SW11 0xB8
+#define CS6_SW11 0xB9
+#define CS7_SW11 0xBA
+#define CS8_SW11 0xBB
+#define CS9_SW11 0xBC
+#define CS10_SW11 0xBD
+#define CS11_SW11 0xBE
+#define CS12_SW11 0xBF
+#define CS13_SW11 0xC0
+#define CS14_SW11 0xC1
+#define CS15_SW11 0xC2
+#define CS16_SW11 0xC3
+#define CS17_SW11 0xC4
+#define CS18_SW11 0xC5
+#define CS1_SW12 0xC6
+#define CS2_SW12 0xC7
+#define CS3_SW12 0xC8
+#define CS4_SW12 0xC9
+#define CS5_SW12 0xCA
+#define CS6_SW12 0xCB
+#define CS7_SW12 0xCC
+#define CS8_SW12 0xCD
+#define CS9_SW12 0xCE
+#define CS10_SW12 0xCF
+#define CS11_SW12 0xD0
+#define CS12_SW12 0xD1
+#define CS13_SW12 0xD2
+#define CS14_SW12 0xD3
+#define CS15_SW12 0xD4
+#define CS16_SW12 0xD5
+#define CS17_SW12 0xD6
+#define CS18_SW12 0xD7
diff --git a/drivers/led/issi/is31fl3218.c b/drivers/led/issi/is31fl3218.c
new file mode 100644
index 0000000000..d43863ac4b
--- /dev/null
+++ b/drivers/led/issi/is31fl3218.c
@@ -0,0 +1,96 @@
+/* Copyright 2018 Jason Williams (Wilba)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#include "is31fl3218.h"
+#include "i2c_master.h"
+
+// This is the full 8-bit address
+#define ISSI_ADDRESS 0b10101000
+
+// These are the register addresses
+#define ISSI_REG_SHUTDOWN 0x00
+#define ISSI_REG_PWM 0x01
+#define ISSI_REG_CONTROL 0x13
+#define ISSI_REG_UPDATE 0x16
+#define ISSI_REG_RESET 0x17
+
+// Default timeout if no I2C response
+#define ISSI_TIMEOUT 100
+
+// Reusable buffer for transfers
+uint8_t g_twi_transfer_buffer[20];
+
+// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
+// If used as RGB LED driver, LEDs are assigned RGB,RGB,RGB,RGB,RGB,RGB
+uint8_t g_pwm_buffer[18];
+bool g_pwm_buffer_update_required = false;
+
+void IS31FL3218_write_register(uint8_t reg, uint8_t data) {
+ g_twi_transfer_buffer[0] = reg;
+ g_twi_transfer_buffer[1] = data;
+ i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
+}
+
+void IS31FL3218_write_pwm_buffer(uint8_t *pwm_buffer) {
+ g_twi_transfer_buffer[0] = ISSI_REG_PWM;
+ for (int i = 0; i < 18; i++) {
+ g_twi_transfer_buffer[1 + i] = pwm_buffer[i];
+ }
+
+ i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT);
+}
+
+void IS31FL3218_init(void) {
+ // In case we ever want to reinitialize (?)
+ IS31FL3218_write_register(ISSI_REG_RESET, 0x00);
+
+ // Turn off software shutdown
+ IS31FL3218_write_register(ISSI_REG_SHUTDOWN, 0x01);
+
+ // Set all PWM values to zero
+ for (uint8_t i = 0; i < 18; i++) {
+ IS31FL3218_write_register(ISSI_REG_PWM + i, 0x00);
+ }
+
+ // Enable all channels
+ for (uint8_t i = 0; i < 3; i++) {
+ IS31FL3218_write_register(ISSI_REG_CONTROL + i, 0b00111111);
+ }
+
+ // Load PWM registers and LED Control register data
+ IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01);
+}
+
+void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ g_pwm_buffer[index * 3 + 0] = red;
+ g_pwm_buffer[index * 3 + 1] = green;
+ g_pwm_buffer[index * 3 + 2] = blue;
+ g_pwm_buffer_update_required = true;
+}
+
+void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < 6; i++) {
+ IS31FL3218_set_color(i, red, green, blue);
+ }
+}
+
+void IS31FL3218_update_pwm_buffers(void) {
+ if (g_pwm_buffer_update_required) {
+ IS31FL3218_write_pwm_buffer(g_pwm_buffer);
+ // Load PWM registers and LED Control register data
+ IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01);
+ }
+ g_pwm_buffer_update_required = false;
+}
diff --git a/drivers/led/issi/is31fl3218.h b/drivers/led/issi/is31fl3218.h
new file mode 100644
index 0000000000..fa760da191
--- /dev/null
+++ b/drivers/led/issi/is31fl3218.h
@@ -0,0 +1,25 @@
+/* Copyright 2018 Jason Williams (Wilba)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+void IS31FL3218_init(void);
+void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3218_update_pwm_buffers(void);
diff --git a/drivers/led/issi/is31fl3731-simple.c b/drivers/led/issi/is31fl3731-simple.c
new file mode 100644
index 0000000000..d295772f5e
--- /dev/null
+++ b/drivers/led/issi/is31fl3731-simple.c
@@ -0,0 +1,233 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2019 Clueboard
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "is31fl3731-simple.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+// This is a 7-bit address, that gets left-shifted and bit 0
+// set to 0 for write, 1 for read (as per I2C protocol)
+// The address will vary depending on your wiring:
+// 0b1110100 AD <-> GND
+// 0b1110111 AD <-> VCC
+// 0b1110101 AD <-> SCL
+// 0b1110110 AD <-> SDA
+#define ISSI_ADDR_DEFAULT 0x74
+
+#define ISSI_REG_CONFIG 0x00
+#define ISSI_REG_CONFIG_PICTUREMODE 0x00
+#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08
+#define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18
+
+#define ISSI_CONF_PICTUREMODE 0x00
+#define ISSI_CONF_AUTOFRAMEMODE 0x04
+#define ISSI_CONF_AUDIOMODE 0x08
+
+#define ISSI_REG_PICTUREFRAME 0x01
+
+#define ISSI_REG_SHUTDOWN 0x0A
+#define ISSI_REG_AUDIOSYNC 0x06
+
+#define ISSI_COMMANDREGISTER 0xFD
+#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
+
+#ifndef ISSI_TIMEOUT
+# define ISSI_TIMEOUT 100
+#endif
+
+#ifndef ISSI_PERSISTENCE
+# define ISSI_PERSISTENCE 0
+#endif
+
+// Transfer buffer for TWITransmitData()
+uint8_t g_twi_transfer_buffer[20];
+
+// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
+// Storing them like this is optimal for I2C transfers to the registers.
+// We could optimize this and take out the unused registers from these
+// buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's
+// probably not worth the extra complexity.
+uint8_t g_pwm_buffer[LED_DRIVER_COUNT][144];
+bool g_pwm_buffer_update_required[LED_DRIVER_COUNT] = {false};
+
+/* There's probably a better way to init this... */
+#if LED_DRIVER_COUNT == 1
+uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}};
+#elif LED_DRIVER_COUNT == 2
+uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}};
+#elif LED_DRIVER_COUNT == 3
+uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}};
+#elif LED_DRIVER_COUNT == 4
+uint8_t g_led_control_registers[LED_DRIVER_COUNT][18] = {{0}, {0}, {0}, {0}};
+#endif
+bool g_led_control_registers_update_required[LED_DRIVER_COUNT] = {false};
+
+// This is the bit pattern in the LED control registers
+// (for matrix A, add one to register for matrix B)
+//
+// reg - b7 b6 b5 b4 b3 b2 b1 b0
+// 0x00 - R08,R07,R06,R05,R04,R03,R02,R01
+// 0x02 - G08,G07,G06,G05,G04,G03,G02,R00
+// 0x04 - B08,B07,B06,B05,B04,B03,G01,G00
+// 0x06 - - , - , - , - , - ,B02,B01,B00
+// 0x08 - - , - , - , - , - , - , - , -
+// 0x0A - B17,B16,B15, - , - , - , - , -
+// 0x0C - G17,G16,B14,B13,B12,B11,B10,B09
+// 0x0E - R17,G15,G14,G13,G12,G11,G10,G09
+// 0x10 - R16,R15,R14,R13,R12,R11,R10,R09
+
+void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+ g_twi_transfer_buffer[0] = reg;
+ g_twi_transfer_buffer[1] = data;
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) {
+ break;
+ }
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
+#endif
+}
+
+void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
+ // assumes bank is already selected
+
+ // transmit PWM registers in 9 transfers of 16 bytes
+ // g_twi_transfer_buffer[] is 20 bytes
+
+ // iterate over the pwm_buffer contents at 16 byte intervals
+ for (int i = 0; i < 144; i += 16) {
+ // set the first register, e.g. 0x24, 0x34, 0x44, etc.
+ g_twi_transfer_buffer[0] = 0x24 + i;
+ // copy the data from i to i+15
+ // device will auto-increment register for data after the first byte
+ // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer
+ for (int j = 0; j < 16; j++) {
+ g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
+ }
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
+ }
+}
+
+void IS31FL3731_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, first enable software shutdown,
+ // then set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ // select "function register" bank
+ IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
+
+ // enable software shutdown
+ IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00);
+
+ // this delay was copied from other drivers, might not be needed
+ wait_ms(10);
+
+ // picture mode
+ IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE);
+ // display frame 0
+ IS31FL3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00);
+ // audio sync off
+ IS31FL3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00);
+
+ // select bank 0
+ IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
+
+ // turn off all LEDs in the LED control register
+ for (int i = 0x00; i <= 0x11; i++) {
+ IS31FL3731_write_register(addr, i, 0x00);
+ }
+
+ // turn off all LEDs in the blink control register (not really needed)
+ for (int i = 0x12; i <= 0x23; i++) {
+ IS31FL3731_write_register(addr, i, 0x00);
+ }
+
+ // set PWM on all LEDs to 0
+ for (int i = 0x24; i <= 0xB3; i++) {
+ IS31FL3731_write_register(addr, i, 0x00);
+ }
+
+ // select "function register" bank
+ IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
+
+ // disable software shutdown
+ IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01);
+
+ // select bank 0 and leave it selected.
+ // most usage after initialization is just writing PWM buffers in bank 0
+ // as there's not much point in double-buffering
+ IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
+}
+
+void IS31FL3731_set_value(int index, uint8_t value) {
+ if (index >= 0 && index < DRIVER_LED_TOTAL) {
+ is31_led led = g_is31_leds[index];
+
+ // Subtract 0x24 to get the second index of g_pwm_buffer
+ g_pwm_buffer[led.driver][led.v - 0x24] = value;
+ g_pwm_buffer_update_required[led.driver] = true;
+ }
+}
+
+void IS31FL3731_set_value_all(uint8_t value) {
+ for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+ IS31FL3731_set_value(i, value);
+ }
+}
+
+void IS31FL3731_set_led_control_register(uint8_t index, bool value) {
+ is31_led led = g_is31_leds[index];
+
+ uint8_t control_register = (led.v - 0x24) / 8;
+ uint8_t bit_value = (led.v - 0x24) % 8;
+
+ if (value) {
+ g_led_control_registers[led.driver][control_register] |= (1 << bit_value);
+ } else {
+ g_led_control_registers[led.driver][control_register] &= ~(1 << bit_value);
+ }
+
+ g_led_control_registers_update_required[led.driver] = true;
+}
+
+void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ IS31FL3731_write_pwm_buffer(addr, g_pwm_buffer[index]);
+ g_pwm_buffer_update_required[index] = false;
+ }
+}
+
+void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index) {
+ if (g_led_control_registers_update_required[index]) {
+ for (int i = 0; i < 18; i++) {
+ IS31FL3731_write_register(addr, i, g_led_control_registers[index][i]);
+ }
+ g_led_control_registers_update_required[index] = false;
+ }
+}
diff --git a/drivers/led/issi/is31fl3731-simple.h b/drivers/led/issi/is31fl3731-simple.h
new file mode 100644
index 0000000000..9665d6ed35
--- /dev/null
+++ b/drivers/led/issi/is31fl3731-simple.h
@@ -0,0 +1,207 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2019 Clueboard
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+typedef struct is31_led {
+ uint8_t driver : 2;
+ uint8_t v;
+} __attribute__((packed)) is31_led;
+
+extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+
+void IS31FL3731_init(uint8_t addr);
+void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+
+void IS31FL3731_set_value(int index, uint8_t value);
+void IS31FL3731_set_value_all(uint8_t value);
+
+void IS31FL3731_set_led_control_register(uint8_t index, bool value);
+
+// This should not be called from an interrupt
+// (eg. from a timer interrupt).
+// Call this while idle (in between matrix scans).
+// If the buffer is dirty, it will update the driver with the buffer.
+void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index);
+void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
+
+#define C1_1 0x24
+#define C1_2 0x25
+#define C1_3 0x26
+#define C1_4 0x27
+#define C1_5 0x28
+#define C1_6 0x29
+#define C1_7 0x2A
+#define C1_8 0x2B
+
+#define C1_9 0x2C
+#define C1_10 0x2D
+#define C1_11 0x2E
+#define C1_12 0x2F
+#define C1_13 0x30
+#define C1_14 0x31
+#define C1_15 0x32
+#define C1_16 0x33
+
+#define C2_1 0x34
+#define C2_2 0x35
+#define C2_3 0x36
+#define C2_4 0x37
+#define C2_5 0x38
+#define C2_6 0x39
+#define C2_7 0x3A
+#define C2_8 0x3B
+
+#define C2_9 0x3C
+#define C2_10 0x3D
+#define C2_11 0x3E
+#define C2_12 0x3F
+#define C2_13 0x40
+#define C2_14 0x41
+#define C2_15 0x42
+#define C2_16 0x43
+
+#define C3_1 0x44
+#define C3_2 0x45
+#define C3_3 0x46
+#define C3_4 0x47
+#define C3_5 0x48
+#define C3_6 0x49
+#define C3_7 0x4A
+#define C3_8 0x4B
+
+#define C3_9 0x4C
+#define C3_10 0x4D
+#define C3_11 0x4E
+#define C3_12 0x4F
+#define C3_13 0x50
+#define C3_14 0x51
+#define C3_15 0x52
+#define C3_16 0x53
+
+#define C4_1 0x54
+#define C4_2 0x55
+#define C4_3 0x56
+#define C4_4 0x57
+#define C4_5 0x58
+#define C4_6 0x59
+#define C4_7 0x5A
+#define C4_8 0x5B
+
+#define C4_9 0x5C
+#define C4_10 0x5D
+#define C4_11 0x5E
+#define C4_12 0x5F
+#define C4_13 0x60
+#define C4_14 0x61
+#define C4_15 0x62
+#define C4_16 0x63
+
+#define C5_1 0x64
+#define C5_2 0x65
+#define C5_3 0x66
+#define C5_4 0x67
+#define C5_5 0x68
+#define C5_6 0x69
+#define C5_7 0x6A
+#define C5_8 0x6B
+
+#define C5_9 0x6C
+#define C5_10 0x6D
+#define C5_11 0x6E
+#define C5_12 0x6F
+#define C5_13 0x70
+#define C5_14 0x71
+#define C5_15 0x72
+#define C5_16 0x73
+
+#define C6_1 0x74
+#define C6_2 0x75
+#define C6_3 0x76
+#define C6_4 0x77
+#define C6_5 0x78
+#define C6_6 0x79
+#define C6_7 0x7A
+#define C6_8 0x7B
+
+#define C6_9 0x7C
+#define C6_10 0x7D
+#define C6_11 0x7E
+#define C6_12 0x7F
+#define C6_13 0x80
+#define C6_14 0x81
+#define C6_15 0x82
+#define C6_16 0x83
+
+#define C7_1 0x84
+#define C7_2 0x85
+#define C7_3 0x86
+#define C7_4 0x87
+#define C7_5 0x88
+#define C7_6 0x89
+#define C7_7 0x8A
+#define C7_8 0x8B
+
+#define C7_9 0x8C
+#define C7_10 0x8D
+#define C7_11 0x8E
+#define C7_12 0x8F
+#define C7_13 0x90
+#define C7_14 0x91
+#define C7_15 0x92
+#define C7_16 0x93
+
+#define C8_1 0x94
+#define C8_2 0x95
+#define C8_3 0x96
+#define C8_4 0x97
+#define C8_5 0x98
+#define C8_6 0x99
+#define C8_7 0x9A
+#define C8_8 0x9B
+
+#define C8_9 0x9C
+#define C8_10 0x9D
+#define C8_11 0x9E
+#define C8_12 0x9F
+#define C8_13 0xA0
+#define C8_14 0xA1
+#define C8_15 0xA2
+#define C8_16 0xA3
+
+#define C9_1 0xA4
+#define C9_2 0xA5
+#define C9_3 0xA6
+#define C9_4 0xA7
+#define C9_5 0xA8
+#define C9_6 0xA9
+#define C9_7 0xAA
+#define C9_8 0xAB
+
+#define C9_9 0xAC
+#define C9_10 0xAD
+#define C9_11 0xAE
+#define C9_12 0xAF
+#define C9_13 0xB0
+#define C9_14 0xB1
+#define C9_15 0xB2
+#define C9_16 0xB3
diff --git a/drivers/led/issi/is31fl3731.c b/drivers/led/issi/is31fl3731.c
new file mode 100644
index 0000000000..110bdc1be4
--- /dev/null
+++ b/drivers/led/issi/is31fl3731.c
@@ -0,0 +1,237 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "is31fl3731.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+// This is a 7-bit address, that gets left-shifted and bit 0
+// set to 0 for write, 1 for read (as per I2C protocol)
+// The address will vary depending on your wiring:
+// 0b1110100 AD <-> GND
+// 0b1110111 AD <-> VCC
+// 0b1110101 AD <-> SCL
+// 0b1110110 AD <-> SDA
+#define ISSI_ADDR_DEFAULT 0x74
+
+#define ISSI_REG_CONFIG 0x00
+#define ISSI_REG_CONFIG_PICTUREMODE 0x00
+#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08
+#define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18
+
+#define ISSI_CONF_PICTUREMODE 0x00
+#define ISSI_CONF_AUTOFRAMEMODE 0x04
+#define ISSI_CONF_AUDIOMODE 0x08
+
+#define ISSI_REG_PICTUREFRAME 0x01
+
+#define ISSI_REG_SHUTDOWN 0x0A
+#define ISSI_REG_AUDIOSYNC 0x06
+
+#define ISSI_COMMANDREGISTER 0xFD
+#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
+
+#ifndef ISSI_TIMEOUT
+# define ISSI_TIMEOUT 100
+#endif
+
+#ifndef ISSI_PERSISTENCE
+# define ISSI_PERSISTENCE 0
+#endif
+
+// Transfer buffer for TWITransmitData()
+uint8_t g_twi_transfer_buffer[20];
+
+// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
+// Storing them like this is optimal for I2C transfers to the registers.
+// We could optimize this and take out the unused registers from these
+// buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's
+// probably not worth the extra complexity.
+uint8_t g_pwm_buffer[DRIVER_COUNT][144];
+bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
+
+uint8_t g_led_control_registers[DRIVER_COUNT][18] = {{0}};
+bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
+
+// This is the bit pattern in the LED control registers
+// (for matrix A, add one to register for matrix B)
+//
+// reg - b7 b6 b5 b4 b3 b2 b1 b0
+// 0x00 - R08,R07,R06,R05,R04,R03,R02,R01
+// 0x02 - G08,G07,G06,G05,G04,G03,G02,R00
+// 0x04 - B08,B07,B06,B05,B04,B03,G01,G00
+// 0x06 - - , - , - , - , - ,B02,B01,B00
+// 0x08 - - , - , - , - , - , - , - , -
+// 0x0A - B17,B16,B15, - , - , - , - , -
+// 0x0C - G17,G16,B14,B13,B12,B11,B10,B09
+// 0x0E - R17,G15,G14,G13,G12,G11,G10,G09
+// 0x10 - R16,R15,R14,R13,R12,R11,R10,R09
+
+void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+ g_twi_transfer_buffer[0] = reg;
+ g_twi_transfer_buffer[1] = data;
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
+#endif
+}
+
+void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
+ // assumes bank is already selected
+
+ // transmit PWM registers in 9 transfers of 16 bytes
+ // g_twi_transfer_buffer[] is 20 bytes
+
+ // iterate over the pwm_buffer contents at 16 byte intervals
+ for (int i = 0; i < 144; i += 16) {
+ // set the first register, e.g. 0x24, 0x34, 0x44, etc.
+ g_twi_transfer_buffer[0] = 0x24 + i;
+ // copy the data from i to i+15
+ // device will auto-increment register for data after the first byte
+ // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer
+ for (int j = 0; j < 16; j++) {
+ g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
+ }
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
+ }
+}
+
+void IS31FL3731_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, first enable software shutdown,
+ // then set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ // select "function register" bank
+ IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
+
+ // enable software shutdown
+ IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00);
+
+ // this delay was copied from other drivers, might not be needed
+ wait_ms(10);
+
+ // picture mode
+ IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE);
+ // display frame 0
+ IS31FL3731_write_register(addr, ISSI_REG_PICTUREFRAME, 0x00);
+ // audio sync off
+ IS31FL3731_write_register(addr, ISSI_REG_AUDIOSYNC, 0x00);
+
+ // select bank 0
+ IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
+
+ // turn off all LEDs in the LED control register
+ for (int i = 0x00; i <= 0x11; i++) {
+ IS31FL3731_write_register(addr, i, 0x00);
+ }
+
+ // turn off all LEDs in the blink control register (not really needed)
+ for (int i = 0x12; i <= 0x23; i++) {
+ IS31FL3731_write_register(addr, i, 0x00);
+ }
+
+ // set PWM on all LEDs to 0
+ for (int i = 0x24; i <= 0xB3; i++) {
+ IS31FL3731_write_register(addr, i, 0x00);
+ }
+
+ // select "function register" bank
+ IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG);
+
+ // disable software shutdown
+ IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x01);
+
+ // select bank 0 and leave it selected.
+ // most usage after initialization is just writing PWM buffers in bank 0
+ // as there's not much point in double-buffering
+ IS31FL3731_write_register(addr, ISSI_COMMANDREGISTER, 0);
+}
+
+void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ if (index >= 0 && index < DRIVER_LED_TOTAL) {
+ is31_led led = g_is31_leds[index];
+
+ // Subtract 0x24 to get the second index of g_pwm_buffer
+ g_pwm_buffer[led.driver][led.r - 0x24] = red;
+ g_pwm_buffer[led.driver][led.g - 0x24] = green;
+ g_pwm_buffer[led.driver][led.b - 0x24] = blue;
+ g_pwm_buffer_update_required[led.driver] = true;
+ }
+}
+
+void IS31FL3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+ IS31FL3731_set_color(i, red, green, blue);
+ }
+}
+
+void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
+ is31_led led = g_is31_leds[index];
+
+ uint8_t control_register_r = (led.r - 0x24) / 8;
+ uint8_t control_register_g = (led.g - 0x24) / 8;
+ uint8_t control_register_b = (led.b - 0x24) / 8;
+ uint8_t bit_r = (led.r - 0x24) % 8;
+ uint8_t bit_g = (led.g - 0x24) % 8;
+ uint8_t bit_b = (led.b - 0x24) % 8;
+
+ if (red) {
+ g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
+ } else {
+ g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
+ }
+ if (green) {
+ g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
+ } else {
+ g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
+ }
+ if (blue) {
+ g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
+ } else {
+ g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
+ }
+
+ g_led_control_registers_update_required[led.driver] = true;
+}
+
+void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ IS31FL3731_write_pwm_buffer(addr, g_pwm_buffer[index]);
+ }
+ g_pwm_buffer_update_required[index] = false;
+}
+
+void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index) {
+ if (g_led_control_registers_update_required[index]) {
+ for (int i = 0; i < 18; i++) {
+ IS31FL3731_write_register(addr, i, g_led_control_registers[index][i]);
+ }
+ }
+ g_led_control_registers_update_required[index] = false;
+}
diff --git a/drivers/led/issi/is31fl3731.h b/drivers/led/issi/is31fl3731.h
new file mode 100644
index 0000000000..19e8e6251f
--- /dev/null
+++ b/drivers/led/issi/is31fl3731.h
@@ -0,0 +1,208 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+typedef struct is31_led {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} __attribute__((packed)) is31_led;
+
+extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+
+void IS31FL3731_init(uint8_t addr);
+void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void IS31FL3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+
+void IS31FL3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void IS31FL3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
+
+// This should not be called from an interrupt
+// (eg. from a timer interrupt).
+// Call this while idle (in between matrix scans).
+// If the buffer is dirty, it will update the driver with the buffer.
+void IS31FL3731_update_pwm_buffers(uint8_t addr, uint8_t index);
+void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
+
+#define C1_1 0x24
+#define C1_2 0x25
+#define C1_3 0x26
+#define C1_4 0x27
+#define C1_5 0x28
+#define C1_6 0x29
+#define C1_7 0x2A
+#define C1_8 0x2B
+
+#define C1_9 0x2C
+#define C1_10 0x2D
+#define C1_11 0x2E
+#define C1_12 0x2F
+#define C1_13 0x30
+#define C1_14 0x31
+#define C1_15 0x32
+#define C1_16 0x33
+
+#define C2_1 0x34
+#define C2_2 0x35
+#define C2_3 0x36
+#define C2_4 0x37
+#define C2_5 0x38
+#define C2_6 0x39
+#define C2_7 0x3A
+#define C2_8 0x3B
+
+#define C2_9 0x3C
+#define C2_10 0x3D
+#define C2_11 0x3E
+#define C2_12 0x3F
+#define C2_13 0x40
+#define C2_14 0x41
+#define C2_15 0x42
+#define C2_16 0x43
+
+#define C3_1 0x44
+#define C3_2 0x45
+#define C3_3 0x46
+#define C3_4 0x47
+#define C3_5 0x48
+#define C3_6 0x49
+#define C3_7 0x4A
+#define C3_8 0x4B
+
+#define C3_9 0x4C
+#define C3_10 0x4D
+#define C3_11 0x4E
+#define C3_12 0x4F
+#define C3_13 0x50
+#define C3_14 0x51
+#define C3_15 0x52
+#define C3_16 0x53
+
+#define C4_1 0x54
+#define C4_2 0x55
+#define C4_3 0x56
+#define C4_4 0x57
+#define C4_5 0x58
+#define C4_6 0x59
+#define C4_7 0x5A
+#define C4_8 0x5B
+
+#define C4_9 0x5C
+#define C4_10 0x5D
+#define C4_11 0x5E
+#define C4_12 0x5F
+#define C4_13 0x60
+#define C4_14 0x61
+#define C4_15 0x62
+#define C4_16 0x63
+
+#define C5_1 0x64
+#define C5_2 0x65
+#define C5_3 0x66
+#define C5_4 0x67
+#define C5_5 0x68
+#define C5_6 0x69
+#define C5_7 0x6A
+#define C5_8 0x6B
+
+#define C5_9 0x6C
+#define C5_10 0x6D
+#define C5_11 0x6E
+#define C5_12 0x6F
+#define C5_13 0x70
+#define C5_14 0x71
+#define C5_15 0x72
+#define C5_16 0x73
+
+#define C6_1 0x74
+#define C6_2 0x75
+#define C6_3 0x76
+#define C6_4 0x77
+#define C6_5 0x78
+#define C6_6 0x79
+#define C6_7 0x7A
+#define C6_8 0x7B
+
+#define C6_9 0x7C
+#define C6_10 0x7D
+#define C6_11 0x7E
+#define C6_12 0x7F
+#define C6_13 0x80
+#define C6_14 0x81
+#define C6_15 0x82
+#define C6_16 0x83
+
+#define C7_1 0x84
+#define C7_2 0x85
+#define C7_3 0x86
+#define C7_4 0x87
+#define C7_5 0x88
+#define C7_6 0x89
+#define C7_7 0x8A
+#define C7_8 0x8B
+
+#define C7_9 0x8C
+#define C7_10 0x8D
+#define C7_11 0x8E
+#define C7_12 0x8F
+#define C7_13 0x90
+#define C7_14 0x91
+#define C7_15 0x92
+#define C7_16 0x93
+
+#define C8_1 0x94
+#define C8_2 0x95
+#define C8_3 0x96
+#define C8_4 0x97
+#define C8_5 0x98
+#define C8_6 0x99
+#define C8_7 0x9A
+#define C8_8 0x9B
+
+#define C8_9 0x9C
+#define C8_10 0x9D
+#define C8_11 0x9E
+#define C8_12 0x9F
+#define C8_13 0xA0
+#define C8_14 0xA1
+#define C8_15 0xA2
+#define C8_16 0xA3
+
+#define C9_1 0xA4
+#define C9_2 0xA5
+#define C9_3 0xA6
+#define C9_4 0xA7
+#define C9_5 0xA8
+#define C9_6 0xA9
+#define C9_7 0xAA
+#define C9_8 0xAB
+
+#define C9_9 0xAC
+#define C9_10 0xAD
+#define C9_11 0xAE
+#define C9_12 0xAF
+#define C9_13 0xB0
+#define C9_14 0xB1
+#define C9_15 0xB2
+#define C9_16 0xB3
diff --git a/drivers/led/issi/is31fl3733.c b/drivers/led/issi/is31fl3733.c
new file mode 100644
index 0000000000..d99e5339c9
--- /dev/null
+++ b/drivers/led/issi/is31fl3733.c
@@ -0,0 +1,237 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "is31fl3733.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+// This is a 7-bit address, that gets left-shifted and bit 0
+// set to 0 for write, 1 for read (as per I2C protocol)
+// The address will vary depending on your wiring:
+// 00 <-> GND
+// 01 <-> SCL
+// 10 <-> SDA
+// 11 <-> VCC
+// ADDR1 represents A1:A0 of the 7-bit address.
+// ADDR2 represents A3:A2 of the 7-bit address.
+// The result is: 0b101(ADDR2)(ADDR1)
+#define ISSI_ADDR_DEFAULT 0x50
+
+#define ISSI_COMMANDREGISTER 0xFD
+#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
+#define ISSI_INTERRUPTMASKREGISTER 0xF0
+#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
+
+#define ISSI_PAGE_LEDCONTROL 0x00 // PG0
+#define ISSI_PAGE_PWM 0x01 // PG1
+#define ISSI_PAGE_AUTOBREATH 0x02 // PG2
+#define ISSI_PAGE_FUNCTION 0x03 // PG3
+
+#define ISSI_REG_CONFIGURATION 0x00 // PG3
+#define ISSI_REG_GLOBALCURRENT 0x01 // PG3
+#define ISSI_REG_RESET 0x11 // PG3
+#define ISSI_REG_SWPULLUP 0x0F // PG3
+#define ISSI_REG_CSPULLUP 0x10 // PG3
+
+#ifndef ISSI_TIMEOUT
+# define ISSI_TIMEOUT 100
+#endif
+
+#ifndef ISSI_PERSISTENCE
+# define ISSI_PERSISTENCE 0
+#endif
+
+// Transfer buffer for TWITransmitData()
+uint8_t g_twi_transfer_buffer[20];
+
+// These buffers match the IS31FL3733 PWM registers.
+// The control buffers match the PG0 LED On/Off registers.
+// Storing them like this is optimal for I2C transfers to the registers.
+// We could optimize this and take out the unused registers from these
+// buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's
+// probably not worth the extra complexity.
+uint8_t g_pwm_buffer[DRIVER_COUNT][192];
+bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
+
+uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
+bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
+
+bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+ // If the transaction fails function returns false.
+ g_twi_transfer_buffer[0] = reg;
+ g_twi_transfer_buffer[1] = data;
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) {
+ return false;
+ }
+ }
+#else
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) {
+ return false;
+ }
+#endif
+ return true;
+}
+
+bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
+ // Assumes PG1 is already selected.
+ // If any of the transactions fails function returns false.
+ // Transmit PWM registers in 12 transfers of 16 bytes.
+ // g_twi_transfer_buffer[] is 20 bytes
+
+ // Iterate over the pwm_buffer contents at 16 byte intervals.
+ for (int i = 0; i < 192; i += 16) {
+ g_twi_transfer_buffer[0] = i;
+ // Copy the data from i to i+15.
+ // Device will auto-increment register for data after the first byte
+ // Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
+ for (int j = 0; j < 16; j++) {
+ g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
+ }
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) {
+ return false;
+ }
+ }
+#else
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) {
+ return false;
+ }
+#endif
+ }
+ return true;
+}
+
+void IS31FL3733_init(uint8_t addr, uint8_t sync) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+ // Sync is passed so set it according to the datasheet.
+
+ // Unlock the command register.
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG0
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ // Turn off all LEDs.
+ for (int i = 0x00; i <= 0x17; i++) {
+ IS31FL3733_write_register(addr, i, 0x00);
+ }
+
+ // Unlock the command register.
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG1
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+ // Set PWM on all LEDs to 0
+ // No need to setup Breath registers to PWM as that is the default.
+ for (int i = 0x00; i <= 0xBF; i++) {
+ IS31FL3733_write_register(addr, i, 0x00);
+ }
+
+ // Unlock the command register.
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG3
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
+ // Set global current to maximum.
+ IS31FL3733_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
+ // Disable software shutdown.
+ IS31FL3733_write_register(addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ if (index >= 0 && index < DRIVER_LED_TOTAL) {
+ is31_led led = g_is31_leds[index];
+
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ g_pwm_buffer_update_required[led.driver] = true;
+ }
+}
+
+void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+ IS31FL3733_set_color(i, red, green, blue);
+ }
+}
+
+void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
+ is31_led led = g_is31_leds[index];
+
+ uint8_t control_register_r = led.r / 8;
+ uint8_t control_register_g = led.g / 8;
+ uint8_t control_register_b = led.b / 8;
+ uint8_t bit_r = led.r % 8;
+ uint8_t bit_g = led.g % 8;
+ uint8_t bit_b = led.b % 8;
+
+ if (red) {
+ g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
+ } else {
+ g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
+ }
+ if (green) {
+ g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
+ } else {
+ g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
+ }
+ if (blue) {
+ g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
+ } else {
+ g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
+ }
+
+ g_led_control_registers_update_required[led.driver] = true;
+}
+
+void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ // Firstly we need to unlock the command register and select PG1.
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+
+ // If any of the transactions fail we risk writing dirty PG0,
+ // refresh page 0 just in case.
+ if (!IS31FL3733_write_pwm_buffer(addr, g_pwm_buffer[index])) {
+ g_led_control_registers_update_required[index] = true;
+ }
+ }
+ g_pwm_buffer_update_required[index] = false;
+}
+
+void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index) {
+ if (g_led_control_registers_update_required[index]) {
+ // Firstly we need to unlock the command register and select PG0
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ for (int i = 0; i < 24; i++) {
+ IS31FL3733_write_register(addr, i, g_led_control_registers[index][i]);
+ }
+ }
+ g_led_control_registers_update_required[index] = false;
+}
diff --git a/drivers/led/issi/is31fl3733.h b/drivers/led/issi/is31fl3733.h
new file mode 100644
index 0000000000..603d505a13
--- /dev/null
+++ b/drivers/led/issi/is31fl3733.h
@@ -0,0 +1,251 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+typedef struct is31_led {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} __attribute__((packed)) is31_led;
+
+extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+
+void IS31FL3733_init(uint8_t addr, uint8_t sync);
+bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+
+void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
+
+// This should not be called from an interrupt
+// (eg. from a timer interrupt).
+// Call this while idle (in between matrix scans).
+// If the buffer is dirty, it will update the driver with the buffer.
+void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index);
+void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index);
+
+#define A_1 0x00
+#define A_2 0x01
+#define A_3 0x02
+#define A_4 0x03
+#define A_5 0x04
+#define A_6 0x05
+#define A_7 0x06
+#define A_8 0x07
+#define A_9 0x08
+#define A_10 0x09
+#define A_11 0x0A
+#define A_12 0x0B
+#define A_13 0x0C
+#define A_14 0x0D
+#define A_15 0x0E
+#define A_16 0x0F
+
+#define B_1 0x10
+#define B_2 0x11
+#define B_3 0x12
+#define B_4 0x13
+#define B_5 0x14
+#define B_6 0x15
+#define B_7 0x16
+#define B_8 0x17
+#define B_9 0x18
+#define B_10 0x19
+#define B_11 0x1A
+#define B_12 0x1B
+#define B_13 0x1C
+#define B_14 0x1D
+#define B_15 0x1E
+#define B_16 0x1F
+
+#define C_1 0x20
+#define C_2 0x21
+#define C_3 0x22
+#define C_4 0x23
+#define C_5 0x24
+#define C_6 0x25
+#define C_7 0x26
+#define C_8 0x27
+#define C_9 0x28
+#define C_10 0x29
+#define C_11 0x2A
+#define C_12 0x2B
+#define C_13 0x2C
+#define C_14 0x2D
+#define C_15 0x2E
+#define C_16 0x2F
+
+#define D_1 0x30
+#define D_2 0x31
+#define D_3 0x32
+#define D_4 0x33
+#define D_5 0x34
+#define D_6 0x35
+#define D_7 0x36
+#define D_8 0x37
+#define D_9 0x38
+#define D_10 0x39
+#define D_11 0x3A
+#define D_12 0x3B
+#define D_13 0x3C
+#define D_14 0x3D
+#define D_15 0x3E
+#define D_16 0x3F
+
+#define E_1 0x40
+#define E_2 0x41
+#define E_3 0x42
+#define E_4 0x43
+#define E_5 0x44
+#define E_6 0x45
+#define E_7 0x46
+#define E_8 0x47
+#define E_9 0x48
+#define E_10 0x49
+#define E_11 0x4A
+#define E_12 0x4B
+#define E_13 0x4C
+#define E_14 0x4D
+#define E_15 0x4E
+#define E_16 0x4F
+
+#define F_1 0x50
+#define F_2 0x51
+#define F_3 0x52
+#define F_4 0x53
+#define F_5 0x54
+#define F_6 0x55
+#define F_7 0x56
+#define F_8 0x57
+#define F_9 0x58
+#define F_10 0x59
+#define F_11 0x5A
+#define F_12 0x5B
+#define F_13 0x5C
+#define F_14 0x5D
+#define F_15 0x5E
+#define F_16 0x5F
+
+#define G_1 0x60
+#define G_2 0x61
+#define G_3 0x62
+#define G_4 0x63
+#define G_5 0x64
+#define G_6 0x65
+#define G_7 0x66
+#define G_8 0x67
+#define G_9 0x68
+#define G_10 0x69
+#define G_11 0x6A
+#define G_12 0x6B
+#define G_13 0x6C
+#define G_14 0x6D
+#define G_15 0x6E
+#define G_16 0x6F
+
+#define H_1 0x70
+#define H_2 0x71
+#define H_3 0x72
+#define H_4 0x73
+#define H_5 0x74
+#define H_6 0x75
+#define H_7 0x76
+#define H_8 0x77
+#define H_9 0x78
+#define H_10 0x79
+#define H_11 0x7A
+#define H_12 0x7B
+#define H_13 0x7C
+#define H_14 0x7D
+#define H_15 0x7E
+#define H_16 0x7F
+
+#define I_1 0x80
+#define I_2 0x81
+#define I_3 0x82
+#define I_4 0x83
+#define I_5 0x84
+#define I_6 0x85
+#define I_7 0x86
+#define I_8 0x87
+#define I_9 0x88
+#define I_10 0x89
+#define I_11 0x8A
+#define I_12 0x8B
+#define I_13 0x8C
+#define I_14 0x8D
+#define I_15 0x8E
+#define I_16 0x8F
+
+#define J_1 0x90
+#define J_2 0x91
+#define J_3 0x92
+#define J_4 0x93
+#define J_5 0x94
+#define J_6 0x95
+#define J_7 0x96
+#define J_8 0x97
+#define J_9 0x98
+#define J_10 0x99
+#define J_11 0x9A
+#define J_12 0x9B
+#define J_13 0x9C
+#define J_14 0x9D
+#define J_15 0x9E
+#define J_16 0x9F
+
+#define K_1 0xA0
+#define K_2 0xA1
+#define K_3 0xA2
+#define K_4 0xA3
+#define K_5 0xA4
+#define K_6 0xA5
+#define K_7 0xA6
+#define K_8 0xA7
+#define K_9 0xA8
+#define K_10 0xA9
+#define K_11 0xAA
+#define K_12 0xAB
+#define K_13 0xAC
+#define K_14 0xAD
+#define K_15 0xAE
+#define K_16 0xAF
+
+#define L_1 0xB0
+#define L_2 0xB1
+#define L_3 0xB2
+#define L_4 0xB3
+#define L_5 0xB4
+#define L_6 0xB5
+#define L_7 0xB6
+#define L_8 0xB7
+#define L_9 0xB8
+#define L_10 0xB9
+#define L_11 0xBA
+#define L_12 0xBB
+#define L_13 0xBC
+#define L_14 0xBD
+#define L_15 0xBE
+#define L_16 0xBF
diff --git a/drivers/led/issi/is31fl3736.c b/drivers/led/issi/is31fl3736.c
new file mode 100644
index 0000000000..7dece1b1eb
--- /dev/null
+++ b/drivers/led/issi/is31fl3736.c
@@ -0,0 +1,269 @@
+/* Copyright 2018 Jason Williams (Wilba)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "is31fl3736.h"
+#include "i2c_master.h"
+#include "wait.h"
+
+// This is a 7-bit address, that gets left-shifted and bit 0
+// set to 0 for write, 1 for read (as per I2C protocol)
+// The address will vary depending on your wiring:
+// 00 <-> GND
+// 01 <-> SCL
+// 10 <-> SDA
+// 11 <-> VCC
+// ADDR1 represents A1:A0 of the 7-bit address.
+// ADDR2 represents A3:A2 of the 7-bit address.
+// The result is: 0b101(ADDR2)(ADDR1)
+#define ISSI_ADDR_DEFAULT 0x50
+
+#define ISSI_COMMANDREGISTER 0xFD
+#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
+#define ISSI_INTERRUPTMASKREGISTER 0xF0
+#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
+
+#define ISSI_PAGE_LEDCONTROL 0x00 // PG0
+#define ISSI_PAGE_PWM 0x01 // PG1
+#define ISSI_PAGE_AUTOBREATH 0x02 // PG2
+#define ISSI_PAGE_FUNCTION 0x03 // PG3
+
+#define ISSI_REG_CONFIGURATION 0x00 // PG3
+#define ISSI_REG_GLOBALCURRENT 0x01 // PG3
+#define ISSI_REG_RESET 0x11 // PG3
+#define ISSI_REG_SWPULLUP 0x0F // PG3
+#define ISSI_REG_CSPULLUP 0x10 // PG3
+
+#ifndef ISSI_TIMEOUT
+# define ISSI_TIMEOUT 100
+#endif
+
+#ifndef ISSI_PERSISTENCE
+# define ISSI_PERSISTENCE 0
+#endif
+
+// Transfer buffer for TWITransmitData()
+uint8_t g_twi_transfer_buffer[20];
+
+// These buffers match the IS31FL3736 PWM registers.
+// The control buffers match the PG0 LED On/Off registers.
+// Storing them like this is optimal for I2C transfers to the registers.
+// We could optimize this and take out the unused registers from these
+// buffers and the transfers in IS31FL3736_write_pwm_buffer() but it's
+// probably not worth the extra complexity.
+uint8_t g_pwm_buffer[DRIVER_COUNT][192];
+bool g_pwm_buffer_update_required = false;
+
+uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}};
+bool g_led_control_registers_update_required = false;
+
+void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+ g_twi_transfer_buffer[0] = reg;
+ g_twi_transfer_buffer[1] = data;
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
+#endif
+}
+
+void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
+ // assumes PG1 is already selected
+
+ // transmit PWM registers in 12 transfers of 16 bytes
+ // g_twi_transfer_buffer[] is 20 bytes
+
+ // iterate over the pwm_buffer contents at 16 byte intervals
+ for (int i = 0; i < 192; i += 16) {
+ g_twi_transfer_buffer[0] = i;
+ // copy the data from i to i+15
+ // device will auto-increment register for data after the first byte
+ // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
+ for (int j = 0; j < 16; j++) {
+ g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
+ }
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
+ }
+}
+
+void IS31FL3736_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ // Unlock the command register.
+ IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG0
+ IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ // Turn off all LEDs.
+ for (int i = 0x00; i <= 0x17; i++) {
+ IS31FL3736_write_register(addr, i, 0x00);
+ }
+
+ // Unlock the command register.
+ IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG1
+ IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+ // Set PWM on all LEDs to 0
+ // No need to setup Breath registers to PWM as that is the default.
+ for (int i = 0x00; i <= 0xBF; i++) {
+ IS31FL3736_write_register(addr, i, 0x00);
+ }
+
+ // Unlock the command register.
+ IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG3
+ IS31FL3736_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
+ // Set global current to maximum.
+ IS31FL3736_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
+ // Disable software shutdown.
+ IS31FL3736_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ if (index >= 0 && index < DRIVER_LED_TOTAL) {
+ is31_led led = g_is31_leds[index];
+
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ g_pwm_buffer_update_required = true;
+ }
+}
+
+void IS31FL3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+ IS31FL3736_set_color(i, red, green, blue);
+ }
+}
+
+void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
+ is31_led led = g_is31_leds[index];
+
+ // IS31FL3733
+ // The PWM register for a matrix position (0x00 to 0xBF) can be
+ // divided by 8 to get the LED control register (0x00 to 0x17),
+ // then mod 8 to get the bit position within that register.
+
+ // IS31FL3736
+ // The PWM register for a matrix position (0x00 to 0xBF) is interleaved, so:
+ // A1=0x00 A2=0x02 A3=0x04 A4=0x06 A5=0x08 A6=0x0A A7=0x0C A8=0x0E
+ // B1=0x10 B2=0x12 B3=0x14
+ // But also, the LED control registers (0x00 to 0x17) are also interleaved, so:
+ // A1-A4=0x00 A5-A8=0x01
+ // So, the same math applies.
+
+ uint8_t control_register_r = led.r / 8;
+ uint8_t control_register_g = led.g / 8;
+ uint8_t control_register_b = led.b / 8;
+
+ uint8_t bit_r = led.r % 8;
+ uint8_t bit_g = led.g % 8;
+ uint8_t bit_b = led.b % 8;
+
+ if (red) {
+ g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
+ } else {
+ g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
+ }
+ if (green) {
+ g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
+ } else {
+ g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
+ }
+ if (blue) {
+ g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
+ } else {
+ g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
+ }
+
+ g_led_control_registers_update_required = true;
+}
+
+void IS31FL3736_mono_set_brightness(int index, uint8_t value) {
+ if (index >= 0 && index < 96) {
+ // Index in range 0..95 -> A1..A8, B1..B8, etc.
+ // Map index 0..95 to registers 0x00..0xBE (interleaved)
+ uint8_t pwm_register = index * 2;
+ g_pwm_buffer[0][pwm_register] = value;
+ g_pwm_buffer_update_required = true;
+ }
+}
+
+void IS31FL3736_mono_set_brightness_all(uint8_t value) {
+ for (int i = 0; i < 96; i++) {
+ IS31FL3736_mono_set_brightness(i, value);
+ }
+}
+
+void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled) {
+ // Index in range 0..95 -> A1..A8, B1..B8, etc.
+
+ // Map index 0..95 to registers 0x00..0xBE (interleaved)
+ uint8_t pwm_register = index * 2;
+ // Map register 0x00..0xBE (interleaved) into control register and bit
+ uint8_t control_register = pwm_register / 8;
+ uint8_t bit = pwm_register % 8;
+
+ if (enabled) {
+ g_led_control_registers[0][control_register] |= (1 << bit);
+ } else {
+ g_led_control_registers[0][control_register] &= ~(1 << bit);
+ }
+
+ g_led_control_registers_update_required = true;
+}
+
+void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
+ if (g_pwm_buffer_update_required) {
+ // Firstly we need to unlock the command register and select PG1
+ IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+
+ IS31FL3736_write_pwm_buffer(addr1, g_pwm_buffer[0]);
+ // IS31FL3736_write_pwm_buffer(addr2, g_pwm_buffer[1]);
+ }
+ g_pwm_buffer_update_required = false;
+}
+
+void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2) {
+ if (g_led_control_registers_update_required) {
+ // Firstly we need to unlock the command register and select PG0
+ IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ for (int i = 0; i < 24; i++) {
+ IS31FL3736_write_register(addr1, i, g_led_control_registers[0][i]);
+ // IS31FL3736_write_register(addr2, i, g_led_control_registers[1][i]);
+ }
+ g_led_control_registers_update_required = false;
+ }
+}
diff --git a/drivers/led/issi/is31fl3736.h b/drivers/led/issi/is31fl3736.h
new file mode 100644
index 0000000000..e48e31c279
--- /dev/null
+++ b/drivers/led/issi/is31fl3736.h
@@ -0,0 +1,168 @@
+/* Copyright 2018 Jason Williams (Wilba)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+// Simple interface option.
+// If these aren't defined, just define them to make it compile
+
+#ifndef DRIVER_COUNT
+# define DRIVER_COUNT 2
+#endif
+
+#ifndef DRIVER_LED_TOTAL
+# define DRIVER_LED_TOTAL 96
+#endif
+
+typedef struct is31_led {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} __attribute__((packed)) is31_led;
+
+extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+
+void IS31FL3736_init(uint8_t addr);
+void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void IS31FL3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+
+void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void IS31FL3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
+
+void IS31FL3736_mono_set_brightness(int index, uint8_t value);
+void IS31FL3736_mono_set_brightness_all(uint8_t value);
+void IS31FL3736_mono_set_led_control_register(uint8_t index, bool enabled);
+
+// This should not be called from an interrupt
+// (eg. from a timer interrupt).
+// Call this while idle (in between matrix scans).
+// If the buffer is dirty, it will update the driver with the buffer.
+void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2);
+void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2);
+
+#define A_1 0x00
+#define A_2 0x02
+#define A_3 0x04
+#define A_4 0x06
+#define A_5 0x08
+#define A_6 0x0A
+#define A_7 0x0C
+#define A_8 0x0E
+
+#define B_1 0x10
+#define B_2 0x12
+#define B_3 0x14
+#define B_4 0x16
+#define B_5 0x18
+#define B_6 0x1A
+#define B_7 0x1C
+#define B_8 0x1E
+
+#define C_1 0x20
+#define C_2 0x22
+#define C_3 0x24
+#define C_4 0x26
+#define C_5 0x28
+#define C_6 0x2A
+#define C_7 0x2C
+#define C_8 0x2E
+
+#define D_1 0x30
+#define D_2 0x32
+#define D_3 0x34
+#define D_4 0x36
+#define D_5 0x38
+#define D_6 0x3A
+#define D_7 0x3C
+#define D_8 0x3E
+
+#define E_1 0x40
+#define E_2 0x42
+#define E_3 0x44
+#define E_4 0x46
+#define E_5 0x48
+#define E_6 0x4A
+#define E_7 0x4C
+#define E_8 0x4E
+
+#define F_1 0x50
+#define F_2 0x52
+#define F_3 0x54
+#define F_4 0x56
+#define F_5 0x58
+#define F_6 0x5A
+#define F_7 0x5C
+#define F_8 0x5E
+
+#define G_1 0x60
+#define G_2 0x62
+#define G_3 0x64
+#define G_4 0x66
+#define G_5 0x68
+#define G_6 0x6A
+#define G_7 0x6C
+#define G_8 0x6E
+
+#define H_1 0x70
+#define H_2 0x72
+#define H_3 0x74
+#define H_4 0x76
+#define H_5 0x78
+#define H_6 0x7A
+#define H_7 0x7C
+#define H_8 0x7E
+
+#define I_1 0x80
+#define I_2 0x82
+#define I_3 0x84
+#define I_4 0x86
+#define I_5 0x88
+#define I_6 0x8A
+#define I_7 0x8C
+#define I_8 0x8E
+
+#define J_1 0x90
+#define J_2 0x92
+#define J_3 0x94
+#define J_4 0x96
+#define J_5 0x98
+#define J_6 0x9A
+#define J_7 0x9C
+#define J_8 0x9E
+
+#define K_1 0xA0
+#define K_2 0xA2
+#define K_3 0xA4
+#define K_4 0xA6
+#define K_5 0xA8
+#define K_6 0xAA
+#define K_7 0xAC
+#define K_8 0xAE
+
+#define L_1 0xB0
+#define L_2 0xB2
+#define L_3 0xB4
+#define L_4 0xB6
+#define L_5 0xB8
+#define L_6 0xBA
+#define L_7 0xBC
+#define L_8 0xBE
diff --git a/drivers/led/issi/is31fl3737.c b/drivers/led/issi/is31fl3737.c
new file mode 100644
index 0000000000..30906b4840
--- /dev/null
+++ b/drivers/led/issi/is31fl3737.c
@@ -0,0 +1,227 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "is31fl3737.h"
+#include "i2c_master.h"
+#include "wait.h"
+#include "progmem.h"
+
+// This is a 7-bit address, that gets left-shifted and bit 0
+// set to 0 for write, 1 for read (as per I2C protocol)
+// The address will vary depending on your wiring:
+// 00 <-> GND
+// 01 <-> SCL
+// 10 <-> SDA
+// 11 <-> VCC
+// ADDR1 represents A1:A0 of the 7-bit address.
+// ADDR2 represents A3:A2 of the 7-bit address.
+// The result is: 0b101(ADDR2)(ADDR1)
+#define ISSI_ADDR_DEFAULT 0x50
+
+#define ISSI_COMMANDREGISTER 0xFD
+#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
+#define ISSI_INTERRUPTMASKREGISTER 0xF0
+#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
+
+#define ISSI_PAGE_LEDCONTROL 0x00 // PG0
+#define ISSI_PAGE_PWM 0x01 // PG1
+#define ISSI_PAGE_AUTOBREATH 0x02 // PG2
+#define ISSI_PAGE_FUNCTION 0x03 // PG3
+
+#define ISSI_REG_CONFIGURATION 0x00 // PG3
+#define ISSI_REG_GLOBALCURRENT 0x01 // PG3
+#define ISSI_REG_RESET 0x11 // PG3
+#define ISSI_REG_SWPULLUP 0x0F // PG3
+#define ISSI_REG_CSPULLUP 0x10 // PG3
+
+#ifndef ISSI_TIMEOUT
+# define ISSI_TIMEOUT 100
+#endif
+
+#ifndef ISSI_PERSISTENCE
+# define ISSI_PERSISTENCE 0
+#endif
+
+// Transfer buffer for TWITransmitData()
+uint8_t g_twi_transfer_buffer[20];
+
+// These buffers match the IS31FL3737 PWM registers.
+// The control buffers match the PG0 LED On/Off registers.
+// Storing them like this is optimal for I2C transfers to the registers.
+// We could optimize this and take out the unused registers from these
+// buffers and the transfers in IS31FL3737_write_pwm_buffer() but it's
+// probably not worth the extra complexity.
+
+uint8_t g_pwm_buffer[DRIVER_COUNT][192];
+bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
+
+uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
+bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
+
+void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+ g_twi_transfer_buffer[0] = reg;
+ g_twi_transfer_buffer[1] = data;
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
+#endif
+}
+
+void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
+ // assumes PG1 is already selected
+
+ // transmit PWM registers in 12 transfers of 16 bytes
+ // g_twi_transfer_buffer[] is 20 bytes
+
+ // iterate over the pwm_buffer contents at 16 byte intervals
+ for (int i = 0; i < 192; i += 16) {
+ g_twi_transfer_buffer[0] = i;
+ // copy the data from i to i+15
+ // device will auto-increment register for data after the first byte
+ // thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
+ for (int j = 0; j < 16; j++) {
+ g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
+ }
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
+#endif
+ }
+}
+
+void IS31FL3737_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+
+ // Unlock the command register.
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG0
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ // Turn off all LEDs.
+ for (int i = 0x00; i <= 0x17; i++) {
+ IS31FL3737_write_register(addr, i, 0x00);
+ }
+
+ // Unlock the command register.
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG1
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+ // Set PWM on all LEDs to 0
+ // No need to setup Breath registers to PWM as that is the default.
+ for (int i = 0x00; i <= 0xBF; i++) {
+ IS31FL3737_write_register(addr, i, 0x00);
+ }
+
+ // Unlock the command register.
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG3
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
+ // Set global current to maximum.
+ IS31FL3737_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
+ // Disable software shutdown.
+ IS31FL3737_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ if (index >= 0 && index < DRIVER_LED_TOTAL) {
+ // copy the led config from progmem to SRAM
+ is31_led led;
+ memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
+
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ g_pwm_buffer_update_required[led.driver] = true;
+ }
+}
+
+void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+ IS31FL3737_set_color(i, red, green, blue);
+ }
+}
+
+void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
+ // copy the led config from progmem to SRAM
+ is31_led led;
+ memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
+
+ uint8_t control_register_r = led.r / 8;
+ uint8_t control_register_g = led.g / 8;
+ uint8_t control_register_b = led.b / 8;
+ uint8_t bit_r = led.r % 8;
+ uint8_t bit_g = led.g % 8;
+ uint8_t bit_b = led.b % 8;
+
+ if (red) {
+ g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r);
+ } else {
+ g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r);
+ }
+ if (green) {
+ g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g);
+ } else {
+ g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g);
+ }
+ if (blue) {
+ g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b);
+ } else {
+ g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
+ }
+
+ g_led_control_registers_update_required[led.driver] = true;
+}
+
+void IS31FL3737_update_pwm_buffers(uint8_t addr, uint8_t index) {
+ if (g_pwm_buffer_update_required[index]) {
+ // Firstly we need to unlock the command register and select PG1
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
+
+ IS31FL3737_write_pwm_buffer(addr, g_pwm_buffer[index]);
+ }
+ g_pwm_buffer_update_required[index] = false;
+}
+
+void IS31FL3737_update_led_control_registers(uint8_t addr, uint8_t index) {
+ if (g_led_control_registers_update_required[index]) {
+ // Firstly we need to unlock the command register and select PG0
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
+ for (int i = 0; i < 24; i++) {
+ IS31FL3737_write_register(addr, i, g_led_control_registers[index][i]);
+ }
+ }
+ g_led_control_registers_update_required[index] = false;
+}
diff --git a/drivers/led/issi/is31fl3737.h b/drivers/led/issi/is31fl3737.h
new file mode 100644
index 0000000000..a1d2281778
--- /dev/null
+++ b/drivers/led/issi/is31fl3737.h
@@ -0,0 +1,203 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+typedef struct is31_led {
+ uint8_t driver : 2;
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+} __attribute__((packed)) is31_led;
+
+extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+
+void IS31FL3737_init(uint8_t addr);
+void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+void IS31FL3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+
+void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
+
+// This should not be called from an interrupt
+// (eg. from a timer interrupt).
+// Call this while idle (in between matrix scans).
+// If the buffer is dirty, it will update the driver with the buffer.
+void IS31FL3737_update_pwm_buffers(uint8_t addr1, uint8_t addr2);
+void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2);
+
+#define A_1 0x00
+#define A_2 0x01
+#define A_3 0x02
+#define A_4 0x03
+#define A_5 0x04
+#define A_6 0x05
+#define A_7 0x08
+#define A_8 0x09
+#define A_9 0x0A
+#define A_10 0x0B
+#define A_11 0x0C
+#define A_12 0x0D
+
+#define B_1 0x10
+#define B_2 0x11
+#define B_3 0x12
+#define B_4 0x13
+#define B_5 0x14
+#define B_6 0x15
+#define B_7 0x18
+#define B_8 0x19
+#define B_9 0x1A
+#define B_10 0x1B
+#define B_11 0x1C
+#define B_12 0x1D
+
+#define C_1 0x20
+#define C_2 0x21
+#define C_3 0x22
+#define C_4 0x23
+#define C_5 0x24
+#define C_6 0x25
+#define C_7 0x28
+#define C_8 0x29
+#define C_9 0x2A
+#define C_10 0x2B
+#define C_11 0x2C
+#define C_12 0x2D
+
+#define D_1 0x30
+#define D_2 0x31
+#define D_3 0x32
+#define D_4 0x33
+#define D_5 0x34
+#define D_6 0x35
+#define D_7 0x38
+#define D_8 0x39
+#define D_9 0x3A
+#define D_10 0x3B
+#define D_11 0x3C
+#define D_12 0x3D
+
+#define E_1 0x40
+#define E_2 0x41
+#define E_3 0x42
+#define E_4 0x43
+#define E_5 0x44
+#define E_6 0x45
+#define E_7 0x48
+#define E_8 0x49
+#define E_9 0x4A
+#define E_10 0x4B
+#define E_11 0x4C
+#define E_12 0x4D
+
+#define F_1 0x50
+#define F_2 0x51
+#define F_3 0x52
+#define F_4 0x53
+#define F_5 0x54
+#define F_6 0x55
+#define F_7 0x58
+#define F_8 0x59
+#define F_9 0x5A
+#define F_10 0x5B
+#define F_11 0x5C
+#define F_12 0x5D
+
+#define G_1 0x60
+#define G_2 0x61
+#define G_3 0x62
+#define G_4 0x63
+#define G_5 0x64
+#define G_6 0x65
+#define G_7 0x68
+#define G_8 0x69
+#define G_9 0x6A
+#define G_10 0x6B
+#define G_11 0x6C
+#define G_12 0x6D
+
+#define H_1 0x70
+#define H_2 0x71
+#define H_3 0x72
+#define H_4 0x73
+#define H_5 0x74
+#define H_6 0x75
+#define H_7 0x78
+#define H_8 0x79
+#define H_9 0x7A
+#define H_10 0x7B
+#define H_11 0x7C
+#define H_12 0x7D
+
+#define I_1 0x80
+#define I_2 0x81
+#define I_3 0x82
+#define I_4 0x83
+#define I_5 0x84
+#define I_6 0x85
+#define I_7 0x88
+#define I_8 0x89
+#define I_9 0x8A
+#define I_10 0x8B
+#define I_11 0x8C
+#define I_12 0x8D
+
+#define J_1 0x90
+#define J_2 0x91
+#define J_3 0x92
+#define J_4 0x93
+#define J_5 0x94
+#define J_6 0x95
+#define J_7 0x98
+#define J_8 0x99
+#define J_9 0x9A
+#define J_10 0x9B
+#define J_11 0x9C
+#define J_12 0x9D
+
+#define K_1 0xA0
+#define K_2 0xA1
+#define K_3 0xA2
+#define K_4 0xA3
+#define K_5 0xA4
+#define K_6 0xA5
+#define K_7 0xA8
+#define K_8 0xA9
+#define K_9 0xAA
+#define K_10 0xAB
+#define K_11 0xAC
+#define K_12 0xAD
+
+#define L_1 0xB0
+#define L_2 0xB1
+#define L_3 0xB2
+#define L_4 0xB3
+#define L_5 0xB4
+#define L_6 0xB5
+#define L_7 0xB8
+#define L_8 0xB9
+#define L_9 0xBA
+#define L_10 0xBB
+#define L_11 0xBC
+#define L_12 0xBD
diff --git a/drivers/led/issi/is31fl3741.c b/drivers/led/issi/is31fl3741.c
new file mode 100644
index 0000000000..1b533c9b6a
--- /dev/null
+++ b/drivers/led/issi/is31fl3741.c
@@ -0,0 +1,255 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "wait.h"
+
+#include "is31fl3741.h"
+#include
+#include "i2c_master.h"
+#include "progmem.h"
+
+// This is a 7-bit address, that gets left-shifted and bit 0
+// set to 0 for write, 1 for read (as per I2C protocol)
+// The address will vary depending on your wiring:
+// 00 <-> GND
+// 01 <-> SCL
+// 10 <-> SDA
+// 11 <-> VCC
+// ADDR1 represents A1:A0 of the 7-bit address.
+// ADDR2 represents A3:A2 of the 7-bit address.
+// The result is: 0b101(ADDR2)(ADDR1)
+#define ISSI_ADDR_DEFAULT 0x60
+
+#define ISSI_COMMANDREGISTER 0xFD
+#define ISSI_COMMANDREGISTER_WRITELOCK 0xFE
+#define ISSI_INTERRUPTMASKREGISTER 0xF0
+#define ISSI_INTERRUPTSTATUSREGISTER 0xF1
+#define ISSI_IDREGISTER 0xFC
+
+#define ISSI_PAGE_PWM0 0x00 // PG0
+#define ISSI_PAGE_PWM1 0x01 // PG1
+#define ISSI_PAGE_SCALING_0 0x02 // PG2
+#define ISSI_PAGE_SCALING_1 0x03 // PG3
+#define ISSI_PAGE_FUNCTION 0x04 // PG4
+
+#define ISSI_REG_CONFIGURATION 0x00 // PG4
+#define ISSI_REG_GLOBALCURRENT 0x01 // PG4
+#define ISSI_REG_PULLDOWNUP 0x02 // PG4
+#define ISSI_REG_RESET 0x3F // PG4
+
+#ifndef ISSI_TIMEOUT
+# define ISSI_TIMEOUT 100
+#endif
+
+#ifndef ISSI_PERSISTENCE
+# define ISSI_PERSISTENCE 0
+#endif
+
+#define ISSI_MAX_LEDS 351
+
+// Transfer buffer for TWITransmitData()
+uint8_t g_twi_transfer_buffer[20] = {0xFF};
+
+// These buffers match the IS31FL3741 and IS31FL3741A PWM registers.
+// The scaling buffers match the PG2 and PG3 LED On/Off registers.
+// Storing them like this is optimal for I2C transfers to the registers.
+// We could optimize this and take out the unused registers from these
+// buffers and the transfers in IS31FL3741_write_pwm_buffer() but it's
+// probably not worth the extra complexity.
+uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS];
+bool g_pwm_buffer_update_required = false;
+bool g_scaling_registers_update_required[DRIVER_COUNT] = {false};
+
+uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_LEDS];
+
+void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
+ g_twi_transfer_buffer[0] = reg;
+ g_twi_transfer_buffer[1] = data;
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
+ }
+#else
+ i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
+#endif
+}
+
+bool IS31FL3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
+ // unlock the command register and select PG2
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM0);
+
+ for (int i = 0; i < 342; i += 18) {
+ if (i == 180) {
+ // unlock the command register and select PG2
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM1);
+ }
+
+ g_twi_transfer_buffer[0] = i % 180;
+ memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 18);
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, ISSI_TIMEOUT) != 0) {
+ return false;
+ }
+ }
+#else
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, ISSI_TIMEOUT) != 0) {
+ return false;
+ }
+#endif
+ }
+
+ // transfer the left cause the total number is 351
+ g_twi_transfer_buffer[0] = 162;
+ memcpy(g_twi_transfer_buffer + 1, pwm_buffer + 342, 9);
+
+#if ISSI_PERSISTENCE > 0
+ for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, ISSI_TIMEOUT) != 0) {
+ return false;
+ }
+ }
+#else
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, ISSI_TIMEOUT) != 0) {
+ return false;
+ }
+#endif
+
+ return true;
+}
+
+void IS31FL3741_init(uint8_t addr) {
+ // In order to avoid the LEDs being driven with garbage data
+ // in the LED driver's PWM registers, shutdown is enabled last.
+ // Set up the mode and other settings, clear the PWM registers,
+ // then disable software shutdown.
+ // Unlock the command register.
+
+ // Unlock the command register.
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+
+ // Select PG4
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_FUNCTION);
+
+ // Set to Normal operation
+ IS31FL3741_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
+
+ // Set Golbal Current Control Register
+ IS31FL3741_write_register(addr, ISSI_REG_GLOBALCURRENT, 0xFF);
+ // Set Pull up & Down for SWx CSy
+ IS31FL3741_write_register(addr, ISSI_REG_PULLDOWNUP, 0x77);
+
+ // IS31FL3741_update_led_scaling_registers(addr, 0xFF, 0xFF, 0xFF);
+
+ // Wait 10ms to ensure the device has woken up.
+ wait_ms(10);
+}
+
+void IS31FL3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
+ if (index >= 0 && index < DRIVER_LED_TOTAL) {
+ is31_led led = g_is31_leds[index];
+
+ g_pwm_buffer[led.driver][led.r] = red;
+ g_pwm_buffer[led.driver][led.g] = green;
+ g_pwm_buffer[led.driver][led.b] = blue;
+ g_pwm_buffer_update_required = true;
+ }
+}
+
+void IS31FL3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
+ for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+ IS31FL3741_set_color(i, red, green, blue);
+ }
+}
+
+void IS31FL3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
+ is31_led led = g_is31_leds[index];
+
+ if (red) {
+ g_scaling_registers[led.driver][led.r] = 0xFF;
+ } else {
+ g_scaling_registers[led.driver][led.r] = 0x00;
+ }
+
+ if (green) {
+ g_scaling_registers[led.driver][led.g] = 0xFF;
+ } else {
+ g_scaling_registers[led.driver][led.g] = 0x00;
+ }
+
+ if (blue) {
+ g_scaling_registers[led.driver][led.b] = 0xFF;
+ } else {
+ g_scaling_registers[led.driver][led.b] = 0x00;
+ }
+
+ g_scaling_registers_update_required[led.driver] = true;
+}
+
+void IS31FL3741_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
+ if (g_pwm_buffer_update_required) {
+ IS31FL3741_write_pwm_buffer(addr1, g_pwm_buffer[0]);
+ }
+
+ g_pwm_buffer_update_required = false;
+}
+
+void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) {
+ g_pwm_buffer[pled->driver][pled->r] = red;
+ g_pwm_buffer[pled->driver][pled->g] = green;
+ g_pwm_buffer[pled->driver][pled->b] = blue;
+
+ g_pwm_buffer_update_required = true;
+}
+
+void IS31FL3741_update_led_control_registers(uint8_t addr, uint8_t index) {
+ if (g_scaling_registers_update_required[index]) {
+ // unlock the command register and select PG2
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_0);
+
+ // CS1_SW1 to CS30_SW6 are on PG2
+ for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
+ IS31FL3741_write_register(addr, i, g_scaling_registers[0][i]);
+ }
+
+ // unlock the command register and select PG3
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
+ IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_1);
+
+ // CS1_SW7 to CS39_SW9 are on PG3
+ for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
+ IS31FL3741_write_register(addr, i - CS1_SW7, g_scaling_registers[0][i]);
+ }
+
+ g_scaling_registers_update_required[index] = false;
+ }
+}
+
+void IS31FL3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) {
+ g_scaling_registers[pled->driver][pled->r] = red;
+ g_scaling_registers[pled->driver][pled->g] = green;
+ g_scaling_registers[pled->driver][pled->b] = blue;
+
+ g_scaling_registers_update_required[pled->driver] = true;
+}
diff --git a/drivers/led/issi/is31fl3741.h b/drivers/led/issi/is31fl3741.h
new file mode 100644
index 0000000000..2df0c5b1a7
--- /dev/null
+++ b/drivers/led/issi/is31fl3741.h
@@ -0,0 +1,420 @@
+/* Copyright 2017 Jason Williams
+ * Copyright 2018 Jack Humbert
+ * Copyright 2018 Yiancar
+ * Copyright 2020 MelGeek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+typedef struct is31_led {
+ uint32_t driver : 2;
+ uint32_t r : 10;
+ uint32_t g : 10;
+ uint32_t b : 10;
+} __attribute__((packed)) is31_led;
+
+extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+
+void IS31FL3741_init(uint8_t addr);
+void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
+bool IS31FL3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
+
+void IS31FL3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
+void IS31FL3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+
+void IS31FL3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
+
+// This should not be called from an interrupt
+// (eg. from a timer interrupt).
+// Call this while idle (in between matrix scans).
+// If the buffer is dirty, it will update the driver with the buffer.
+void IS31FL3741_update_pwm_buffers(uint8_t addr1, uint8_t addr2);
+void IS31FL3741_update_led_control_registers(uint8_t addr1, uint8_t addr2);
+void IS31FL3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue);
+
+void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue);
+
+#define CS1_SW1 0x00
+#define CS2_SW1 0x01
+#define CS3_SW1 0x02
+#define CS4_SW1 0x03
+#define CS5_SW1 0x04
+#define CS6_SW1 0x05
+#define CS7_SW1 0x06
+#define CS8_SW1 0x07
+#define CS9_SW1 0x08
+#define CS10_SW1 0x09
+#define CS11_SW1 0x0A
+#define CS12_SW1 0x0B
+#define CS13_SW1 0x0C
+#define CS14_SW1 0x0D
+#define CS15_SW1 0x0E
+#define CS16_SW1 0x0F
+#define CS17_SW1 0x10
+#define CS18_SW1 0x11
+#define CS19_SW1 0x12
+#define CS20_SW1 0x13
+#define CS21_SW1 0x14
+#define CS22_SW1 0x15
+#define CS23_SW1 0x16
+#define CS24_SW1 0x17
+#define CS25_SW1 0x18
+#define CS26_SW1 0x19
+#define CS27_SW1 0x1A
+#define CS28_SW1 0x1B
+#define CS29_SW1 0x1C
+#define CS30_SW1 0x1D
+
+#define CS1_SW2 0x1E
+#define CS2_SW2 0x1F
+#define CS3_SW2 0x20
+#define CS4_SW2 0x21
+#define CS5_SW2 0x22
+#define CS6_SW2 0x23
+#define CS7_SW2 0x24
+#define CS8_SW2 0x25
+#define CS9_SW2 0x26
+#define CS10_SW2 0x27
+#define CS11_SW2 0x28
+#define CS12_SW2 0x29
+#define CS13_SW2 0x2A
+#define CS14_SW2 0x2B
+#define CS15_SW2 0x2C
+#define CS16_SW2 0x2D
+#define CS17_SW2 0x2E
+#define CS18_SW2 0x2F
+#define CS19_SW2 0x30
+#define CS20_SW2 0x31
+#define CS21_SW2 0x32
+#define CS22_SW2 0x33
+#define CS23_SW2 0x34
+#define CS24_SW2 0x35
+#define CS25_SW2 0x36
+#define CS26_SW2 0x37
+#define CS27_SW2 0x38
+#define CS28_SW2 0x39
+#define CS29_SW2 0x3A
+#define CS30_SW2 0x3B
+
+#define CS1_SW3 0x3C
+#define CS2_SW3 0x3D
+#define CS3_SW3 0x3E
+#define CS4_SW3 0x3F
+#define CS5_SW3 0x40
+#define CS6_SW3 0x41
+#define CS7_SW3 0x42
+#define CS8_SW3 0x43
+#define CS9_SW3 0x44
+#define CS10_SW3 0x45
+#define CS11_SW3 0x46
+#define CS12_SW3 0x47
+#define CS13_SW3 0x48
+#define CS14_SW3 0x49
+#define CS15_SW3 0x4A
+#define CS16_SW3 0x4B
+#define CS17_SW3 0x4C
+#define CS18_SW3 0x4D
+#define CS19_SW3 0x4E
+#define CS20_SW3 0x4F
+#define CS21_SW3 0x50
+#define CS22_SW3 0x51
+#define CS23_SW3 0x52
+#define CS24_SW3 0x53
+#define CS25_SW3 0x54
+#define CS26_SW3 0x55
+#define CS27_SW3 0x56
+#define CS28_SW3 0x57
+#define CS29_SW3 0x58
+#define CS30_SW3 0x59
+
+#define CS1_SW4 0x5A
+#define CS2_SW4 0x5B
+#define CS3_SW4 0x5C
+#define CS4_SW4 0x5D
+#define CS5_SW4 0x5E
+#define CS6_SW4 0x5F
+#define CS7_SW4 0x60
+#define CS8_SW4 0x61
+#define CS9_SW4 0x62
+#define CS10_SW4 0x63
+#define CS11_SW4 0x64
+#define CS12_SW4 0x65
+#define CS13_SW4 0x66
+#define CS14_SW4 0x67
+#define CS15_SW4 0x68
+#define CS16_SW4 0x69
+#define CS17_SW4 0x6A
+#define CS18_SW4 0x6B
+#define CS19_SW4 0x6C
+#define CS20_SW4 0x6D
+#define CS21_SW4 0x6E
+#define CS22_SW4 0x6F
+#define CS23_SW4 0x70
+#define CS24_SW4 0x71
+#define CS25_SW4 0x72
+#define CS26_SW4 0x73
+#define CS27_SW4 0x74
+#define CS28_SW4 0x75
+#define CS29_SW4 0x76
+#define CS30_SW4 0x77
+
+#define CS1_SW5 0x78
+#define CS2_SW5 0x79
+#define CS3_SW5 0x7A
+#define CS4_SW5 0x7B
+#define CS5_SW5 0x7C
+#define CS6_SW5 0x7D
+#define CS7_SW5 0x7E
+#define CS8_SW5 0x7F
+#define CS9_SW5 0x80
+#define CS10_SW5 0x81
+#define CS11_SW5 0x82
+#define CS12_SW5 0x83
+#define CS13_SW5 0x84
+#define CS14_SW5 0x85
+#define CS15_SW5 0x86
+#define CS16_SW5 0x87
+#define CS17_SW5 0x88
+#define CS18_SW5 0x89
+#define CS19_SW5 0x8A
+#define CS20_SW5 0x8B
+#define CS21_SW5 0x8C
+#define CS22_SW5 0x8D
+#define CS23_SW5 0x8E
+#define CS24_SW5 0x8F
+#define CS25_SW5 0x90
+#define CS26_SW5 0x91
+#define CS27_SW5 0x92
+#define CS28_SW5 0x93
+#define CS29_SW5 0x94
+#define CS30_SW5 0x95
+
+#define CS1_SW6 0x96
+#define CS2_SW6 0x97
+#define CS3_SW6 0x98
+#define CS4_SW6 0x99
+#define CS5_SW6 0x9A
+#define CS6_SW6 0x9B
+#define CS7_SW6 0x9C
+#define CS8_SW6 0x9D
+#define CS9_SW6 0x9E
+#define CS10_SW6 0x9F
+#define CS11_SW6 0xA0
+#define CS12_SW6 0xA1
+#define CS13_SW6 0xA2
+#define CS14_SW6 0xA3
+#define CS15_SW6 0xA4
+#define CS16_SW6 0xA5
+#define CS17_SW6 0xA6
+#define CS18_SW6 0xA7
+#define CS19_SW6 0xA8
+#define CS20_SW6 0xA9
+#define CS21_SW6 0xAA
+#define CS22_SW6 0xAB
+#define CS23_SW6 0xAC
+#define CS24_SW6 0xAD
+#define CS25_SW6 0xAE
+#define CS26_SW6 0xAF
+#define CS27_SW6 0xB0
+#define CS28_SW6 0xB1
+#define CS29_SW6 0xB2
+#define CS30_SW6 0xB3
+
+#define CS1_SW7 0xB4
+#define CS2_SW7 0xB5
+#define CS3_SW7 0xB6
+#define CS4_SW7 0xB7
+#define CS5_SW7 0xB8
+#define CS6_SW7 0xB9
+#define CS7_SW7 0xBA
+#define CS8_SW7 0xBB
+#define CS9_SW7 0xBC
+#define CS10_SW7 0xBD
+#define CS11_SW7 0xBE
+#define CS12_SW7 0xBF
+#define CS13_SW7 0xC0
+#define CS14_SW7 0xC1
+#define CS15_SW7 0xC2
+#define CS16_SW7 0xC3
+#define CS17_SW7 0xC4
+#define CS18_SW7 0xC5
+#define CS19_SW7 0xC6
+#define CS20_SW7 0xC7
+#define CS21_SW7 0xC8
+#define CS22_SW7 0xC9
+#define CS23_SW7 0xCA
+#define CS24_SW7 0xCB
+#define CS25_SW7 0xCC
+#define CS26_SW7 0xCD
+#define CS27_SW7 0xCE
+#define CS28_SW7 0xCF
+#define CS29_SW7 0xD0
+#define CS30_SW7 0xD1
+
+#define CS1_SW8 0xD2
+#define CS2_SW8 0xD3
+#define CS3_SW8 0xD4
+#define CS4_SW8 0xD5
+#define CS5_SW8 0xD6
+#define CS6_SW8 0xD7
+#define CS7_SW8 0xD8
+#define CS8_SW8 0xD9
+#define CS9_SW8 0xDA
+#define CS10_SW8 0xDB
+#define CS11_SW8 0xDC
+#define CS12_SW8 0xDD
+#define CS13_SW8 0xDE
+#define CS14_SW8 0xDF
+#define CS15_SW8 0xE0
+#define CS16_SW8 0xE1
+#define CS17_SW8 0xE2
+#define CS18_SW8 0xE3
+#define CS19_SW8 0xE4
+#define CS20_SW8 0xE5
+#define CS21_SW8 0xE6
+#define CS22_SW8 0xE7
+#define CS23_SW8 0xE8
+#define CS24_SW8 0xE9
+#define CS25_SW8 0xEA
+#define CS26_SW8 0xEB
+#define CS27_SW8 0xEC
+#define CS28_SW8 0xED
+#define CS29_SW8 0xEE
+#define CS30_SW8 0xEF
+
+#define CS1_SW9 0xF0
+#define CS2_SW9 0xF1
+#define CS3_SW9 0xF2
+#define CS4_SW9 0xF3
+#define CS5_SW9 0xF4
+#define CS6_SW9 0xF5
+#define CS7_SW9 0xF6
+#define CS8_SW9 0xF7
+#define CS9_SW9 0xF8
+#define CS10_SW9 0xF9
+#define CS11_SW9 0xFA
+#define CS12_SW9 0xFB
+#define CS13_SW9 0xFC
+#define CS14_SW9 0xFD
+#define CS15_SW9 0xFE
+#define CS16_SW9 0xFF
+#define CS17_SW9 0x100
+#define CS18_SW9 0x101
+#define CS19_SW9 0x102
+#define CS20_SW9 0x103
+#define CS21_SW9 0x104
+#define CS22_SW9 0x105
+#define CS23_SW9 0x106
+#define CS24_SW9 0x107
+#define CS25_SW9 0x108
+#define CS26_SW9 0x109
+#define CS27_SW9 0x10A
+#define CS28_SW9 0x10B
+#define CS29_SW9 0x10C
+#define CS30_SW9 0x10D
+
+#define CS31_SW1 0x10E
+#define CS32_SW1 0x10F
+#define CS33_SW1 0x110
+#define CS34_SW1 0x111
+#define CS35_SW1 0x112
+#define CS36_SW1 0x113
+#define CS37_SW1 0x114
+#define CS38_SW1 0x115
+#define CS39_SW1 0x116
+
+#define CS31_SW2 0x117
+#define CS32_SW2 0x118
+#define CS33_SW2 0x119
+#define CS34_SW2 0x11A
+#define CS35_SW2 0x11B
+#define CS36_SW2 0x11C
+#define CS37_SW2 0x11D
+#define CS38_SW2 0x11E
+#define CS39_SW2 0x11F
+
+#define CS31_SW3 0x120
+#define CS32_SW3 0x121
+#define CS33_SW3 0x122
+#define CS34_SW3 0x123
+#define CS35_SW3 0x124
+#define CS36_SW3 0x125
+#define CS37_SW3 0x126
+#define CS38_SW3 0x127
+#define CS39_SW3 0x128
+
+#define CS31_SW4 0x129
+#define CS32_SW4 0x12A
+#define CS33_SW4 0x12B
+#define CS34_SW4 0x12C
+#define CS35_SW4 0x12D
+#define CS36_SW4 0x12E
+#define CS37_SW4 0x12F
+#define CS38_SW4 0x130
+#define CS39_SW4 0x131
+
+#define CS31_SW5 0x132
+#define CS32_SW5 0x133
+#define CS33_SW5 0x134
+#define CS34_SW5 0x135
+#define CS35_SW5 0x136
+#define CS36_SW5 0x137
+#define CS37_SW5 0x138
+#define CS38_SW5 0x139
+#define CS39_SW5 0x13A
+
+#define CS31_SW6 0x13B
+#define CS32_SW6 0x13C
+#define CS33_SW6 0x13D
+#define CS34_SW6 0x13E
+#define CS35_SW6 0x13F
+#define CS36_SW6 0x140
+#define CS37_SW6 0x141
+#define CS38_SW6 0x142
+#define CS39_SW6 0x143
+
+#define CS31_SW7 0x144
+#define CS32_SW7 0x145
+#define CS33_SW7 0x146
+#define CS34_SW7 0x147
+#define CS35_SW7 0x148
+#define CS36_SW7 0x149
+#define CS37_SW7 0x14A
+#define CS38_SW7 0x14B
+#define CS39_SW7 0x14C
+
+#define CS31_SW8 0x14D
+#define CS32_SW8 0x14E
+#define CS33_SW8 0x14F
+#define CS34_SW8 0x150
+#define CS35_SW8 0x151
+#define CS36_SW8 0x152
+#define CS37_SW8 0x153
+#define CS38_SW8 0x154
+#define CS39_SW8 0x155
+
+#define CS31_SW9 0x156
+#define CS32_SW9 0x157
+#define CS33_SW9 0x158
+#define CS34_SW9 0x159
+#define CS35_SW9 0x15A
+#define CS36_SW9 0x15B
+#define CS37_SW9 0x15C
+#define CS38_SW9 0x15D
+#define CS39_SW9 0x15E
diff --git a/keyboards/fallacy/indicators.c b/keyboards/fallacy/indicators.c
index 6c80f31678..08c500064d 100755
--- a/keyboards/fallacy/indicators.c
+++ b/keyboards/fallacy/indicators.c
@@ -15,7 +15,7 @@
*/
#include "indicators.h"
-#include "drivers/issi/is31fl3731-simple.h"
+#include "drivers/led/issi/is31fl3731-simple.h"
#include "i2c_master.h"
/* Set up IS31FL3731 for use in powering indicator LEDs. Absolutely overkill for this job but it was already in the design.
diff --git a/keyboards/fallacy/rules.mk b/keyboards/fallacy/rules.mk
index dfc96a31b8..93e02c1695 100755
--- a/keyboards/fallacy/rules.mk
+++ b/keyboards/fallacy/rules.mk
@@ -24,7 +24,7 @@ AUDIO_ENABLE = no # Audio output
# project specific files
SRC += indicators.c \
- drivers/issi/is31fl3731-simple.c
+ drivers/led/issi/is31fl3731-simple.c
QUANTUM_LIB_SRC += i2c_master.c
LAYOUTS = alice alice_split_bs
diff --git a/keyboards/hs60/v2/ansi/rules.mk b/keyboards/hs60/v2/ansi/rules.mk
index 1a0c1abbd8..c8030e7040 100644
--- a/keyboards/hs60/v2/ansi/rules.mk
+++ b/keyboards/hs60/v2/ansi/rules.mk
@@ -31,6 +31,6 @@ LAYOUTS = 60_ansi
# project specific files
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
- drivers/issi/is31fl3733.c \
+ drivers/led/issi/is31fl3733.c \
quantum/color.c \
drivers/chibios/i2c_master.c
diff --git a/keyboards/hs60/v2/hhkb/rules.mk b/keyboards/hs60/v2/hhkb/rules.mk
index 87d86ccd4c..62c067cb2e 100644
--- a/keyboards/hs60/v2/hhkb/rules.mk
+++ b/keyboards/hs60/v2/hhkb/rules.mk
@@ -29,6 +29,6 @@ CIE1931_CURVE = yes
# project specific files
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
- drivers/issi/is31fl3733.c \
+ drivers/led/issi/is31fl3733.c \
quantum/color.c \
drivers/chibios/i2c_master.c
diff --git a/keyboards/hs60/v2/iso/rules.mk b/keyboards/hs60/v2/iso/rules.mk
index 53b801289d..34cfa9e559 100644
--- a/keyboards/hs60/v2/iso/rules.mk
+++ b/keyboards/hs60/v2/iso/rules.mk
@@ -31,6 +31,6 @@ LAYOUTS = 60_iso
# project specific files
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
- drivers/issi/is31fl3733.c \
+ drivers/led/issi/is31fl3733.c \
quantum/color.c \
drivers/chibios/i2c_master.c
diff --git a/keyboards/keebwerk/mega/ansi/ansi.c b/keyboards/keebwerk/mega/ansi/ansi.c
index b5eb0bbad2..532cdec9aa 100755
--- a/keyboards/keebwerk/mega/ansi/ansi.c
+++ b/keyboards/keebwerk/mega/ansi/ansi.c
@@ -18,7 +18,7 @@
#endif
#include "ansi.h"
-#include "drivers/issi/is31fl3733.h"
+#include "drivers/led/issi/is31fl3733.h"
uint8_t R = 0;
uint8_t G = 0;
diff --git a/keyboards/keebwerk/mega/ansi/rules.mk b/keyboards/keebwerk/mega/ansi/rules.mk
index 6a1a9cbfad..aaf31579f0 100755
--- a/keyboards/keebwerk/mega/ansi/rules.mk
+++ b/keyboards/keebwerk/mega/ansi/rules.mk
@@ -34,6 +34,6 @@ LAYOUTS = 65_ansi
# project specific files
SRC += keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
- drivers/issi/is31fl3733.c \
+ drivers/led/issi/is31fl3733.c \
quantum/color.c
QUANTUM_LIB_SRC += drivers/chibios/i2c_master.c
diff --git a/keyboards/nebula12/rules.mk b/keyboards/nebula12/rules.mk
index 3a423fb78e..ce18e6b2e3 100755
--- a/keyboards/nebula12/rules.mk
+++ b/keyboards/nebula12/rules.mk
@@ -31,6 +31,6 @@ CIE1931_CURVE = yes
# project specific files
SRC += keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
quantum/color.c
QUANTUM_LIB_SRC += drivers/chibios/i2c_master.c
diff --git a/keyboards/nebula68/rules.mk b/keyboards/nebula68/rules.mk
index bcf1fd1a8f..14782d6547 100755
--- a/keyboards/nebula68/rules.mk
+++ b/keyboards/nebula68/rules.mk
@@ -33,6 +33,6 @@ LAYOUTS = 68_ansi
# project specific files
SRC += keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
- drivers/issi/is31fl3733.c \
+ drivers/led/issi/is31fl3733.c \
quantum/color.c
QUANTUM_LIB_SRC += drivers/chibios/i2c_master.c
diff --git a/keyboards/nk65/nk65.c b/keyboards/nk65/nk65.c
index fae30ac75c..4ed18c114e 100755
--- a/keyboards/nk65/nk65.c
+++ b/keyboards/nk65/nk65.c
@@ -18,7 +18,7 @@
#endif
#include "nk65.h"
-#include "drivers/issi/is31fl3733.h"
+#include "drivers/led/issi/is31fl3733.h"
/* Indicator LEDS are part of the LED driver
* Top LED is blue only. LED driver 2 RGB 7 Green channel
diff --git a/keyboards/nk65/rules.mk b/keyboards/nk65/rules.mk
index e3f02ee09b..bdb8a74903 100755
--- a/keyboards/nk65/rules.mk
+++ b/keyboards/nk65/rules.mk
@@ -31,6 +31,6 @@ LAYOUTS = 65_ansi
# project specific files
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
- drivers/issi/is31fl3733.c \
+ drivers/led/issi/is31fl3733.c \
quantum/color.c \
drivers/chibios/i2c_master.c
diff --git a/keyboards/nk87/nk87.c b/keyboards/nk87/nk87.c
index bcebbc651c..c90ba02ea4 100755
--- a/keyboards/nk87/nk87.c
+++ b/keyboards/nk87/nk87.c
@@ -18,7 +18,7 @@
#endif
#include "nk87.h"
-#include "drivers/issi/is31fl3733.h"
+#include "drivers/led/issi/is31fl3733.h"
/* Indicator LEDS are part of the LED driver
* Top LED is blue only. LED driver 2 RGB 63 Blue channel
diff --git a/keyboards/nk87/rules.mk b/keyboards/nk87/rules.mk
index 71f8f3dd80..d7ca223b30 100755
--- a/keyboards/nk87/rules.mk
+++ b/keyboards/nk87/rules.mk
@@ -32,6 +32,6 @@ CIE1931_CURVE = yes
# project specific files
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
- drivers/issi/is31fl3733.c \
+ drivers/led/issi/is31fl3733.c \
quantum/color.c \
drivers/chibios/i2c_master.c
diff --git a/keyboards/tkc/portico/rules.mk b/keyboards/tkc/portico/rules.mk
index 84a65370e3..174938417c 100644
--- a/keyboards/tkc/portico/rules.mk
+++ b/keyboards/tkc/portico/rules.mk
@@ -28,7 +28,7 @@ CIE1931_CURVE = yes
SRC += keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c
+ drivers/led/issi/is31fl3731.c
QUANTUM_LIB_SRC += i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_kara/rules.mk b/keyboards/wilba_tech/rama_works_kara/rules.mk
index 8af9101d35..69efcc01e7 100644
--- a/keyboards/wilba_tech/rama_works_kara/rules.mk
+++ b/keyboards/wilba_tech/rama_works_kara/rules.mk
@@ -34,5 +34,5 @@ LAYOUTS = 60_hhkb
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_koyu/rules.mk b/keyboards/wilba_tech/rama_works_koyu/rules.mk
index 809ab26d0e..be95279206 100644
--- a/keyboards/wilba_tech/rama_works_koyu/rules.mk
+++ b/keyboards/wilba_tech/rama_works_koyu/rules.mk
@@ -42,5 +42,5 @@ CIE1931_CURVE = yes
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_m10_c/rules.mk b/keyboards/wilba_tech/rama_works_m10_c/rules.mk
index 9f4cc186ed..ab9fdaeb61 100644
--- a/keyboards/wilba_tech/rama_works_m10_c/rules.mk
+++ b/keyboards/wilba_tech/rama_works_m10_c/rules.mk
@@ -31,5 +31,5 @@ OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_m50_a/rules.mk b/keyboards/wilba_tech/rama_works_m50_a/rules.mk
index 9f4cc186ed..ab9fdaeb61 100644
--- a/keyboards/wilba_tech/rama_works_m50_a/rules.mk
+++ b/keyboards/wilba_tech/rama_works_m50_a/rules.mk
@@ -31,5 +31,5 @@ OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_m60_a/rules.mk b/keyboards/wilba_tech/rama_works_m60_a/rules.mk
index 7e76a962a2..f44c5856ae 100644
--- a/keyboards/wilba_tech/rama_works_m60_a/rules.mk
+++ b/keyboards/wilba_tech/rama_works_m60_a/rules.mk
@@ -44,5 +44,5 @@ LAYOUTS = 60_hhkb
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_m65_b/rules.mk b/keyboards/wilba_tech/rama_works_m65_b/rules.mk
index 9f4cc186ed..ab9fdaeb61 100644
--- a/keyboards/wilba_tech/rama_works_m65_b/rules.mk
+++ b/keyboards/wilba_tech/rama_works_m65_b/rules.mk
@@ -31,5 +31,5 @@ OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_m65_bx/rules.mk b/keyboards/wilba_tech/rama_works_m65_bx/rules.mk
index 9f4cc186ed..ab9fdaeb61 100644
--- a/keyboards/wilba_tech/rama_works_m65_bx/rules.mk
+++ b/keyboards/wilba_tech/rama_works_m65_bx/rules.mk
@@ -31,5 +31,5 @@ OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_m6_b/rules.mk b/keyboards/wilba_tech/rama_works_m6_b/rules.mk
index 51d1a0c805..139a968c24 100644
--- a/keyboards/wilba_tech/rama_works_m6_b/rules.mk
+++ b/keyboards/wilba_tech/rama_works_m6_b/rules.mk
@@ -41,5 +41,5 @@ CIE1931_CURVE = yes
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3218.c \
+ drivers/led/issi/is31fl3218.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/rama_works_u80_a/rules.mk b/keyboards/wilba_tech/rama_works_u80_a/rules.mk
index 735d2a24ae..654465e683 100644
--- a/keyboards/wilba_tech/rama_works_u80_a/rules.mk
+++ b/keyboards/wilba_tech/rama_works_u80_a/rules.mk
@@ -34,5 +34,5 @@ CIE1931_CURVE = yes
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/wt60_a/rules.mk b/keyboards/wilba_tech/wt60_a/rules.mk
index a0f923a2f3..e892986112 100644
--- a/keyboards/wilba_tech/wt60_a/rules.mk
+++ b/keyboards/wilba_tech/wt60_a/rules.mk
@@ -30,7 +30,7 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
# project specific files
-SRC = drivers/issi/is31fl3736.c \
+SRC = drivers/led/issi/is31fl3736.c \
drivers/avr/i2c_master.c \
quantum/color.c \
keyboards/wilba_tech/wt_mono_backlight.c \
diff --git a/keyboards/wilba_tech/wt60_b/rules.mk b/keyboards/wilba_tech/wt60_b/rules.mk
index 50faab968c..e3cbad41ca 100644
--- a/keyboards/wilba_tech/wt60_b/rules.mk
+++ b/keyboards/wilba_tech/wt60_b/rules.mk
@@ -42,5 +42,5 @@ CIE1931_CURVE = yes
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/wt60_bx/rules.mk b/keyboards/wilba_tech/wt60_bx/rules.mk
index 50faab968c..e3cbad41ca 100644
--- a/keyboards/wilba_tech/wt60_bx/rules.mk
+++ b/keyboards/wilba_tech/wt60_bx/rules.mk
@@ -42,5 +42,5 @@ CIE1931_CURVE = yes
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/wt60_c/rules.mk b/keyboards/wilba_tech/wt60_c/rules.mk
index 50faab968c..e3cbad41ca 100644
--- a/keyboards/wilba_tech/wt60_c/rules.mk
+++ b/keyboards/wilba_tech/wt60_c/rules.mk
@@ -42,5 +42,5 @@ CIE1931_CURVE = yes
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/wt65_a/rules.mk b/keyboards/wilba_tech/wt65_a/rules.mk
index a0f923a2f3..e892986112 100644
--- a/keyboards/wilba_tech/wt65_a/rules.mk
+++ b/keyboards/wilba_tech/wt65_a/rules.mk
@@ -30,7 +30,7 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
# project specific files
-SRC = drivers/issi/is31fl3736.c \
+SRC = drivers/led/issi/is31fl3736.c \
drivers/avr/i2c_master.c \
quantum/color.c \
keyboards/wilba_tech/wt_mono_backlight.c \
diff --git a/keyboards/wilba_tech/wt65_b/rules.mk b/keyboards/wilba_tech/wt65_b/rules.mk
index a0f923a2f3..e892986112 100644
--- a/keyboards/wilba_tech/wt65_b/rules.mk
+++ b/keyboards/wilba_tech/wt65_b/rules.mk
@@ -30,7 +30,7 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
# project specific files
-SRC = drivers/issi/is31fl3736.c \
+SRC = drivers/led/issi/is31fl3736.c \
drivers/avr/i2c_master.c \
quantum/color.c \
keyboards/wilba_tech/wt_mono_backlight.c \
diff --git a/keyboards/wilba_tech/wt75_a/rules.mk b/keyboards/wilba_tech/wt75_a/rules.mk
index a0f923a2f3..e892986112 100644
--- a/keyboards/wilba_tech/wt75_a/rules.mk
+++ b/keyboards/wilba_tech/wt75_a/rules.mk
@@ -30,7 +30,7 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
# project specific files
-SRC = drivers/issi/is31fl3736.c \
+SRC = drivers/led/issi/is31fl3736.c \
drivers/avr/i2c_master.c \
quantum/color.c \
keyboards/wilba_tech/wt_mono_backlight.c \
diff --git a/keyboards/wilba_tech/wt75_b/rules.mk b/keyboards/wilba_tech/wt75_b/rules.mk
index a0f923a2f3..e892986112 100644
--- a/keyboards/wilba_tech/wt75_b/rules.mk
+++ b/keyboards/wilba_tech/wt75_b/rules.mk
@@ -30,7 +30,7 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
# project specific files
-SRC = drivers/issi/is31fl3736.c \
+SRC = drivers/led/issi/is31fl3736.c \
drivers/avr/i2c_master.c \
quantum/color.c \
keyboards/wilba_tech/wt_mono_backlight.c \
diff --git a/keyboards/wilba_tech/wt75_c/rules.mk b/keyboards/wilba_tech/wt75_c/rules.mk
index a0f923a2f3..e892986112 100644
--- a/keyboards/wilba_tech/wt75_c/rules.mk
+++ b/keyboards/wilba_tech/wt75_c/rules.mk
@@ -30,7 +30,7 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
# project specific files
-SRC = drivers/issi/is31fl3736.c \
+SRC = drivers/led/issi/is31fl3736.c \
drivers/avr/i2c_master.c \
quantum/color.c \
keyboards/wilba_tech/wt_mono_backlight.c \
diff --git a/keyboards/wilba_tech/wt80_a/rules.mk b/keyboards/wilba_tech/wt80_a/rules.mk
index a0f923a2f3..e892986112 100644
--- a/keyboards/wilba_tech/wt80_a/rules.mk
+++ b/keyboards/wilba_tech/wt80_a/rules.mk
@@ -30,7 +30,7 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
# project specific files
-SRC = drivers/issi/is31fl3736.c \
+SRC = drivers/led/issi/is31fl3736.c \
drivers/avr/i2c_master.c \
quantum/color.c \
keyboards/wilba_tech/wt_mono_backlight.c \
diff --git a/keyboards/wilba_tech/wt_mono_backlight.c b/keyboards/wilba_tech/wt_mono_backlight.c
index fbc3102e8c..310e9afd1b 100644
--- a/keyboards/wilba_tech/wt_mono_backlight.c
+++ b/keyboards/wilba_tech/wt_mono_backlight.c
@@ -33,7 +33,7 @@
#error VIA_EEPROM_CUSTOM_CONFIG_SIZE was not defined to store backlight_config struct
#endif
-#include "drivers/issi/is31fl3736.h"
+#include "drivers/led/issi/is31fl3736.h"
#define ISSI_ADDR_DEFAULT 0x50
diff --git a/keyboards/wilba_tech/wt_rgb_backlight.c b/keyboards/wilba_tech/wt_rgb_backlight.c
index e57d061b20..e0359daab4 100644
--- a/keyboards/wilba_tech/wt_rgb_backlight.c
+++ b/keyboards/wilba_tech/wt_rgb_backlight.c
@@ -78,19 +78,19 @@ LED_TYPE g_ws2812_leds[WS2812_LED_TOTAL];
#endif
#if defined(RGB_BACKLIGHT_M6_B)
-#include "drivers/issi/is31fl3218.h"
+#include "drivers/led/issi/is31fl3218.h"
#define BACKLIGHT_LED_COUNT 6
#elif defined(RGB_BACKLIGHT_HS60)
-#include "drivers/issi/is31fl3733.h"
+#include "drivers/led/issi/is31fl3733.h"
#define BACKLIGHT_LED_COUNT 64
#elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
-#include "drivers/issi/is31fl3733.h"
+#include "drivers/led/issi/is31fl3733.h"
#define BACKLIGHT_LED_COUNT 69
#elif defined(RGB_BACKLIGHT_NK87)
-#include "drivers/issi/is31fl3733.h"
+#include "drivers/led/issi/is31fl3733.h"
#define BACKLIGHT_LED_COUNT 128
#else
-#include "drivers/issi/is31fl3731.h"
+#include "drivers/led/issi/is31fl3731.h"
#if defined(RGB_BACKLIGHT_U80_A)
#define BACKLIGHT_LED_COUNT 108
#elif defined(RGB_BACKLIGHT_DAWN60)
diff --git a/keyboards/wilba_tech/zeal60/rules.mk b/keyboards/wilba_tech/zeal60/rules.mk
index 172ebaf6b5..acd1ba36d9 100644
--- a/keyboards/wilba_tech/zeal60/rules.mk
+++ b/keyboards/wilba_tech/zeal60/rules.mk
@@ -44,5 +44,5 @@ LAYOUTS = 60_ansi 60_iso 60_hhkb 60_ansi_split_bs_rshift
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/wilba_tech/zeal65/rules.mk b/keyboards/wilba_tech/zeal65/rules.mk
index fcf3d07637..8c3a3772c1 100644
--- a/keyboards/wilba_tech/zeal65/rules.mk
+++ b/keyboards/wilba_tech/zeal65/rules.mk
@@ -42,5 +42,5 @@ CIE1931_CURVE = yes
SRC = keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
drivers/avr/i2c_master.c
diff --git a/keyboards/xelus/dawn60/rev1/rules.mk b/keyboards/xelus/dawn60/rev1/rules.mk
index 64b6615e81..dda4e5048f 100644
--- a/keyboards/xelus/dawn60/rev1/rules.mk
+++ b/keyboards/xelus/dawn60/rev1/rules.mk
@@ -42,7 +42,7 @@ CIE1931_CURVE = yes
SRC += keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
- drivers/issi/is31fl3731.c \
+ drivers/led/issi/is31fl3731.c \
ws2812.c
QUANTUM_LIB_SRC += i2c_master.c
diff --git a/keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c b/keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c
index 901f7a18c2..c305ecae14 100644
--- a/keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c
+++ b/keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c
@@ -18,7 +18,7 @@
#include
#include
#include
-#include "drivers/issi/is31fl3731.h"
+#include "drivers/led/issi/is31fl3731.h"
#include "ws2812.h"
#include "rev1_qmk.h"
diff --git a/keyboards/xelus/dawn60/rev1_qmk/rules.mk b/keyboards/xelus/dawn60/rev1_qmk/rules.mk
index edfba27304..eb1dd5557c 100644
--- a/keyboards/xelus/dawn60/rev1_qmk/rules.mk
+++ b/keyboards/xelus/dawn60/rev1_qmk/rules.mk
@@ -42,7 +42,7 @@ RGB_MATRIX_DRIVER = custom # Enable RGB matrix effects.
COMMON_VPATH += $(DRIVER_PATH)/issi
# project specific files
-SRC += drivers/issi/is31fl3731.c \
+SRC += drivers/led/issi/is31fl3731.c \
ws2812.c
QUANTUM_LIB_SRC += i2c_master.c
diff --git a/keyboards/xelus/pachi/rgb/rgb.c b/keyboards/xelus/pachi/rgb/rgb.c
index 1e4ad619c3..ea9812d6b1 100644
--- a/keyboards/xelus/pachi/rgb/rgb.c
+++ b/keyboards/xelus/pachi/rgb/rgb.c
@@ -23,7 +23,7 @@ void matrix_io_delay(void) { __asm__ volatile("nop\nnop\nnop\n"); }
#ifdef RGB_MATRIX_ENABLE
#include
-#include "drivers/issi/is31fl3741.h"
+#include "drivers/led/issi/is31fl3741.h"
const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
diff --git a/keyboards/xelus/pachi/rgb/rules.mk b/keyboards/xelus/pachi/rgb/rules.mk
index 6c1b3298c4..bc55888bef 100644
--- a/keyboards/xelus/pachi/rgb/rules.mk
+++ b/keyboards/xelus/pachi/rgb/rules.mk
@@ -29,7 +29,7 @@ RGB_MATRIX_ENABLE = yes
RGB_MATRIX_DRIVER = custom
COMMON_VPATH += $(DRIVER_PATH)/issi
-SRC += drivers/issi/is31fl3741.c
+SRC += drivers/led/issi/is31fl3741.c
LTO_ENABLE = yes
OPT = 2
--
cgit v1.2.3
From 70fb3e1aaf406cbbd5137916a93ed814d6891ef2 Mon Sep 17 00:00:00 2001
From: Joel Challis
Date: Sat, 31 Jul 2021 14:35:30 +0100
Subject: __flash? (#13799)
---
docs/feature_led_matrix.md | 2 +-
docs/feature_rgb_matrix.md | 8 ++++----
docs/ja/feature_led_matrix.md | 2 +-
drivers/led/aw20216.h | 3 ++-
drivers/led/issi/is31fl3731-simple.h | 3 ++-
drivers/led/issi/is31fl3731.h | 3 ++-
drivers/led/issi/is31fl3733.h | 3 ++-
drivers/led/issi/is31fl3736.h | 3 ++-
drivers/led/issi/is31fl3737.c | 9 ++-------
drivers/led/issi/is31fl3737.h | 3 ++-
drivers/led/issi/is31fl3741.h | 3 ++-
keyboards/clueboard/66_hotswap/gen1/gen1.c | 2 +-
keyboards/dp60/dp60.c | 2 +-
keyboards/durgod/dgk6x/galaxy/galaxy.c | 2 +-
keyboards/durgod/dgk6x/hades/hades.c | 2 +-
keyboards/durgod/dgk6x/venus/venus.c | 2 +-
keyboards/dztech/dz60rgb/dz60rgb.c | 2 +-
keyboards/dztech/dz60rgb_ansi/dz60rgb_ansi.c | 2 +-
keyboards/dztech/dz60rgb_wkl/dz60rgb_wkl.c | 2 +-
keyboards/dztech/dz65rgb/v1/v1.c | 2 +-
keyboards/dztech/dz65rgb/v2/v2.c | 2 +-
keyboards/dztech/dz65rgb/v3/v3.c | 2 +-
keyboards/ergodox_ez/ergodox_ez.c | 2 +-
keyboards/ergodox_infinity/ergodox_infinity.c | 2 +-
keyboards/exclusive/e6_rgb/e6_rgb.c | 2 +-
keyboards/fallacy/indicators.c | 2 +-
keyboards/geekboards/tester/tester.c | 2 +-
keyboards/hs60/v1/v1.c | 4 ++--
keyboards/inett_studio/sqx/hotswap/hotswap.c | 2 +-
keyboards/inett_studio/sqx/universal/universal.c | 2 +-
keyboards/k_type/is31fl3733-dual.h | 2 +-
keyboards/k_type/k_type.c | 2 +-
keyboards/kbdfans/bella/rgb/rgb.c | 2 +-
keyboards/kbdfans/bella/rgb_iso/rgb_iso.c | 2 +-
keyboards/kbdfans/kbd67/mkiirgb/mkiirgb.c | 2 +-
keyboards/kbdfans/kbdmini/kbdmini.c | 2 +-
keyboards/kbdfans/maja/maja.c | 2 +-
keyboards/keychron/q1/q1.c | 2 +-
keyboards/latin17rgb/latin17rgb.c | 2 +-
keyboards/latin60rgb/latin60rgb.c | 2 +-
keyboards/latin6rgb/latin6rgb.c | 2 +-
keyboards/matrix/m20add/rgb_ring.c | 2 +-
keyboards/matrix/noah/noah.c | 2 +-
keyboards/mechlovin/adelais/rgb_led/rev2/rev2.c | 2 +-
keyboards/mechlovin/delphine/rgb_led/rgb_led.c | 2 +-
keyboards/mechlovin/hannah60rgb/rev2/rev2.c | 2 +-
keyboards/mechlovin/infinity87/rgb_rev1/rgb_rev1.c | 2 +-
keyboards/melgeek/mj61/rev1/rev1.c | 2 +-
keyboards/melgeek/mj61/rev2/rev2.c | 2 +-
keyboards/melgeek/mj63/rev1/rev1.c | 2 +-
keyboards/melgeek/mj63/rev2/rev2.c | 2 +-
keyboards/melgeek/mj64/rev1/rev1.c | 2 +-
keyboards/melgeek/mj64/rev2/rev2.c | 2 +-
keyboards/melgeek/mj64/rev3/rev3.c | 2 +-
keyboards/melgeek/mj65/rev3/rev3.c | 2 +-
keyboards/melgeek/mojo75/rev1/rev1.c | 2 +-
keyboards/melgeek/z70ultra/z70ultra.c | 2 +-
keyboards/miller/gm862/gm862.c | 2 +-
keyboards/moonlander/moonlander.c | 2 +-
keyboards/mt64rgb/mt64rgb.c | 2 +-
keyboards/mt84/mt84.c | 2 +-
keyboards/opendeck/32/rev1/rev1.c | 2 +-
keyboards/planck/ez/ez.c | 2 +-
keyboards/planck/light/light.c | 2 +-
keyboards/terrazzo/terrazzo.c | 2 +-
keyboards/tkc/portico/portico.c | 2 +-
keyboards/whitefox/whitefox.c | 2 +-
keyboards/wilba_tech/wt_rgb_backlight.c | 16 ++++++++--------
keyboards/xbows/knight/knight.c | 2 +-
keyboards/xbows/knight_plus/knight_plus.c | 2 +-
keyboards/xbows/nature/nature.c | 2 +-
keyboards/xbows/numpad/numpad.c | 2 +-
keyboards/xbows/woody/woody.c | 2 +-
keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c | 2 +-
keyboards/xelus/pachi/rgb/rgb.c | 2 +-
tmk_core/common/progmem.h | 1 +
76 files changed, 95 insertions(+), 92 deletions(-)
(limited to 'drivers')
diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md
index afa11e7232..7d7971bbed 100644
--- a/docs/feature_led_matrix.md
+++ b/docs/feature_led_matrix.md
@@ -52,7 +52,7 @@ Here is an example using 2 drivers.
Define these arrays listing all the LEDs in your `.c`:
```c
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | LED address
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index 18e38955ec..670d7e09bf 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -52,7 +52,7 @@ Here is an example using 2 drivers.
Define these arrays listing all the LEDs in your `.c`:
```c
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -122,7 +122,7 @@ Currently only 4 drivers are supported, but it would be trivial to support all 8
Define these arrays listing all the LEDs in your `.c`:
```c
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -186,7 +186,7 @@ Currently only 2 drivers are supported, but it would be trivial to support all 4
Define these arrays listing all the LEDs in your `.c`:
```c
-const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -287,7 +287,7 @@ Here is an example using 2 drivers.
Define these arrays listing all the LEDs in your `.c`:
```c
-const aw_led g_aw_leds[DRIVER_LED_TOTAL] = {
+const aw_led __flash g_aw_leds[DRIVER_LED_TOTAL] = {
/* Each AW20216 channel is controlled by a register at some offset between 0x00
* and 0xD7 inclusive.
* See drivers/awinic/aw20216.h for the mapping between register offsets and
diff --git a/docs/ja/feature_led_matrix.md b/docs/ja/feature_led_matrix.md
index f132d716f6..6511b28249 100644
--- a/docs/ja/feature_led_matrix.md
+++ b/docs/ja/feature_led_matrix.md
@@ -52,7 +52,7 @@ I2C IS31FL3731 RGB コントローラを使ったアドレス指定可能な LED
`.c` に全ての LED を列挙する配列を定義します:
- const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+ const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* これらの位置については IS31 マニュアルを参照してください
* driver
* | LED address
diff --git a/drivers/led/aw20216.h b/drivers/led/aw20216.h
index c55d9605fc..97ac6dc5bf 100644
--- a/drivers/led/aw20216.h
+++ b/drivers/led/aw20216.h
@@ -18,6 +18,7 @@
#include
#include
+#include "progmem.h"
#include "gpio.h"
typedef struct aw_led {
@@ -27,7 +28,7 @@ typedef struct aw_led {
uint8_t b;
} aw_led;
-extern const aw_led g_aw_leds[DRIVER_LED_TOTAL];
+extern const aw_led __flash g_aw_leds[DRIVER_LED_TOTAL];
void AW20216_init(pin_t cs_pin, pin_t en_pin);
void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
diff --git a/drivers/led/issi/is31fl3731-simple.h b/drivers/led/issi/is31fl3731-simple.h
index 9665d6ed35..ecde31eed5 100644
--- a/drivers/led/issi/is31fl3731-simple.h
+++ b/drivers/led/issi/is31fl3731-simple.h
@@ -20,13 +20,14 @@
#include
#include
+#include "progmem.h"
typedef struct is31_led {
uint8_t driver : 2;
uint8_t v;
} __attribute__((packed)) is31_led;
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];
void IS31FL3731_init(uint8_t addr);
void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
diff --git a/drivers/led/issi/is31fl3731.h b/drivers/led/issi/is31fl3731.h
index 19e8e6251f..803ea3ea12 100644
--- a/drivers/led/issi/is31fl3731.h
+++ b/drivers/led/issi/is31fl3731.h
@@ -19,6 +19,7 @@
#include
#include
+#include "progmem.h"
typedef struct is31_led {
uint8_t driver : 2;
@@ -27,7 +28,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];
void IS31FL3731_init(uint8_t addr);
void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
diff --git a/drivers/led/issi/is31fl3733.h b/drivers/led/issi/is31fl3733.h
index 603d505a13..64fd38eb19 100644
--- a/drivers/led/issi/is31fl3733.h
+++ b/drivers/led/issi/is31fl3733.h
@@ -20,6 +20,7 @@
#include
#include
+#include "progmem.h"
typedef struct is31_led {
uint8_t driver : 2;
@@ -28,7 +29,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];
void IS31FL3733_init(uint8_t addr, uint8_t sync);
bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
diff --git a/drivers/led/issi/is31fl3736.h b/drivers/led/issi/is31fl3736.h
index e48e31c279..c956c87f7c 100644
--- a/drivers/led/issi/is31fl3736.h
+++ b/drivers/led/issi/is31fl3736.h
@@ -18,6 +18,7 @@
#include
#include
+#include "progmem.h"
// Simple interface option.
// If these aren't defined, just define them to make it compile
@@ -37,7 +38,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];
void IS31FL3736_init(uint8_t addr);
void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
diff --git a/drivers/led/issi/is31fl3737.c b/drivers/led/issi/is31fl3737.c
index 30906b4840..0bb4ddd425 100644
--- a/drivers/led/issi/is31fl3737.c
+++ b/drivers/led/issi/is31fl3737.c
@@ -19,7 +19,6 @@
#include "is31fl3737.h"
#include "i2c_master.h"
#include "wait.h"
-#include "progmem.h"
// This is a 7-bit address, that gets left-shifted and bit 0
// set to 0 for write, 1 for read (as per I2C protocol)
@@ -155,9 +154,7 @@ void IS31FL3737_init(uint8_t addr) {
void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index >= 0 && index < DRIVER_LED_TOTAL) {
- // copy the led config from progmem to SRAM
- is31_led led;
- memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
+ is31_led led = g_is31_leds[index];
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
@@ -173,9 +170,7 @@ void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
}
void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
- // copy the led config from progmem to SRAM
- is31_led led;
- memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
+ is31_led led = g_is31_leds[index];
uint8_t control_register_r = led.r / 8;
uint8_t control_register_g = led.g / 8;
diff --git a/drivers/led/issi/is31fl3737.h b/drivers/led/issi/is31fl3737.h
index a1d2281778..06886e9c9b 100644
--- a/drivers/led/issi/is31fl3737.h
+++ b/drivers/led/issi/is31fl3737.h
@@ -20,6 +20,7 @@
#include
#include
+#include "progmem.h"
typedef struct is31_led {
uint8_t driver : 2;
@@ -28,7 +29,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];
void IS31FL3737_init(uint8_t addr);
void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
diff --git a/drivers/led/issi/is31fl3741.h b/drivers/led/issi/is31fl3741.h
index 2df0c5b1a7..cea6761ca8 100644
--- a/drivers/led/issi/is31fl3741.h
+++ b/drivers/led/issi/is31fl3741.h
@@ -21,6 +21,7 @@
#include
#include
+#include "progmem.h"
typedef struct is31_led {
uint32_t driver : 2;
@@ -29,7 +30,7 @@ typedef struct is31_led {
uint32_t b : 10;
} __attribute__((packed)) is31_led;
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];
void IS31FL3741_init(uint8_t addr);
void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
diff --git a/keyboards/clueboard/66_hotswap/gen1/gen1.c b/keyboards/clueboard/66_hotswap/gen1/gen1.c
index 339bd78d5a..8e3db70d07 100644
--- a/keyboards/clueboard/66_hotswap/gen1/gen1.c
+++ b/keyboards/clueboard/66_hotswap/gen1/gen1.c
@@ -16,7 +16,7 @@
#include "gen1.h"
#ifdef LED_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | LED address
diff --git a/keyboards/dp60/dp60.c b/keyboards/dp60/dp60.c
index 475084b049..87543b2a1c 100644
--- a/keyboards/dp60/dp60.c
+++ b/keyboards/dp60/dp60.c
@@ -17,7 +17,7 @@
#include "dp60.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/durgod/dgk6x/galaxy/galaxy.c b/keyboards/durgod/dgk6x/galaxy/galaxy.c
index d101533b16..5f793ed85b 100644
--- a/keyboards/durgod/dgk6x/galaxy/galaxy.c
+++ b/keyboards/durgod/dgk6x/galaxy/galaxy.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/durgod/dgk6x/hades/hades.c b/keyboards/durgod/dgk6x/hades/hades.c
index 21b2722913..3e235683f1 100644
--- a/keyboards/durgod/dgk6x/hades/hades.c
+++ b/keyboards/durgod/dgk6x/hades/hades.c
@@ -19,7 +19,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/durgod/dgk6x/venus/venus.c b/keyboards/durgod/dgk6x/venus/venus.c
index 2d49b34daf..3398acb19d 100644
--- a/keyboards/durgod/dgk6x/venus/venus.c
+++ b/keyboards/durgod/dgk6x/venus/venus.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/dztech/dz60rgb/dz60rgb.c b/keyboards/dztech/dz60rgb/dz60rgb.c
index aa02fb902d..a7fc3dbc5c 100644
--- a/keyboards/dztech/dz60rgb/dz60rgb.c
+++ b/keyboards/dztech/dz60rgb/dz60rgb.c
@@ -1,7 +1,7 @@
#include "dz60rgb.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, K_14, J_14, L_14 },
{ 0, K_13, J_13, L_13 },
{ 0, K_12, J_12, L_12 },
diff --git a/keyboards/dztech/dz60rgb_ansi/dz60rgb_ansi.c b/keyboards/dztech/dz60rgb_ansi/dz60rgb_ansi.c
index 4bb5938b66..ab24410912 100644
--- a/keyboards/dztech/dz60rgb_ansi/dz60rgb_ansi.c
+++ b/keyboards/dztech/dz60rgb_ansi/dz60rgb_ansi.c
@@ -1,7 +1,7 @@
#include "dz60rgb_ansi.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, K_14, J_14, L_14 },
{ 0, K_13, J_13, L_13 },
{ 0, K_12, J_12, L_12 },
diff --git a/keyboards/dztech/dz60rgb_wkl/dz60rgb_wkl.c b/keyboards/dztech/dz60rgb_wkl/dz60rgb_wkl.c
index b57560bacd..455624471d 100644
--- a/keyboards/dztech/dz60rgb_wkl/dz60rgb_wkl.c
+++ b/keyboards/dztech/dz60rgb_wkl/dz60rgb_wkl.c
@@ -1,7 +1,7 @@
#include "dz60rgb_wkl.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, H_15, G_15, I_15 },
{ 0, K_14, J_14, L_14 },
{ 0, K_13, J_13, L_13 },
diff --git a/keyboards/dztech/dz65rgb/v1/v1.c b/keyboards/dztech/dz65rgb/v1/v1.c
index 8a3f0e27bf..aabe41c313 100644
--- a/keyboards/dztech/dz65rgb/v1/v1.c
+++ b/keyboards/dztech/dz65rgb/v1/v1.c
@@ -16,7 +16,7 @@
#include "v1.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, C8_8, C7_8, C6_8 },
{ 0, C9_8, C7_7, C6_7 },
{ 0, C9_7, C8_7, C6_6 },
diff --git a/keyboards/dztech/dz65rgb/v2/v2.c b/keyboards/dztech/dz65rgb/v2/v2.c
index 788709d989..dce167c73f 100644
--- a/keyboards/dztech/dz65rgb/v2/v2.c
+++ b/keyboards/dztech/dz65rgb/v2/v2.c
@@ -16,7 +16,7 @@
#include "v2.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, C8_8, C7_8, C6_8 },
{ 0, C9_8, C7_7, C6_7 },
{ 0, C9_7, C8_7, C6_6 },
diff --git a/keyboards/dztech/dz65rgb/v3/v3.c b/keyboards/dztech/dz65rgb/v3/v3.c
index dec75814ca..c3719bfa51 100755
--- a/keyboards/dztech/dz65rgb/v3/v3.c
+++ b/keyboards/dztech/dz65rgb/v3/v3.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS21_SW1, CS20_SW1, CS19_SW1},
{0, CS21_SW2, CS20_SW2, CS19_SW2},
{0, CS21_SW3, CS20_SW3, CS19_SW3},
diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c
index 47dd1b0cc9..7af76cb624 100644
--- a/keyboards/ergodox_ez/ergodox_ez.c
+++ b/keyboards/ergodox_ez/ergodox_ez.c
@@ -243,7 +243,7 @@ const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
#ifdef RGB_MATRIX_ENABLE
// clang-format off
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* driver
* | R location
* | | G location
diff --git a/keyboards/ergodox_infinity/ergodox_infinity.c b/keyboards/ergodox_infinity/ergodox_infinity.c
index 76cbca07f8..90aa522427 100644
--- a/keyboards/ergodox_infinity/ergodox_infinity.c
+++ b/keyboards/ergodox_infinity/ergodox_infinity.c
@@ -191,7 +191,7 @@ const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
#endif
#ifdef LED_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
// The numbers in the comments are the led numbers DXX on the PCB
/* Refer to IS31 manual for these locations
* driver
diff --git a/keyboards/exclusive/e6_rgb/e6_rgb.c b/keyboards/exclusive/e6_rgb/e6_rgb.c
index 0e248a2023..e0d313f835 100644
--- a/keyboards/exclusive/e6_rgb/e6_rgb.c
+++ b/keyboards/exclusive/e6_rgb/e6_rgb.c
@@ -11,7 +11,7 @@ void matrix_init_kb(void) {
matrix_init_user();
}
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/fallacy/indicators.c b/keyboards/fallacy/indicators.c
index 08c500064d..dcf1b4de07 100755
--- a/keyboards/fallacy/indicators.c
+++ b/keyboards/fallacy/indicators.c
@@ -54,7 +54,7 @@ void set_fallacy_led(int index, bool state) {
/* define LED matrix
*/
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C1_1},
{0, C2_1},
{0, C3_1},
diff --git a/keyboards/geekboards/tester/tester.c b/keyboards/geekboards/tester/tester.c
index 4fab1a7012..0c5c056cc0 100644
--- a/keyboards/geekboards/tester/tester.c
+++ b/keyboards/geekboards/tester/tester.c
@@ -1,5 +1,5 @@
#include "tester.h"
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/hs60/v1/v1.c b/keyboards/hs60/v1/v1.c
index 70c1c2128e..58b19b6408 100644
--- a/keyboards/hs60/v1/v1.c
+++ b/keyboards/hs60/v1/v1.c
@@ -91,7 +91,7 @@ void raw_hid_receive( uint8_t *data, uint8_t length )
#ifdef HS60_ANSI
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -199,7 +199,7 @@ led_config_t g_led_config = { {
#else
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/inett_studio/sqx/hotswap/hotswap.c b/keyboards/inett_studio/sqx/hotswap/hotswap.c
index be8985c87e..5b3c8df822 100644
--- a/keyboards/inett_studio/sqx/hotswap/hotswap.c
+++ b/keyboards/inett_studio/sqx/hotswap/hotswap.c
@@ -20,7 +20,7 @@
#include "hotswap.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/inett_studio/sqx/universal/universal.c b/keyboards/inett_studio/sqx/universal/universal.c
index 42d99330d5..dd431a7f45 100644
--- a/keyboards/inett_studio/sqx/universal/universal.c
+++ b/keyboards/inett_studio/sqx/universal/universal.c
@@ -20,7 +20,7 @@
#include "universal.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/k_type/is31fl3733-dual.h b/keyboards/k_type/is31fl3733-dual.h
index 272bcdc417..aab170a3fd 100644
--- a/keyboards/k_type/is31fl3733-dual.h
+++ b/keyboards/k_type/is31fl3733-dual.h
@@ -28,7 +28,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;
-extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
+extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];
void IS31FL3733_init(uint8_t bus, uint8_t addr, uint8_t sync);
bool IS31FL3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data);
diff --git a/keyboards/k_type/k_type.c b/keyboards/k_type/k_type.c
index 61c5881454..924862277f 100644
--- a/keyboards/k_type/k_type.c
+++ b/keyboards/k_type/k_type.c
@@ -23,7 +23,7 @@ along with this program. If not, see .
#include "is31fl3733-dual.h"
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, B_1, A_1, C_1 },
{ 0, B_2, A_2, C_2 },
{ 0, B_3, A_3, C_3 },
diff --git a/keyboards/kbdfans/bella/rgb/rgb.c b/keyboards/kbdfans/bella/rgb/rgb.c
index e197d9b538..17cf992146 100644
--- a/keyboards/kbdfans/bella/rgb/rgb.c
+++ b/keyboards/kbdfans/bella/rgb/rgb.c
@@ -15,7 +15,7 @@
*/
#include "rgb.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS18_SW1, CS17_SW1, CS16_SW1}, /* RGB6 */
{0, CS18_SW3, CS17_SW3, CS16_SW3}, /* RGB32 */
{0, CS18_SW4, CS17_SW4, CS16_SW4}, /* RGB45 */
diff --git a/keyboards/kbdfans/bella/rgb_iso/rgb_iso.c b/keyboards/kbdfans/bella/rgb_iso/rgb_iso.c
index 1a853ac8af..0c431b1543 100644
--- a/keyboards/kbdfans/bella/rgb_iso/rgb_iso.c
+++ b/keyboards/kbdfans/bella/rgb_iso/rgb_iso.c
@@ -15,7 +15,7 @@
*/
#include "rgb_iso.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS18_SW1, CS17_SW1, CS16_SW1}, /* RGB6 */
{0, CS18_SW3, CS17_SW3, CS16_SW3}, /* RGB32 */
{0, CS18_SW4, CS17_SW4, CS16_SW4}, /* RGB45 */
diff --git a/keyboards/kbdfans/kbd67/mkiirgb/mkiirgb.c b/keyboards/kbdfans/kbd67/mkiirgb/mkiirgb.c
index 323cb23848..2826c08988 100644
--- a/keyboards/kbdfans/kbd67/mkiirgb/mkiirgb.c
+++ b/keyboards/kbdfans/kbd67/mkiirgb/mkiirgb.c
@@ -1,6 +1,6 @@
#include "mkiirgb.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C8_8, C7_8, C6_8}, // LA17
{0, C9_8, C7_7, C6_7}, // LA16
diff --git a/keyboards/kbdfans/kbdmini/kbdmini.c b/keyboards/kbdfans/kbdmini/kbdmini.c
index 0e0df2f9af..799803c6fa 100644
--- a/keyboards/kbdfans/kbdmini/kbdmini.c
+++ b/keyboards/kbdfans/kbdmini/kbdmini.c
@@ -1,6 +1,6 @@
#include "kbdmini.h"
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, B_9, A_9, C_9 }, //LA33
{ 0, B_10, A_10, C_10 }, //LA37
{ 0, B_11, A_11, C_11 }, //LA41
diff --git a/keyboards/kbdfans/maja/maja.c b/keyboards/kbdfans/maja/maja.c
index a0afcbda8a..9619a84b48 100755
--- a/keyboards/kbdfans/maja/maja.c
+++ b/keyboards/kbdfans/maja/maja.c
@@ -1,6 +1,6 @@
#include "maja.h"
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C2_1, C3_1, C4_1}, // LA0
{0, C1_1, C3_2, C4_2}, // LA1
{0, C1_2, C2_2, C4_3}, // LA2
diff --git a/keyboards/keychron/q1/q1.c b/keyboards/keychron/q1/q1.c
index 520e6e4c57..6beb96e7eb 100644
--- a/keyboards/keychron/q1/q1.c
+++ b/keyboards/keychron/q1/q1.c
@@ -33,7 +33,7 @@ bool dip_switch_update_kb(uint8_t index, bool active) {
return true;
}
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/latin17rgb/latin17rgb.c b/keyboards/latin17rgb/latin17rgb.c
index 8d9eaae8ae..f7bbe125c2 100644
--- a/keyboards/latin17rgb/latin17rgb.c
+++ b/keyboards/latin17rgb/latin17rgb.c
@@ -17,7 +17,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/latin60rgb/latin60rgb.c b/keyboards/latin60rgb/latin60rgb.c
index cdd6fed44d..fe5d2eea8f 100644
--- a/keyboards/latin60rgb/latin60rgb.c
+++ b/keyboards/latin60rgb/latin60rgb.c
@@ -16,7 +16,7 @@
#include "latin60rgb.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, K_13, J_13, L_13 },
{ 0, K_12, J_12, L_12 },
{ 0, K_11, J_11, L_11 },
diff --git a/keyboards/latin6rgb/latin6rgb.c b/keyboards/latin6rgb/latin6rgb.c
index 76b39c86bb..9ea4721ecb 100644
--- a/keyboards/latin6rgb/latin6rgb.c
+++ b/keyboards/latin6rgb/latin6rgb.c
@@ -17,7 +17,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/matrix/m20add/rgb_ring.c b/keyboards/matrix/m20add/rgb_ring.c
index fa70dea7eb..3a8af7cd3b 100644
--- a/keyboards/matrix/m20add/rgb_ring.c
+++ b/keyboards/matrix/m20add/rgb_ring.c
@@ -30,7 +30,7 @@
#endif
// rgb ring leds setting
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/matrix/noah/noah.c b/keyboards/matrix/noah/noah.c
index 1e2f4bb7d9..6b624b9e09 100644
--- a/keyboards/matrix/noah/noah.c
+++ b/keyboards/matrix/noah/noah.c
@@ -66,7 +66,7 @@ __attribute__((weak))
void matrix_scan_user(void) { }
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/mechlovin/adelais/rgb_led/rev2/rev2.c b/keyboards/mechlovin/adelais/rgb_led/rev2/rev2.c
index 5087174b96..fe946169a7 100644
--- a/keyboards/mechlovin/adelais/rgb_led/rev2/rev2.c
+++ b/keyboards/mechlovin/adelais/rgb_led/rev2/rev2.c
@@ -17,7 +17,7 @@
#include "adelais.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C2_1, C3_1, C4_1}, //D102-A0-0
{0, C5_1, C6_1, C7_1}, //D108-A1-1
diff --git a/keyboards/mechlovin/delphine/rgb_led/rgb_led.c b/keyboards/mechlovin/delphine/rgb_led/rgb_led.c
index 6f3e3ec731..29b6d1f783 100644
--- a/keyboards/mechlovin/delphine/rgb_led/rgb_led.c
+++ b/keyboards/mechlovin/delphine/rgb_led/rgb_led.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
// left CA
{0, C5_2, C6_2, C7_2}, //D2-0
{0, C1_1, C3_2, C4_2}, //D20-1
diff --git a/keyboards/mechlovin/hannah60rgb/rev2/rev2.c b/keyboards/mechlovin/hannah60rgb/rev2/rev2.c
index 05469a1bbe..8b30538cc2 100644
--- a/keyboards/mechlovin/hannah60rgb/rev2/rev2.c
+++ b/keyboards/mechlovin/hannah60rgb/rev2/rev2.c
@@ -17,7 +17,7 @@
#include "rev2.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/mechlovin/infinity87/rgb_rev1/rgb_rev1.c b/keyboards/mechlovin/infinity87/rgb_rev1/rgb_rev1.c
index f13fee8add..bd1fd8abf7 100644
--- a/keyboards/mechlovin/infinity87/rgb_rev1/rgb_rev1.c
+++ b/keyboards/mechlovin/infinity87/rgb_rev1/rgb_rev1.c
@@ -17,7 +17,7 @@
#include "rgb_rev1.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS34_SW1, CS35_SW1, CS36_SW1}, //D92-K00-0
{0, CS37_SW1, CS38_SW1, CS39_SW1}, //D94-K01-1
{0, CS31_SW1, CS32_SW1, CS33_SW1}, //D96-K02-2
diff --git a/keyboards/melgeek/mj61/rev1/rev1.c b/keyboards/melgeek/mj61/rev1/rev1.c
index be58f57a95..e51c57548f 100644
--- a/keyboards/melgeek/mj61/rev1/rev1.c
+++ b/keyboards/melgeek/mj61/rev1/rev1.c
@@ -17,7 +17,7 @@
#include "mj61.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS12_SW1, CS11_SW1, CS10_SW1}, /* RGB1 */
{0, CS12_SW2, CS11_SW2, CS10_SW2}, /* RGB2 */
{0, CS12_SW3, CS11_SW3, CS10_SW3}, /* RGB3 */
diff --git a/keyboards/melgeek/mj61/rev2/rev2.c b/keyboards/melgeek/mj61/rev2/rev2.c
index 236b003972..3f6b1bff77 100644
--- a/keyboards/melgeek/mj61/rev2/rev2.c
+++ b/keyboards/melgeek/mj61/rev2/rev2.c
@@ -19,7 +19,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS9_SW1, CS8_SW1, CS7_SW1}, /* RGB1 */
{0, CS9_SW2, CS8_SW2, CS7_SW2}, /* RGB3 */
{0, CS9_SW3, CS8_SW3, CS7_SW3}, /* RGB4 */
diff --git a/keyboards/melgeek/mj63/rev1/rev1.c b/keyboards/melgeek/mj63/rev1/rev1.c
index 34ff28d25f..a6ee8859b0 100644
--- a/keyboards/melgeek/mj63/rev1/rev1.c
+++ b/keyboards/melgeek/mj63/rev1/rev1.c
@@ -19,7 +19,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS9_SW1, CS8_SW1, CS7_SW1}, /* RGB1 */
{0, CS9_SW2, CS8_SW2, CS7_SW2}, /* RGB2 */
{0, CS9_SW3, CS8_SW3, CS7_SW3}, /* RGB3 */
diff --git a/keyboards/melgeek/mj63/rev2/rev2.c b/keyboards/melgeek/mj63/rev2/rev2.c
index c2379dabe9..8cacc689ae 100644
--- a/keyboards/melgeek/mj63/rev2/rev2.c
+++ b/keyboards/melgeek/mj63/rev2/rev2.c
@@ -19,7 +19,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS9_SW1, CS8_SW1, CS7_SW1}, /* RGB1 */
{0, CS9_SW2, CS8_SW2, CS7_SW2}, /* RGB3 */
{0, CS9_SW3, CS8_SW3, CS7_SW3}, /* RGB4 */
diff --git a/keyboards/melgeek/mj64/rev1/rev1.c b/keyboards/melgeek/mj64/rev1/rev1.c
index e01765b694..446ba779d0 100644
--- a/keyboards/melgeek/mj64/rev1/rev1.c
+++ b/keyboards/melgeek/mj64/rev1/rev1.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS9_SW1, CS8_SW1, CS7_SW1}, /* RGB1 */
{0, CS9_SW2, CS8_SW2, CS7_SW2}, /* RGB2 */
{0, CS9_SW3, CS8_SW3, CS7_SW3}, /* RGB3 */
diff --git a/keyboards/melgeek/mj64/rev2/rev2.c b/keyboards/melgeek/mj64/rev2/rev2.c
index d5486b9086..444e8f60ac 100644
--- a/keyboards/melgeek/mj64/rev2/rev2.c
+++ b/keyboards/melgeek/mj64/rev2/rev2.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS9_SW1, CS8_SW1, CS7_SW1}, /* RGB1 */
{0, CS9_SW2, CS8_SW2, CS7_SW2}, /* RGB2 */
{0, CS9_SW3, CS8_SW3, CS7_SW3}, /* RGB3 */
diff --git a/keyboards/melgeek/mj64/rev3/rev3.c b/keyboards/melgeek/mj64/rev3/rev3.c
index 03ed9fe007..2a1283ec70 100644
--- a/keyboards/melgeek/mj64/rev3/rev3.c
+++ b/keyboards/melgeek/mj64/rev3/rev3.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS9_SW1, CS8_SW1, CS7_SW1}, /* RGB1 */
{0, CS9_SW2, CS8_SW2, CS7_SW2}, /* RGB3 */
{0, CS9_SW3, CS8_SW3, CS7_SW3}, /* RGB4 */
diff --git a/keyboards/melgeek/mj65/rev3/rev3.c b/keyboards/melgeek/mj65/rev3/rev3.c
index 43fae53a36..6335edd796 100644
--- a/keyboards/melgeek/mj65/rev3/rev3.c
+++ b/keyboards/melgeek/mj65/rev3/rev3.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS9_SW1, CS8_SW1, CS7_SW1}, /* RGB1 */
{0, CS9_SW2, CS8_SW2, CS7_SW2}, /* RGB2 */
{0, CS9_SW3, CS8_SW3, CS7_SW3}, /* RGB3 */
diff --git a/keyboards/melgeek/mojo75/rev1/rev1.c b/keyboards/melgeek/mojo75/rev1/rev1.c
index 670116fcd6..07ae916da2 100644
--- a/keyboards/melgeek/mojo75/rev1/rev1.c
+++ b/keyboards/melgeek/mojo75/rev1/rev1.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS6_SW1, CS5_SW1, CS4_SW1}, /* RGB1 */
{0, CS6_SW2, CS5_SW2, CS4_SW2}, /* RGB2 */
{0, CS6_SW3, CS5_SW3, CS4_SW3}, /* RGB3 */
diff --git a/keyboards/melgeek/z70ultra/z70ultra.c b/keyboards/melgeek/z70ultra/z70ultra.c
index 740720681a..552576cd7c 100644
--- a/keyboards/melgeek/z70ultra/z70ultra.c
+++ b/keyboards/melgeek/z70ultra/z70ultra.c
@@ -18,7 +18,7 @@
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, CS28_SW1, CS30_SW1, CS29_SW1}, /* RGB10 */
{0, CS28_SW2, CS30_SW2, CS29_SW2}, /* RGB11 */
{0, CS28_SW3, CS30_SW3, CS29_SW3}, /* RGB12 */
diff --git a/keyboards/miller/gm862/gm862.c b/keyboards/miller/gm862/gm862.c
index 5af66dd398..d67104838b 100644
--- a/keyboards/miller/gm862/gm862.c
+++ b/keyboards/miller/gm862/gm862.c
@@ -1,7 +1,7 @@
#include "gm862.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, B_1, A_1, C_1},
{0, B_2, A_2, C_2},
{0, B_3, A_3, C_3},
diff --git a/keyboards/moonlander/moonlander.c b/keyboards/moonlander/moonlander.c
index d66b74d973..8688b9efa4 100644
--- a/keyboards/moonlander/moonlander.c
+++ b/keyboards/moonlander/moonlander.c
@@ -203,7 +203,7 @@ layer_state_t layer_state_set_kb(layer_state_t state) {
#ifdef RGB_MATRIX_ENABLE
// clang-format off
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/mt64rgb/mt64rgb.c b/keyboards/mt64rgb/mt64rgb.c
index 73f0e562e7..a0b8e8da71 100644
--- a/keyboards/mt64rgb/mt64rgb.c
+++ b/keyboards/mt64rgb/mt64rgb.c
@@ -16,7 +16,7 @@
#include "mt64rgb.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/mt84/mt84.c b/keyboards/mt84/mt84.c
index e15a1ff951..9b00aa635e 100644
--- a/keyboards/mt84/mt84.c
+++ b/keyboards/mt84/mt84.c
@@ -16,7 +16,7 @@
#include "mt84.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/opendeck/32/rev1/rev1.c b/keyboards/opendeck/32/rev1/rev1.c
index 297af907e2..91f59a60b7 100644
--- a/keyboards/opendeck/32/rev1/rev1.c
+++ b/keyboards/opendeck/32/rev1/rev1.c
@@ -17,7 +17,7 @@
#include "rev1.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c
index 5c68726a01..27cb2a1d1d 100644
--- a/keyboards/planck/ez/ez.c
+++ b/keyboards/planck/ez/ez.c
@@ -21,7 +21,7 @@
keyboard_config_t keyboard_config;
#ifdef RGB_MATRIX_ENABLE
-const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/planck/light/light.c b/keyboards/planck/light/light.c
index 896ec44587..3a53e39985 100644
--- a/keyboards/planck/light/light.c
+++ b/keyboards/planck/light/light.c
@@ -16,7 +16,7 @@
#include "light.h"
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/terrazzo/terrazzo.c b/keyboards/terrazzo/terrazzo.c
index e6ba1f6c39..19ac6be491 100644
--- a/keyboards/terrazzo/terrazzo.c
+++ b/keyboards/terrazzo/terrazzo.c
@@ -21,7 +21,7 @@
#include "print.h"
#include "quantum.h"
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* https://cdn-learn.adafruit.com/downloads/pdf/adafruit-15x7-7x15-charlieplex-led-matrix-charliewing-featherwing.pdf
*/
diff --git a/keyboards/tkc/portico/portico.c b/keyboards/tkc/portico/portico.c
index a65a85d242..e3d3a14880 100644
--- a/keyboards/tkc/portico/portico.c
+++ b/keyboards/tkc/portico/portico.c
@@ -19,7 +19,7 @@ along with this program. If not, see .
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{ 0, C2_1, C3_1, C4_1 },
{ 0, C1_1, C3_2, C4_2 },
{ 0, C1_2, C2_2, C4_3 },
diff --git a/keyboards/whitefox/whitefox.c b/keyboards/whitefox/whitefox.c
index f10f0fd5c4..b17af15127 100644
--- a/keyboards/whitefox/whitefox.c
+++ b/keyboards/whitefox/whitefox.c
@@ -18,7 +18,7 @@ along with this program. If not, see .
#include "whitefox.h"
#ifdef LED_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
// The numbers in the comments are the led numbers DXX on the PCB
/* Refer to IS31 manual for these locations
* driver
diff --git a/keyboards/wilba_tech/wt_rgb_backlight.c b/keyboards/wilba_tech/wt_rgb_backlight.c
index e0359daab4..77613a3338 100644
--- a/keyboards/wilba_tech/wt_rgb_backlight.c
+++ b/keyboards/wilba_tech/wt_rgb_backlight.c
@@ -158,7 +158,7 @@ uint32_t g_any_key_hit = 0;
// ADDR_2 is not needed. it is here as a dummy
#define ISSI_ADDR_1 0x50
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -239,7 +239,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
#define ISSI_ADDR_1 0x50
#define ISSI_ADDR_2 0x52
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -382,7 +382,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
// set to 0 for write, 1 for read (as per I2C protocol)
#define ISSI_ADDR_1 0x74
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -414,7 +414,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
#define ISSI_ADDR_2 0x76 // 11101[10] <- SDA
#define ISSI_ADDR_3 0x75 // 11101[01] <- SCL
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -541,7 +541,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
#define ISSI_ADDR_1 0x74
#define ISSI_ADDR_2 0x76
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -622,7 +622,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
#define ISSI_ADDR_1 0x74
#define ISSI_ADDR_2 0x77
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
@@ -709,7 +709,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
#define ISSI_ADDR_1 0x74
#define ISSI_ADDR_2
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C1_9, C3_10, C4_10}, // LB1
{0, C1_10, C2_10, C4_11}, // LB2
{0, C1_11, C2_11, C3_11}, // LB3
@@ -729,7 +729,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
#define ISSI_ADDR_1 0x74
#define ISSI_ADDR_2 0x76
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/xbows/knight/knight.c b/keyboards/xbows/knight/knight.c
index 1a1aebf18f..539ecb653e 100644
--- a/keyboards/xbows/knight/knight.c
+++ b/keyboards/xbows/knight/knight.c
@@ -15,7 +15,7 @@
*/
#include "knight.h"
#ifdef RGB_MATRIX_ENABLE
- const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+ const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C1_3, C2_3, C3_3}, // L01
{0, C1_4, C2_4, C3_4}, // L02
diff --git a/keyboards/xbows/knight_plus/knight_plus.c b/keyboards/xbows/knight_plus/knight_plus.c
index f2cf5399b6..c5dd1a5fd6 100644
--- a/keyboards/xbows/knight_plus/knight_plus.c
+++ b/keyboards/xbows/knight_plus/knight_plus.c
@@ -15,7 +15,7 @@
*/
#include "knight_plus.h"
#ifdef RGB_MATRIX_ENABLE
- const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+ const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C1_3, C2_3, C3_3}, // L01
{0, C1_4, C2_4, C3_4}, // L02
diff --git a/keyboards/xbows/nature/nature.c b/keyboards/xbows/nature/nature.c
index f1b0615845..b7b10d5abb 100644
--- a/keyboards/xbows/nature/nature.c
+++ b/keyboards/xbows/nature/nature.c
@@ -15,7 +15,7 @@
*/
#include "nature.h"
#ifdef RGB_MATRIX_ENABLE
- const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+ const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C1_3, C2_3, C3_3}, // L01
{0, C1_4, C2_4, C3_4}, // L02
diff --git a/keyboards/xbows/numpad/numpad.c b/keyboards/xbows/numpad/numpad.c
index 0ab677c769..4e05473b67 100644
--- a/keyboards/xbows/numpad/numpad.c
+++ b/keyboards/xbows/numpad/numpad.c
@@ -15,7 +15,7 @@
*/
#include "numpad.h"
#ifdef RGB_MATRIX_ENABLE
- const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+ const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C3_3, C2_3, C1_3}, // L01
{0, C3_4, C2_4, C1_4}, // L02
diff --git a/keyboards/xbows/woody/woody.c b/keyboards/xbows/woody/woody.c
index 9821f5f655..1027e3ca37 100644
--- a/keyboards/xbows/woody/woody.c
+++ b/keyboards/xbows/woody/woody.c
@@ -1,6 +1,6 @@
#include "woody.h"
#ifdef RGB_MATRIX_ENABLE
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
{0, C8_8, C7_8, C6_8}, // LA17
{0, C9_8, C7_7, C6_7}, // LA16
diff --git a/keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c b/keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c
index c305ecae14..c6ddef0931 100644
--- a/keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c
+++ b/keyboards/xelus/dawn60/rev1_qmk/rev1_qmk.c
@@ -25,7 +25,7 @@
#ifdef RGB_MATRIX_ENABLE
LED_TYPE rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/keyboards/xelus/pachi/rgb/rgb.c b/keyboards/xelus/pachi/rgb/rgb.c
index ea9812d6b1..6f44b13e12 100644
--- a/keyboards/xelus/pachi/rgb/rgb.c
+++ b/keyboards/xelus/pachi/rgb/rgb.c
@@ -24,7 +24,7 @@ void matrix_io_delay(void) { __asm__ volatile("nop\nnop\nnop\n"); }
#ifdef RGB_MATRIX_ENABLE
#include
#include "drivers/led/issi/is31fl3741.h"
-const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
+const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h
index 3a7a169682..a70d8e299f 100644
--- a/tmk_core/common/progmem.h
+++ b/tmk_core/common/progmem.h
@@ -5,6 +5,7 @@
#else
# include
# define PROGMEM
+# define __flash
# define PSTR(x) x
# define PGM_P const char*
# define memcpy_P(dest, src, n) memcpy(dest, src, n)
--
cgit v1.2.3
From 7ef4d0c8868dae2deb998f5aa29a5f3cb855dc91 Mon Sep 17 00:00:00 2001
From: Drashna Jaelre
Date: Fri, 13 Aug 2021 14:20:47 -0700
Subject: Fix pmw3360 code to only output debug info if mouse debugging is
enabled (#13993)
---
drivers/sensors/pmw3360.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
(limited to 'drivers')
diff --git a/drivers/sensors/pmw3360.c b/drivers/sensors/pmw3360.c
index 91ee87b957..13c5bdea26 100644
--- a/drivers/sensors/pmw3360.c
+++ b/drivers/sensors/pmw3360.c
@@ -213,12 +213,14 @@ report_pmw_t pmw_read_burst(void) {
spi_stop();
- print_byte(data.motion);
- print_byte(data.dx);
- print_byte(data.mdx);
- print_byte(data.dy);
- print_byte(data.mdy);
- dprintf("\n");
+ if (debug_mouse) {
+ print_byte(data.motion);
+ print_byte(data.dx);
+ print_byte(data.mdx);
+ print_byte(data.dy);
+ print_byte(data.mdy);
+ dprintf("\n");
+ }
data.isMotion = (data.motion & 0x80) != 0;
data.isOnSurface = (data.motion & 0x08) == 0;
--
cgit v1.2.3
From 1bb7af4d446174b7181c9bb22dbd14c93642ea10 Mon Sep 17 00:00:00 2001
From: Joel Challis
Date: Tue, 17 Aug 2021 23:43:09 +0100
Subject: Relocate platform specific drivers (#13894)
* Relocate platform specific drivers
* Move stm eeprom
* Tidy up slightly---
common.mk | 3 +
common_features.mk | 1 +
drivers/avr/analog.c | 138 ------
drivers/avr/analog.h | 53 --
drivers/avr/glcdfont.c | 23 -
drivers/avr/hd44780.c | 536 ---------------------
drivers/avr/hd44780.h | 348 -------------
drivers/avr/i2c_master.c | 241 ---------
drivers/avr/i2c_master.h | 43 --
drivers/avr/i2c_slave.c | 111 -----
drivers/avr/i2c_slave.h | 41 --
drivers/avr/serial.c | 529 --------------------
drivers/avr/spi_master.c | 180 -------
drivers/avr/spi_master.h | 59 ---
drivers/avr/ssd1306.c | 319 ------------
drivers/avr/ssd1306.h | 87 ----
drivers/avr/uart.c | 170 -------
drivers/avr/uart.h | 35 --
drivers/avr/ws2812.c | 176 -------
drivers/avr/ws2812_i2c.c | 27 --
drivers/chibios/analog.c | 321 ------------
drivers/chibios/analog.h | 41 --
drivers/chibios/i2c_master.c | 121 -----
drivers/chibios/i2c_master.h | 113 -----
drivers/chibios/serial.c | 278 -----------
drivers/chibios/serial_usart.c | 318 ------------
drivers/chibios/serial_usart.h | 116 -----
drivers/chibios/spi_master.c | 202 --------
drivers/chibios/spi_master.h | 93 ----
drivers/chibios/uart.c | 50 --
drivers/chibios/uart.h | 77 ---
drivers/chibios/usbpd_stm32g4.c | 76 ---
drivers/chibios/ws2812.c | 114 -----
drivers/chibios/ws2812_pwm.c | 311 ------------
drivers/chibios/ws2812_spi.c | 159 ------
drivers/eeprom/eeprom_stm32_L0_L1.c | 96 ----
drivers/eeprom/eeprom_stm32_L0_L1.h | 33 --
platforms/avr/drivers/analog.c | 138 ++++++
platforms/avr/drivers/analog.h | 53 ++
platforms/avr/drivers/glcdfont.c | 23 +
platforms/avr/drivers/hd44780.c | 536 +++++++++++++++++++++
platforms/avr/drivers/hd44780.h | 348 +++++++++++++
platforms/avr/drivers/i2c_master.c | 241 +++++++++
platforms/avr/drivers/i2c_master.h | 43 ++
platforms/avr/drivers/i2c_slave.c | 111 +++++
platforms/avr/drivers/i2c_slave.h | 41 ++
platforms/avr/drivers/serial.c | 529 ++++++++++++++++++++
platforms/avr/drivers/spi_master.c | 180 +++++++
platforms/avr/drivers/spi_master.h | 59 +++
platforms/avr/drivers/ssd1306.c | 319 ++++++++++++
platforms/avr/drivers/ssd1306.h | 87 ++++
platforms/avr/drivers/uart.c | 170 +++++++
platforms/avr/drivers/uart.h | 35 ++
platforms/avr/drivers/ws2812.c | 176 +++++++
platforms/avr/drivers/ws2812_i2c.c | 27 ++
platforms/chibios/drivers/analog.c | 321 ++++++++++++
platforms/chibios/drivers/analog.h | 41 ++
.../chibios/drivers/eeprom/eeprom_stm32_L0_L1.c | 96 ++++
.../chibios/drivers/eeprom/eeprom_stm32_L0_L1.h | 33 ++
platforms/chibios/drivers/i2c_master.c | 121 +++++
platforms/chibios/drivers/i2c_master.h | 113 +++++
platforms/chibios/drivers/serial.c | 278 +++++++++++
platforms/chibios/drivers/serial_usart.c | 318 ++++++++++++
platforms/chibios/drivers/serial_usart.h | 116 +++++
platforms/chibios/drivers/spi_master.c | 202 ++++++++
platforms/chibios/drivers/spi_master.h | 93 ++++
platforms/chibios/drivers/uart.c | 50 ++
platforms/chibios/drivers/uart.h | 77 +++
platforms/chibios/drivers/usbpd_stm32g4.c | 76 +++
platforms/chibios/drivers/ws2812.c | 114 +++++
platforms/chibios/drivers/ws2812_pwm.c | 311 ++++++++++++
platforms/chibios/drivers/ws2812_spi.c | 159 ++++++
tmk_core/avr.mk | 2 -
tmk_core/chibios.mk | 2 -
tmk_core/common.mk | 1 +
tmk_core/protocol/lufa.mk | 1 -
76 files changed, 5640 insertions(+), 5640 deletions(-)
delete mode 100644 drivers/avr/analog.c
delete mode 100644 drivers/avr/analog.h
delete mode 100644 drivers/avr/glcdfont.c
delete mode 100644 drivers/avr/hd44780.c
delete mode 100644 drivers/avr/hd44780.h
delete mode 100644 drivers/avr/i2c_master.c
delete mode 100644 drivers/avr/i2c_master.h
delete mode 100644 drivers/avr/i2c_slave.c
delete mode 100644 drivers/avr/i2c_slave.h
delete mode 100644 drivers/avr/serial.c
delete mode 100644 drivers/avr/spi_master.c
delete mode 100644 drivers/avr/spi_master.h
delete mode 100644 drivers/avr/ssd1306.c
delete mode 100644 drivers/avr/ssd1306.h
delete mode 100644 drivers/avr/uart.c
delete mode 100644 drivers/avr/uart.h
delete mode 100644 drivers/avr/ws2812.c
delete mode 100644 drivers/avr/ws2812_i2c.c
delete mode 100644 drivers/chibios/analog.c
delete mode 100644 drivers/chibios/analog.h
delete mode 100644 drivers/chibios/i2c_master.c
delete mode 100644 drivers/chibios/i2c_master.h
delete mode 100644 drivers/chibios/serial.c
delete mode 100644 drivers/chibios/serial_usart.c
delete mode 100644 drivers/chibios/serial_usart.h
delete mode 100644 drivers/chibios/spi_master.c
delete mode 100644 drivers/chibios/spi_master.h
delete mode 100644 drivers/chibios/uart.c
delete mode 100644 drivers/chibios/uart.h
delete mode 100644 drivers/chibios/usbpd_stm32g4.c
delete mode 100644 drivers/chibios/ws2812.c
delete mode 100644 drivers/chibios/ws2812_pwm.c
delete mode 100644 drivers/chibios/ws2812_spi.c
delete mode 100644 drivers/eeprom/eeprom_stm32_L0_L1.c
delete mode 100644 drivers/eeprom/eeprom_stm32_L0_L1.h
create mode 100644 platforms/avr/drivers/analog.c
create mode 100644 platforms/avr/drivers/analog.h
create mode 100644 platforms/avr/drivers/glcdfont.c
create mode 100644 platforms/avr/drivers/hd44780.c
create mode 100644 platforms/avr/drivers/hd44780.h
create mode 100644 platforms/avr/drivers/i2c_master.c
create mode 100644 platforms/avr/drivers/i2c_master.h
create mode 100644 platforms/avr/drivers/i2c_slave.c
create mode 100644 platforms/avr/drivers/i2c_slave.h
create mode 100644 platforms/avr/drivers/serial.c
create mode 100644 platforms/avr/drivers/spi_master.c
create mode 100644 platforms/avr/drivers/spi_master.h
create mode 100644 platforms/avr/drivers/ssd1306.c
create mode 100644 platforms/avr/drivers/ssd1306.h
create mode 100644 platforms/avr/drivers/uart.c
create mode 100644 platforms/avr/drivers/uart.h
create mode 100644 platforms/avr/drivers/ws2812.c
create mode 100644 platforms/avr/drivers/ws2812_i2c.c
create mode 100644 platforms/chibios/drivers/analog.c
create mode 100644 platforms/chibios/drivers/analog.h
create mode 100644 platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c
create mode 100644 platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.h
create mode 100644 platforms/chibios/drivers/i2c_master.c
create mode 100644 platforms/chibios/drivers/i2c_master.h
create mode 100644 platforms/chibios/drivers/serial.c
create mode 100644 platforms/chibios/drivers/serial_usart.c
create mode 100644 platforms/chibios/drivers/serial_usart.h
create mode 100644 platforms/chibios/drivers/spi_master.c
create mode 100644 platforms/chibios/drivers/spi_master.h
create mode 100644 platforms/chibios/drivers/uart.c
create mode 100644 platforms/chibios/drivers/uart.h
create mode 100644 platforms/chibios/drivers/usbpd_stm32g4.c
create mode 100644 platforms/chibios/drivers/ws2812.c
create mode 100644 platforms/chibios/drivers/ws2812_pwm.c
create mode 100644 platforms/chibios/drivers/ws2812_spi.c
(limited to 'drivers')
diff --git a/common.mk b/common.mk
index c13b5e2768..8acea39376 100644
--- a/common.mk
+++ b/common.mk
@@ -12,6 +12,9 @@ QUANTUM_PATH = $(QUANTUM_DIR)
DRIVER_DIR = drivers
DRIVER_PATH = $(DRIVER_DIR)
+PLATFORM_DIR = platforms
+PLATFORM_PATH = $(PLATFORM_DIR)
+
BUILD_DIR := .build
COMMON_VPATH := $(TOP_DIR)
diff --git a/common_features.mk b/common_features.mk
index 493aab6353..1eece0242e 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -178,6 +178,7 @@ else
else ifneq ($(filter $(MCU_SERIES),STM32L0xx STM32L1xx),)
OPT_DEFS += -DEEPROM_DRIVER
COMMON_VPATH += $(DRIVER_PATH)/eeprom
+ COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/eeprom
SRC += eeprom_driver.c eeprom_stm32_L0_L1.c
else
# This will effectively work the same as "transient" if not supported by the chip
diff --git a/drivers/avr/analog.c b/drivers/avr/analog.c
deleted file mode 100644
index 8d299ffdb9..0000000000
--- a/drivers/avr/analog.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/* Copyright 2015 Jack Humbert
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include
-#include
-#include
-#include "analog.h"
-
-static uint8_t aref = ADC_REF_POWER;
-
-void analogReference(uint8_t mode) { aref = mode & (_BV(REFS1) | _BV(REFS0)); }
-
-// Arduino compatible pin input
-int16_t analogRead(uint8_t pin) {
-#if defined(__AVR_ATmega32U4__)
- // clang-format off
- static const uint8_t PROGMEM pin_to_mux[] = {
- //A0 A1 A2 A3 A4 A5
- //F7 F6 F5 F4 F1 F0
- 0x07, 0x06, 0x05, 0x04, 0x01, 0x00,
- //A6 A7 A8 A9 A10 A11
- //D4 D7 B4 B5 B6 D6
- 0x20, 0x22, 0x23, 0x24, 0x25, 0x21
- };
- // clang-format on
- if (pin >= 12) return 0;
- return adc_read(pgm_read_byte(pin_to_mux + pin));
-#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
- if (pin >= 8) return 0;
- return adc_read(pin);
-#else
- return 0;
-#endif
-}
-
-int16_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); }
-
-uint8_t pinToMux(pin_t pin) {
- switch (pin) {
- // clang-format off
-#if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
- case F0: return 0; // ADC0
- case F1: return _BV(MUX0); // ADC1
- case F2: return _BV(MUX1); // ADC2
- case F3: return _BV(MUX1) | _BV(MUX0); // ADC3
- case F4: return _BV(MUX2); // ADC4
- case F5: return _BV(MUX2) | _BV(MUX0); // ADC5
- case F6: return _BV(MUX2) | _BV(MUX1); // ADC6
- case F7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
- default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
-#elif defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
- case F0: return 0; // ADC0
- case F1: return _BV(MUX0); // ADC1
- case F4: return _BV(MUX2); // ADC4
- case F5: return _BV(MUX2) | _BV(MUX0); // ADC5
- case F6: return _BV(MUX2) | _BV(MUX1); // ADC6
- case F7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
- case D4: return _BV(MUX5); // ADC8
- case D6: return _BV(MUX5) | _BV(MUX0); // ADC9
- case D7: return _BV(MUX5) | _BV(MUX1); // ADC10
- case B4: return _BV(MUX5) | _BV(MUX1) | _BV(MUX0); // ADC11
- case B5: return _BV(MUX5) | _BV(MUX2); // ADC12
- case B6: return _BV(MUX5) | _BV(MUX2) | _BV(MUX0); // ADC13
- default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
-#elif defined(__AVR_ATmega32A__)
- case A0: return 0; // ADC0
- case A1: return _BV(MUX0); // ADC1
- case A2: return _BV(MUX1); // ADC2
- case A3: return _BV(MUX1) | _BV(MUX0); // ADC3
- case A4: return _BV(MUX2); // ADC4
- case A5: return _BV(MUX2) | _BV(MUX0); // ADC5
- case A6: return _BV(MUX2) | _BV(MUX1); // ADC6
- case A7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
- default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
-#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
- case C0: return 0; // ADC0
- case C1: return _BV(MUX0); // ADC1
- case C2: return _BV(MUX1); // ADC2
- case C3: return _BV(MUX1) | _BV(MUX0); // ADC3
- case C4: return _BV(MUX2); // ADC4
- case C5: return _BV(MUX2) | _BV(MUX0); // ADC5
- // ADC7:6 not present in DIP package and not shared by GPIO pins
- default: return _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
-#endif
- // clang-format on
- }
- return 0;
-}
-
-int16_t adc_read(uint8_t mux) {
- uint16_t low;
-
- // Enable ADC and configure prescaler
- ADCSRA = _BV(ADEN) | ADC_PRESCALER;
-
-#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
- // High speed mode and ADC8-13
- ADCSRB = _BV(ADHSM) | (mux & _BV(MUX5));
-#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
- // High speed mode only
- ADCSRB = _BV(ADHSM);
-#endif
-
- // Configure mux input
-#if defined(MUX4)
- ADMUX = aref | (mux & (_BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0)));
-#else
- ADMUX = aref | (mux & (_BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0)));
-#endif
-
- // Start the conversion
- ADCSRA |= _BV(ADSC);
- // Wait for result
- while (ADCSRA & _BV(ADSC))
- ;
- // Must read LSB first
- low = ADCL;
- // Must read MSB only once!
- low |= (ADCH << 8);
-
- // turn off the ADC
- ADCSRA &= ~(1 << ADEN);
-
- return low;
-}
diff --git a/drivers/avr/analog.h b/drivers/avr/analog.h
deleted file mode 100644
index 058882450d..0000000000
--- a/drivers/avr/analog.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Copyright 2015 Jack Humbert
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include "quantum.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-void analogReference(uint8_t mode);
-int16_t analogRead(uint8_t pin);
-
-int16_t analogReadPin(pin_t pin);
-uint8_t pinToMux(pin_t pin);
-
-int16_t adc_read(uint8_t mux);
-#ifdef __cplusplus
-}
-#endif
-
-#define ADC_REF_EXTERNAL 0 // AREF, Internal Vref turned off
-#define ADC_REF_POWER _BV(REFS0) // AVCC with external capacitor on AREF pin
-#define ADC_REF_INTERNAL (_BV(REFS1) | _BV(REFS0)) // Internal 2.56V Voltage Reference with external capacitor on AREF pin (1.1V for 328P)
-
-// These prescaler values are for high speed mode, ADHSM = 1
-#if F_CPU == 16000000L || F_CPU == 12000000L
-# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS1)) // /64
-#elif F_CPU == 8000000L
-# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS0)) // /32
-#elif F_CPU == 4000000L
-# define ADC_PRESCALER (_BV(ADPS2)) // /16
-#elif F_CPU == 2000000L
-# define ADC_PRESCALER (_BV(ADPS1) | _BV(ADPS0)) // /8
-#elif F_CPU == 1000000L
-# define ADC_PRESCALER _BV(ADPS1) // /4
-#else
-# define ADC_PRESCALER _BV(ADPS0) // /2
-#endif
diff --git a/drivers/avr/glcdfont.c b/drivers/avr/glcdfont.c
deleted file mode 100644
index 5e763b054f..0000000000
--- a/drivers/avr/glcdfont.c
+++ /dev/null
@@ -1,23 +0,0 @@
-// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
-// See gfxfont.h for newer custom bitmap font info.
-
-#include "progmem.h"
-
-// Standard ASCII 5x7 font
-
-static const unsigned char font[] PROGMEM = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x18, 0x3C, 0x18, 0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x18, 0x24, 0x18, 0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x26, 0x29, 0x79, 0x29, 0x26, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x60, 0x60, 0x60, 0x60, 0x60, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x10, 0x20, 0x7E, 0x20, 0x10, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
- 0x30, 0x38, 0x3E, 0x38, 0x30, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x23, 0x13, 0x08, 0x64, 0x62, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x80, 0x70, 0x30, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x60, 0x60, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x72, 0x49, 0x49, 0x49, 0x46, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x27, 0x45, 0x45, 0x45, 0x39, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x41, 0x21, 0x11, 0x09, 0x07, 0x36, 0x49, 0x49, 0x49, 0x36, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00,
- 0x00, 0x08, 0x14, 0x22, 0x41, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x41, 0x22, 0x14, 0x08, 0x02, 0x01, 0x59, 0x09, 0x06, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x26, 0x49, 0x49, 0x49, 0x32, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x63, 0x14, 0x08, 0x14, 0x63, 0x03, 0x04, 0x78, 0x04, 0x03,
- 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x04, 0x02, 0x01, 0x02, 0x04, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x03, 0x07, 0x08, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x38, 0x44, 0x44, 0x44, 0x28, 0x38, 0x44, 0x44, 0x28, 0x7F, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x38, 0x44, 0x44, 0x44, 0x38, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x48, 0x54, 0x54, 0x54, 0x24, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x3C, 0x40, 0x30, 0x40, 0x3C,
- 0x44, 0x28, 0x10, 0x28, 0x44, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x1E, 0xA1, 0xA1, 0x61, 0x12, 0x3A, 0x40, 0x40, 0x20, 0x7A, 0x38, 0x54, 0x54, 0x55, 0x59, 0x21, 0x55, 0x55, 0x79, 0x41, 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
- 0x21, 0x55, 0x54, 0x78, 0x40, 0x20, 0x54, 0x55, 0x79, 0x40, 0x0C, 0x1E, 0x52, 0x72, 0x12, 0x39, 0x55, 0x55, 0x55, 0x59, 0x39, 0x54, 0x54, 0x54, 0x59, 0x39, 0x55, 0x54, 0x54, 0x58, 0x00, 0x00, 0x45, 0x7C, 0x41, 0x00, 0x02, 0x45, 0x7D, 0x42, 0x00, 0x01, 0x45, 0x7C, 0x40, 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
- 0xF0, 0x28, 0x25, 0x28, 0xF0, 0x7C, 0x54, 0x55, 0x45, 0x00, 0x20, 0x54, 0x54, 0x7C, 0x54, 0x7C, 0x0A, 0x09, 0x7F, 0x49, 0x32, 0x49, 0x49, 0x49, 0x32, 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
- 0x32, 0x4A, 0x48, 0x48, 0x30, 0x3A, 0x41, 0x41, 0x21, 0x7A, 0x3A, 0x42, 0x40, 0x20, 0x78, 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
- 0x3D, 0x40, 0x40, 0x40, 0x3D, 0x3C, 0x24, 0xFF, 0x24, 0x24, 0x48, 0x7E, 0x49, 0x43, 0x66, 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 0xFF, 0x09, 0x29, 0xF6, 0x20, 0xC0, 0x88, 0x7E, 0x09, 0x03, 0x20, 0x54, 0x54, 0x79, 0x41, 0x00, 0x00, 0x44, 0x7D, 0x41, 0x30, 0x48, 0x48, 0x4A, 0x32, 0x38, 0x40, 0x40, 0x22, 0x7A, 0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x26, 0x29, 0x29, 0x2F, 0x28, 0x26, 0x29, 0x29, 0x29, 0x26, 0x30, 0x48, 0x4D, 0x40, 0x20, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x22, 0x14, 0x2A, 0x14, 0x08, 0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
- 0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
- 0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
- 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x14, 0x14, 0x14, 0xFF, 0x00, 0x10, 0x10, 0xFF, 0x00, 0xFF, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x14, 0x14, 0x14, 0xFC, 0x00, 0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x14, 0x14, 0xF4, 0x04, 0xFC, 0x14, 0x14, 0x17, 0x10, 0x1F, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x14, 0x14, 0x14, 0x1F, 0x00, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x14, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x1F, 0x10, 0x17, 0x00, 0x00, 0xFC, 0x04, 0xF4, 0x14, 0x14, 0x17, 0x10, 0x17, 0x14, 0x14, 0xF4, 0x04, 0xF4, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0xF7, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x17, 0x14, 0x10, 0x10, 0x1F, 0x10, 0x1F,
- 0x14, 0x14, 0x14, 0xF4, 0x14, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x1F, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x00, 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0xFF, 0x10, 0xFF, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x38, 0x44, 0x44, 0x38, 0x44, 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
- 0x7E, 0x02, 0x02, 0x06, 0x06, 0x02, 0x7E, 0x02, 0x7E, 0x02, 0x63, 0x55, 0x49, 0x41, 0x63, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x40, 0x7E, 0x20, 0x1E, 0x20, 0x06, 0x02, 0x7E, 0x02, 0x02, 0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x4C, 0x72, 0x01, 0x72, 0x4C, 0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x30, 0x48, 0x78, 0x48, 0x30, 0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x3E, 0x49, 0x49, 0x49, 0x00, 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x44, 0x44, 0x5F, 0x44, 0x44, 0x40, 0x51, 0x4A, 0x44, 0x40, 0x40, 0x44, 0x4A, 0x51, 0x40, 0x00, 0x00, 0xFF, 0x01, 0x03, 0xE0, 0x80, 0xFF, 0x00, 0x00, 0x08, 0x08, 0x6B, 0x6B, 0x08, 0x36, 0x12, 0x36, 0x24, 0x36, 0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x30, 0x40, 0xFF, 0x01, 0x01, 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
-};
diff --git a/drivers/avr/hd44780.c b/drivers/avr/hd44780.c
deleted file mode 100644
index f71069dece..0000000000
--- a/drivers/avr/hd44780.c
+++ /dev/null
@@ -1,536 +0,0 @@
-/****************************************************************************
- Title: HD44780U LCD library
- Author: Peter Fleury http://tinyurl.com/peterfleury
- License: GNU General Public License Version 3
- File: $Id: lcd.c,v 1.15.2.2 2015/01/17 12:16:05 peter Exp $
- Software: AVR-GCC 3.3
- Target: any AVR device, memory mapped mode only for AT90S4414/8515/Mega
-
- DESCRIPTION
- Basic routines for interfacing a HD44780U-based text lcd display
-
- Originally based on Volker Oth's lcd library,
- changed lcd_init(), added additional constants for lcd_command(),
- added 4-bit I/O mode, improved and optimized code.
-
- Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in
- 4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported.
-
- Memory mapped mode compatible with Kanda STK200, but supports also
- generation of R/W signal through A8 address line.
-
- USAGE
- See the C include lcd.h file for a description of each function
-
-*****************************************************************************/
-#include
-#include
-#include
-#include
-#include "hd44780.h"
-
-/*
-** constants/macros
-*/
-#define DDR(x) (*(&x - 1)) /* address of data direction register of port x */
-#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
-/* on ATmega64/128 PINF is on port 0x00 and not 0x60 */
-# define PIN(x) (&PORTF == &(x) ? _SFR_IO8(0x00) : (*(&x - 2)))
-#else
-# define PIN(x) (*(&x - 2)) /* address of input register of port x */
-#endif
-
-#if LCD_IO_MODE
-# define lcd_e_delay() _delay_us(LCD_DELAY_ENABLE_PULSE)
-# define lcd_e_high() LCD_E_PORT |= _BV(LCD_E_PIN);
-# define lcd_e_low() LCD_E_PORT &= ~_BV(LCD_E_PIN);
-# define lcd_e_toggle() toggle_e()
-# define lcd_rw_high() LCD_RW_PORT |= _BV(LCD_RW_PIN)
-# define lcd_rw_low() LCD_RW_PORT &= ~_BV(LCD_RW_PIN)
-# define lcd_rs_high() LCD_RS_PORT |= _BV(LCD_RS_PIN)
-# define lcd_rs_low() LCD_RS_PORT &= ~_BV(LCD_RS_PIN)
-#endif
-
-#if LCD_IO_MODE
-# if LCD_LINES == 1
-# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_1LINE
-# else
-# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_2LINES
-# endif
-#else
-# if LCD_LINES == 1
-# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_1LINE
-# else
-# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_2LINES
-# endif
-#endif
-
-#if LCD_CONTROLLER_KS0073
-# if LCD_LINES == 4
-
-# define KS0073_EXTENDED_FUNCTION_REGISTER_ON 0x2C /* |0|010|1100 4-bit mode, extension-bit RE = 1 */
-# define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x28 /* |0|010|1000 4-bit mode, extension-bit RE = 0 */
-# define KS0073_4LINES_MODE 0x09 /* |0|000|1001 4 lines mode */
-
-# endif
-#endif
-
-/*
-** function prototypes
-*/
-#if LCD_IO_MODE
-static void toggle_e(void);
-#endif
-
-/*
-** local functions
-*/
-
-/*************************************************************************
-delay for a minimum of microseconds
-the number of loops is calculated at compile-time from MCU clock frequency
-*************************************************************************/
-#define delay(us) _delay_us(us)
-
-#if LCD_IO_MODE
-/* toggle Enable Pin to initiate write */
-static void toggle_e(void) {
- lcd_e_high();
- lcd_e_delay();
- lcd_e_low();
-}
-#endif
-
-/*************************************************************************
-Low-level function to write byte to LCD controller
-Input: data byte to write to LCD
- rs 1: write data
- 0: write instruction
-Returns: none
-*************************************************************************/
-#if LCD_IO_MODE
-static void lcd_write(uint8_t data, uint8_t rs) {
- unsigned char dataBits;
-
- if (rs) { /* write data (RS=1, RW=0) */
- lcd_rs_high();
- } else { /* write instruction (RS=0, RW=0) */
- lcd_rs_low();
- }
- lcd_rw_low(); /* RW=0 write mode */
-
- if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
- /* configure data pins as output */
- DDR(LCD_DATA0_PORT) |= 0x0F;
-
- /* output high nibble first */
- dataBits = LCD_DATA0_PORT & 0xF0;
- LCD_DATA0_PORT = dataBits | ((data >> 4) & 0x0F);
- lcd_e_toggle();
-
- /* output low nibble */
- LCD_DATA0_PORT = dataBits | (data & 0x0F);
- lcd_e_toggle();
-
- /* all data pins high (inactive) */
- LCD_DATA0_PORT = dataBits | 0x0F;
- } else {
- /* configure data pins as output */
- DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
- DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
- DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
- DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
-
- /* output high nibble first */
- LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
- LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
- LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
- LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
- if (data & 0x80) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
- if (data & 0x40) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
- if (data & 0x20) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
- if (data & 0x10) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
- lcd_e_toggle();
-
- /* output low nibble */
- LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
- LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
- LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
- LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
- if (data & 0x08) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
- if (data & 0x04) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
- if (data & 0x02) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
- if (data & 0x01) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
- lcd_e_toggle();
-
- /* all data pins high (inactive) */
- LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
- LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
- LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
- LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
- }
-}
-#else
-# define lcd_write(d, rs) \
- if (rs) \
- *(volatile uint8_t *)(LCD_IO_DATA) = d; \
- else \
- *(volatile uint8_t *)(LCD_IO_FUNCTION) = d;
-/* rs==0 -> write instruction to LCD_IO_FUNCTION */
-/* rs==1 -> write data to LCD_IO_DATA */
-#endif
-
-/*************************************************************************
-Low-level function to read byte from LCD controller
-Input: rs 1: read data
- 0: read busy flag / address counter
-Returns: byte read from LCD controller
-*************************************************************************/
-#if LCD_IO_MODE
-static uint8_t lcd_read(uint8_t rs) {
- uint8_t data;
-
- if (rs)
- lcd_rs_high(); /* RS=1: read data */
- else
- lcd_rs_low(); /* RS=0: read busy flag */
- lcd_rw_high(); /* RW=1 read mode */
-
- if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
- DDR(LCD_DATA0_PORT) &= 0xF0; /* configure data pins as input */
-
- lcd_e_high();
- lcd_e_delay();
- data = PIN(LCD_DATA0_PORT) << 4; /* read high nibble first */
- lcd_e_low();
-
- lcd_e_delay(); /* Enable 500ns low */
-
- lcd_e_high();
- lcd_e_delay();
- data |= PIN(LCD_DATA0_PORT) & 0x0F; /* read low nibble */
- lcd_e_low();
- } else {
- /* configure data pins as input */
- DDR(LCD_DATA0_PORT) &= ~_BV(LCD_DATA0_PIN);
- DDR(LCD_DATA1_PORT) &= ~_BV(LCD_DATA1_PIN);
- DDR(LCD_DATA2_PORT) &= ~_BV(LCD_DATA2_PIN);
- DDR(LCD_DATA3_PORT) &= ~_BV(LCD_DATA3_PIN);
-
- /* read high nibble first */
- lcd_e_high();
- lcd_e_delay();
- data = 0;
- if (PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN)) data |= 0x10;
- if (PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN)) data |= 0x20;
- if (PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN)) data |= 0x40;
- if (PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN)) data |= 0x80;
- lcd_e_low();
-
- lcd_e_delay(); /* Enable 500ns low */
-
- /* read low nibble */
- lcd_e_high();
- lcd_e_delay();
- if (PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN)) data |= 0x01;
- if (PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN)) data |= 0x02;
- if (PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN)) data |= 0x04;
- if (PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN)) data |= 0x08;
- lcd_e_low();
- }
- return data;
-}
-#else
-# define lcd_read(rs) (rs) ? *(volatile uint8_t *)(LCD_IO_DATA + LCD_IO_READ) : *(volatile uint8_t *)(LCD_IO_FUNCTION + LCD_IO_READ)
-/* rs==0 -> read instruction from LCD_IO_FUNCTION */
-/* rs==1 -> read data from LCD_IO_DATA */
-#endif
-
-/*************************************************************************
-loops while lcd is busy, returns address counter
-*************************************************************************/
-static uint8_t lcd_waitbusy(void)
-
-{
- register uint8_t c;
-
- /* wait until busy flag is cleared */
- while ((c = lcd_read(0)) & (1 << LCD_BUSY)) {
- }
-
- /* the address counter is updated 4us after the busy flag is cleared */
- delay(LCD_DELAY_BUSY_FLAG);
-
- /* now read the address counter */
- return (lcd_read(0)); // return address counter
-
-} /* lcd_waitbusy */
-
-/*************************************************************************
-Move cursor to the start of next line or to the first line if the cursor
-is already on the last line.
-*************************************************************************/
-static inline void lcd_newline(uint8_t pos) {
- register uint8_t addressCounter;
-
-#if LCD_LINES == 1
- addressCounter = 0;
-#endif
-#if LCD_LINES == 2
- if (pos < (LCD_START_LINE2))
- addressCounter = LCD_START_LINE2;
- else
- addressCounter = LCD_START_LINE1;
-#endif
-#if LCD_LINES == 4
-# if KS0073_4LINES_MODE
- if (pos < LCD_START_LINE2)
- addressCounter = LCD_START_LINE2;
- else if ((pos >= LCD_START_LINE2) && (pos < LCD_START_LINE3))
- addressCounter = LCD_START_LINE3;
- else if ((pos >= LCD_START_LINE3) && (pos < LCD_START_LINE4))
- addressCounter = LCD_START_LINE4;
- else
- addressCounter = LCD_START_LINE1;
-# else
- if (pos < LCD_START_LINE3)
- addressCounter = LCD_START_LINE2;
- else if ((pos >= LCD_START_LINE2) && (pos < LCD_START_LINE4))
- addressCounter = LCD_START_LINE3;
- else if ((pos >= LCD_START_LINE3) && (pos < LCD_START_LINE2))
- addressCounter = LCD_START_LINE4;
- else
- addressCounter = LCD_START_LINE1;
-# endif
-#endif
- lcd_command((1 << LCD_DDRAM) + addressCounter);
-
-} /* lcd_newline */
-
-/*
-** PUBLIC FUNCTIONS
-*/
-
-/*************************************************************************
-Send LCD controller instruction command
-Input: instruction to send to LCD controller, see HD44780 data sheet
-Returns: none
-*************************************************************************/
-void lcd_command(uint8_t cmd) {
- lcd_waitbusy();
- lcd_write(cmd, 0);
-}
-
-/*************************************************************************
-Send data byte to LCD controller
-Input: data to send to LCD controller, see HD44780 data sheet
-Returns: none
-*************************************************************************/
-void lcd_data(uint8_t data) {
- lcd_waitbusy();
- lcd_write(data, 1);
-}
-
-/*************************************************************************
-Set cursor to specified position
-Input: x horizontal position (0: left most position)
- y vertical position (0: first line)
-Returns: none
-*************************************************************************/
-void lcd_gotoxy(uint8_t x, uint8_t y) {
-#if LCD_LINES == 1
- lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
-#endif
-#if LCD_LINES == 2
- if (y == 0)
- lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
- else
- lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x);
-#endif
-#if LCD_LINES == 4
- if (y == 0)
- lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
- else if (y == 1)
- lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x);
- else if (y == 2)
- lcd_command((1 << LCD_DDRAM) + LCD_START_LINE3 + x);
- else /* y==3 */
- lcd_command((1 << LCD_DDRAM) + LCD_START_LINE4 + x);
-#endif
-
-} /* lcd_gotoxy */
-
-/*************************************************************************
-*************************************************************************/
-int lcd_getxy(void) { return lcd_waitbusy(); }
-
-/*************************************************************************
-Clear display and set cursor to home position
-*************************************************************************/
-void lcd_clrscr(void) { lcd_command(1 << LCD_CLR); }
-
-/*************************************************************************
-Set cursor to home position
-*************************************************************************/
-void lcd_home(void) { lcd_command(1 << LCD_HOME); }
-
-/*************************************************************************
-Display character at current cursor position
-Input: character to be displayed
-Returns: none
-*************************************************************************/
-void lcd_putc(char c) {
- uint8_t pos;
-
- pos = lcd_waitbusy(); // read busy-flag and address counter
- if (c == '\n') {
- lcd_newline(pos);
- } else {
-#if LCD_WRAP_LINES == 1
-# if LCD_LINES == 1
- if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
- lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
- }
-# elif LCD_LINES == 2
- if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
- lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2, 0);
- } else if (pos == LCD_START_LINE2 + LCD_DISP_LENGTH) {
- lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
- }
-# elif LCD_LINES == 4
- if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
- lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2, 0);
- } else if (pos == LCD_START_LINE2 + LCD_DISP_LENGTH) {
- lcd_write((1 << LCD_DDRAM) + LCD_START_LINE3, 0);
- } else if (pos == LCD_START_LINE3 + LCD_DISP_LENGTH) {
- lcd_write((1 << LCD_DDRAM) + LCD_START_LINE4, 0);
- } else if (pos == LCD_START_LINE4 + LCD_DISP_LENGTH) {
- lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
- }
-# endif
- lcd_waitbusy();
-#endif
- lcd_write(c, 1);
- }
-
-} /* lcd_putc */
-
-/*************************************************************************
-Display string without auto linefeed
-Input: string to be displayed
-Returns: none
-*************************************************************************/
-void lcd_puts(const char *s)
-/* print string on lcd (no auto linefeed) */
-{
- register char c;
-
- while ((c = *s++)) {
- lcd_putc(c);
- }
-
-} /* lcd_puts */
-
-/*************************************************************************
-Display string from program memory without auto linefeed
-Input: string from program memory be be displayed
-Returns: none
-*************************************************************************/
-void lcd_puts_p(const char *progmem_s)
-/* print string from program memory on lcd (no auto linefeed) */
-{
- register char c;
-
- while ((c = pgm_read_byte(progmem_s++))) {
- lcd_putc(c);
- }
-
-} /* lcd_puts_p */
-
-/*************************************************************************
-Initialize display and select type of cursor
-Input: dispAttr LCD_DISP_OFF display off
- LCD_DISP_ON display on, cursor off
- LCD_DISP_ON_CURSOR display on, cursor on
- LCD_DISP_CURSOR_BLINK display on, cursor on flashing
-Returns: none
-*************************************************************************/
-void lcd_init(uint8_t dispAttr) {
-#if LCD_IO_MODE
- /*
- * Initialize LCD to 4 bit I/O mode
- */
-
- if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (&LCD_RS_PORT == &LCD_DATA0_PORT) && (&LCD_RW_PORT == &LCD_DATA0_PORT) && (&LCD_E_PORT == &LCD_DATA0_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) && (LCD_RS_PIN == 4) && (LCD_RW_PIN == 5) && (LCD_E_PIN == 6)) {
- /* configure all port bits as output (all LCD lines on same port) */
- DDR(LCD_DATA0_PORT) |= 0x7F;
- } else if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
- /* configure all port bits as output (all LCD data lines on same port, but control lines on different ports) */
- DDR(LCD_DATA0_PORT) |= 0x0F;
- DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN);
- DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN);
- DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
- } else {
- /* configure all port bits as output (LCD data and control lines on different ports */
- DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN);
- DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN);
- DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
- DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
- DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
- DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
- DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
- }
- delay(LCD_DELAY_BOOTUP); /* wait 16ms or more after power-on */
-
- /* initial write to lcd is 8bit */
- LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); // LCD_FUNCTION>>4;
- LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); // LCD_FUNCTION_8BIT>>4;
- lcd_e_toggle();
- delay(LCD_DELAY_INIT); /* delay, busy flag can't be checked here */
-
- /* repeat last command */
- lcd_e_toggle();
- delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */
-
- /* repeat last command a third time */
- lcd_e_toggle();
- delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */
-
- /* now configure for 4bit mode */
- LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); // LCD_FUNCTION_4BIT_1LINE>>4
- lcd_e_toggle();
- delay(LCD_DELAY_INIT_4BIT); /* some displays need this additional delay */
-
- /* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */
-#else
- /*
- * Initialize LCD to 8 bit memory mapped mode
- */
-
- /* enable external SRAM (memory mapped lcd) and one wait state */
- MCUCR = _BV(SRE) | _BV(SRW);
-
- /* reset LCD */
- delay(LCD_DELAY_BOOTUP); /* wait 16ms after power-on */
- lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
- delay(LCD_DELAY_INIT); /* wait 5ms */
- lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
- delay(LCD_DELAY_INIT_REP); /* wait 64us */
- lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
- delay(LCD_DELAY_INIT_REP); /* wait 64us */
-#endif
-
-#if KS0073_4LINES_MODE
- /* Display with KS0073 controller requires special commands for enabling 4 line mode */
- lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_ON);
- lcd_command(KS0073_4LINES_MODE);
- lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF);
-#else
- lcd_command(LCD_FUNCTION_DEFAULT); /* function set: display lines */
-#endif
- lcd_command(LCD_DISP_OFF); /* display off */
- lcd_clrscr(); /* display clear */
- lcd_command(LCD_MODE_DEFAULT); /* set entry mode */
- lcd_command(dispAttr); /* display/cursor control */
-
-} /* lcd_init */
diff --git a/drivers/avr/hd44780.h b/drivers/avr/hd44780.h
deleted file mode 100644
index 08e60f8a44..0000000000
--- a/drivers/avr/hd44780.h
+++ /dev/null
@@ -1,348 +0,0 @@
-/*************************************************************************
- Title : C include file for the HD44780U LCD library (lcd.c)
- Author: Peter Fleury http://tinyurl.com/peterfleury
- License: GNU General Public License Version 3
- File: $Id: lcd.h,v 1.14.2.4 2015/01/20 17:16:07 peter Exp $
- Software: AVR-GCC 4.x
- Hardware: any AVR device, memory mapped mode only for AVR with
- memory mapped interface (AT90S8515/ATmega8515/ATmega128)
-***************************************************************************/
-
-/**
- @mainpage
- Collection of libraries for AVR-GCC
- @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury
- @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
-
- @file
- @defgroup pfleury_lcd LCD library
- @code #include @endcode
-
- @brief Basic routines for interfacing a HD44780U-based character LCD display
-
- LCD character displays can be found in many devices, like espresso machines, laser printers.
- The Hitachi HD44780 controller and its compatible controllers like Samsung KS0066U have become an industry standard for these types of displays.
-
- This library allows easy interfacing with a HD44780 compatible display and can be
- operated in memory mapped mode (LCD_IO_MODE defined as 0 in the include file lcd.h.) or in
- 4-bit IO port mode (LCD_IO_MODE defined as 1). 8-bit IO port mode is not supported.
-
- Memory mapped mode is compatible with old Kanda STK200 starter kit, but also supports
- generation of R/W signal through A8 address line.
-
- @see The chapter Interfacing a HD44780 Based LCD to an AVR
- on my home page, which shows example circuits how to connect an LCD to an AVR controller.
-
- @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury
-
- @version 2.0
-
- @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
-
-*/
-
-#pragma once
-
-#include
-#include
-
-#if (__GNUC__ * 100 + __GNUC_MINOR__) < 405
-# error "This library requires AVR-GCC 4.5 or later, update to newer AVR-GCC compiler !"
-#endif
-
-/**@{*/
-
-/*
- * LCD and target specific definitions below can be defined in a separate include file with name lcd_definitions.h instead modifying this file
- * by adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile
- * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
- */
-#ifdef _LCD_DEFINITIONS_FILE
-# include "lcd_definitions.h"
-#endif
-
-/**
- * @name Definition for LCD controller type
- * Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller.
- */
-#ifndef LCD_CONTROLLER_KS0073
-# define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */
-#endif
-
-/**
- * @name Definitions for Display Size
- * Change these definitions to adapt setting to your display
- *
- * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
- * adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile.
- * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
- *
- */
-#ifndef LCD_LINES
-# define LCD_LINES 2 /**< number of visible lines of the display */
-#endif
-#ifndef LCD_DISP_LENGTH
-# define LCD_DISP_LENGTH 16 /**< visibles characters per line of the display */
-#endif
-#ifndef LCD_LINE_LENGTH
-# define LCD_LINE_LENGTH 0x40 /**< internal line length of the display */
-#endif
-#ifndef LCD_START_LINE1
-# define LCD_START_LINE1 0x00 /**< DDRAM address of first char of line 1 */
-#endif
-#ifndef LCD_START_LINE2
-# define LCD_START_LINE2 0x40 /**< DDRAM address of first char of line 2 */
-#endif
-#ifndef LCD_START_LINE3
-# define LCD_START_LINE3 0x14 /**< DDRAM address of first char of line 3 */
-#endif
-#ifndef LCD_START_LINE4
-# define LCD_START_LINE4 0x54 /**< DDRAM address of first char of line 4 */
-#endif
-#ifndef LCD_WRAP_LINES
-# define LCD_WRAP_LINES 0 /**< 0: no wrap, 1: wrap at end of visibile line */
-#endif
-
-/**
- * @name Definitions for 4-bit IO mode
- *
- * The four LCD data lines and the three control lines RS, RW, E can be on the
- * same port or on different ports.
- * Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on
- * different ports.
- *
- * Normally the four data lines should be mapped to bit 0..3 on one port, but it
- * is possible to connect these data lines in different order or even on different
- * ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions.
- *
- * Adjust these definitions to your target.\n
- * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
- * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile.
- * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
- *
- */
-#define LCD_IO_MODE 1 /**< 0: memory mapped mode, 1: IO port mode */
-
-#if LCD_IO_MODE
-
-# ifndef LCD_PORT
-# define LCD_PORT PORTA /**< port for the LCD lines */
-# endif
-# ifndef LCD_DATA0_PORT
-# define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */
-# endif
-# ifndef LCD_DATA1_PORT
-# define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */
-# endif
-# ifndef LCD_DATA2_PORT
-# define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */
-# endif
-# ifndef LCD_DATA3_PORT
-# define LCD_DATA3_PORT LCD_PORT /**< port for 4bit data bit 3 */
-# endif
-# ifndef LCD_DATA0_PIN
-# define LCD_DATA0_PIN 4 /**< pin for 4bit data bit 0 */
-# endif
-# ifndef LCD_DATA1_PIN
-# define LCD_DATA1_PIN 5 /**< pin for 4bit data bit 1 */
-# endif
-# ifndef LCD_DATA2_PIN
-# define LCD_DATA2_PIN 6 /**< pin for 4bit data bit 2 */
-# endif
-# ifndef LCD_DATA3_PIN
-# define LCD_DATA3_PIN 7 /**< pin for 4bit data bit 3 */
-# endif
-# ifndef LCD_RS_PORT
-# define LCD_RS_PORT LCD_PORT /**< port for RS line */
-# endif
-# ifndef LCD_RS_PIN
-# define LCD_RS_PIN 3 /**< pin for RS line */
-# endif
-# ifndef LCD_RW_PORT
-# define LCD_RW_PORT LCD_PORT /**< port for RW line */
-# endif
-# ifndef LCD_RW_PIN
-# define LCD_RW_PIN 2 /**< pin for RW line */
-# endif
-# ifndef LCD_E_PORT
-# define LCD_E_PORT LCD_PORT /**< port for Enable line */
-# endif
-# ifndef LCD_E_PIN
-# define LCD_E_PIN 1 /**< pin for Enable line */
-# endif
-
-#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__)
-/*
- * memory mapped mode is only supported when the device has an external data memory interface
- */
-# define LCD_IO_DATA 0xC000 /* A15=E=1, A14=RS=1 */
-# define LCD_IO_FUNCTION 0x8000 /* A15=E=1, A14=RS=0 */
-# define LCD_IO_READ 0x0100 /* A8 =R/W=1 (R/W: 1=Read, 0=Write */
-
-#else
-# error "external data memory interface not available for this device, use 4-bit IO port mode"
-
-#endif
-
-/**
- * @name Definitions of delays
- * Used to calculate delay timers.
- * Adapt the F_CPU define in the Makefile to the clock frequency in Hz of your target
- *
- * These delay times can be adjusted, if some displays require different delays.\n
- * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
- * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile.
- * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
- */
-#ifndef LCD_DELAY_BOOTUP
-# define LCD_DELAY_BOOTUP 16000 /**< delay in micro seconds after power-on */
-#endif
-#ifndef LCD_DELAY_INIT
-# define LCD_DELAY_INIT 5000 /**< delay in micro seconds after initialization command sent */
-#endif
-#ifndef LCD_DELAY_INIT_REP
-# define LCD_DELAY_INIT_REP 64 /**< delay in micro seconds after initialization command repeated */
-#endif
-#ifndef LCD_DELAY_INIT_4BIT
-# define LCD_DELAY_INIT_4BIT 64 /**< delay in micro seconds after setting 4-bit mode */
-#endif
-#ifndef LCD_DELAY_BUSY_FLAG
-# define LCD_DELAY_BUSY_FLAG 4 /**< time in micro seconds the address counter is updated after busy flag is cleared */
-#endif
-#ifndef LCD_DELAY_ENABLE_PULSE
-# define LCD_DELAY_ENABLE_PULSE 1 /**< enable signal pulse width in micro seconds */
-#endif
-
-/**
- * @name Definitions for LCD command instructions
- * The constants define the various LCD controller instructions which can be passed to the
- * function lcd_command(), see HD44780 data sheet for a complete description.
- */
-
-/* instruction register bit positions, see HD44780U data sheet */
-#define LCD_CLR 0 /* DB0: clear display */
-#define LCD_HOME 1 /* DB1: return to home position */
-#define LCD_ENTRY_MODE 2 /* DB2: set entry mode */
-#define LCD_ENTRY_INC 1 /* DB1: 1=increment, 0=decrement */
-#define LCD_ENTRY_SHIFT 0 /* DB2: 1=display shift on */
-#define LCD_ON 3 /* DB3: turn lcd/cursor on */
-#define LCD_ON_DISPLAY 2 /* DB2: turn display on */
-#define LCD_ON_CURSOR 1 /* DB1: turn cursor on */
-#define LCD_ON_BLINK 0 /* DB0: blinking cursor ? */
-#define LCD_MOVE 4 /* DB4: move cursor/display */
-#define LCD_MOVE_DISP 3 /* DB3: move display (0-> cursor) ? */
-#define LCD_MOVE_RIGHT 2 /* DB2: move right (0-> left) ? */
-#define LCD_FUNCTION 5 /* DB5: function set */
-#define LCD_FUNCTION_8BIT 4 /* DB4: set 8BIT mode (0->4BIT mode) */
-#define LCD_FUNCTION_2LINES 3 /* DB3: two lines (0->one line) */
-#define LCD_FUNCTION_10DOTS 2 /* DB2: 5x10 font (0->5x7 font) */
-#define LCD_CGRAM 6 /* DB6: set CG RAM address */
-#define LCD_DDRAM 7 /* DB7: set DD RAM address */
-#define LCD_BUSY 7 /* DB7: LCD is busy */
-
-/* set entry mode: display shift on/off, dec/inc cursor move direction */
-#define LCD_ENTRY_DEC 0x04 /* display shift off, dec cursor move dir */
-#define LCD_ENTRY_DEC_SHIFT 0x05 /* display shift on, dec cursor move dir */
-#define LCD_ENTRY_INC_ 0x06 /* display shift off, inc cursor move dir */
-#define LCD_ENTRY_INC_SHIFT 0x07 /* display shift on, inc cursor move dir */
-
-/* display on/off, cursor on/off, blinking char at cursor position */
-#define LCD_DISP_OFF 0x08 /* display off */
-#define LCD_DISP_ON 0x0C /* display on, cursor off */
-#define LCD_DISP_ON_BLINK 0x0D /* display on, cursor off, blink char */
-#define LCD_DISP_ON_CURSOR 0x0E /* display on, cursor on */
-#define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */
-
-/* move cursor/shift display */
-#define LCD_MOVE_CURSOR_LEFT 0x10 /* move cursor left (decrement) */
-#define LCD_MOVE_CURSOR_RIGHT 0x14 /* move cursor right (increment) */
-#define LCD_MOVE_DISP_LEFT 0x18 /* shift display left */
-#define LCD_MOVE_DISP_RIGHT 0x1C /* shift display right */
-
-/* function set: set interface data length and number of display lines */
-#define LCD_FUNCTION_4BIT_1LINE 0x20 /* 4-bit interface, single line, 5x7 dots */
-#define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line, 5x7 dots */
-#define LCD_FUNCTION_8BIT_1LINE 0x30 /* 8-bit interface, single line, 5x7 dots */
-#define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line, 5x7 dots */
-
-#define LCD_MODE_DEFAULT ((1 << LCD_ENTRY_MODE) | (1 << LCD_ENTRY_INC))
-
-/**
- * @name Functions
- */
-
-/**
- @brief Initialize display and select type of cursor
- @param dispAttr \b LCD_DISP_OFF display off\n
- \b LCD_DISP_ON display on, cursor off\n
- \b LCD_DISP_ON_CURSOR display on, cursor on\n
- \b LCD_DISP_ON_CURSOR_BLINK display on, cursor on flashing
- @return none
-*/
-extern void lcd_init(uint8_t dispAttr);
-
-/**
- @brief Clear display and set cursor to home position
- @return none
-*/
-extern void lcd_clrscr(void);
-
-/**
- @brief Set cursor to home position
- @return none
-*/
-extern void lcd_home(void);
-
-/**
- @brief Set cursor to specified position
-
- @param x horizontal position\n (0: left most position)
- @param y vertical position\n (0: first line)
- @return none
-*/
-extern void lcd_gotoxy(uint8_t x, uint8_t y);
-
-/**
- @brief Display character at current cursor position
- @param c character to be displayed
- @return none
-*/
-extern void lcd_putc(char c);
-
-/**
- @brief Display string without auto linefeed
- @param s string to be displayed
- @return none
-*/
-extern void lcd_puts(const char *s);
-
-/**
- @brief Display string from program memory without auto linefeed
- @param progmem_s string from program memory be be displayed
- @return none
- @see lcd_puts_P
-*/
-extern void lcd_puts_p(const char *progmem_s);
-
-/**
- @brief Send LCD controller instruction command
- @param cmd instruction to send to LCD controller, see HD44780 data sheet
- @return none
-*/
-extern void lcd_command(uint8_t cmd);
-
-/**
- @brief Send data byte to LCD controller
-
- Similar to lcd_putc(), but without interpreting LF
- @param data byte to send to LCD controller, see HD44780 data sheet
- @return none
-*/
-extern void lcd_data(uint8_t data);
-
-/**
- @brief macros for automatically storing string constant in program memory
-*/
-#define lcd_puts_P(__s) lcd_puts_p(PSTR(__s))
-
-/**@}*/
diff --git a/drivers/avr/i2c_master.c b/drivers/avr/i2c_master.c
deleted file mode 100644
index 2773e00778..0000000000
--- a/drivers/avr/i2c_master.c
+++ /dev/null
@@ -1,241 +0,0 @@
-/* Copyright (C) 2019 Elia Ritterbusch
- +
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-/* Library made by: g4lvanix
- * GitHub repository: https://github.com/g4lvanix/I2C-master-lib
- */
-
-#include
-#include
-
-#include "i2c_master.h"
-#include "timer.h"
-#include "wait.h"
-
-#ifndef F_SCL
-# define F_SCL 400000UL // SCL frequency
-#endif
-
-#ifndef I2C_START_RETRY_COUNT
-# define I2C_START_RETRY_COUNT 20
-#endif // I2C_START_RETRY_COUNT
-
-#define TWBR_val (((F_CPU / F_SCL) - 16) / 2)
-
-#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
-
-void i2c_init(void) {
- TWSR = 0; /* no prescaler */
- TWBR = (uint8_t)TWBR_val;
-
-#ifdef __AVR_ATmega32A__
- // set pull-up resistors on I2C bus pins
- PORTC |= 0b11;
-
- // enable TWI (two-wire interface)
- TWCR |= (1 << TWEN);
-
- // enable TWI interrupt and slave address ACK
- TWCR |= (1 << TWIE);
- TWCR |= (1 << TWEA);
-#endif
-}
-
-static i2c_status_t i2c_start_impl(uint8_t address, uint16_t timeout) {
- // reset TWI control register
- TWCR = 0;
- // transmit START condition
- TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
-
- uint16_t timeout_timer = timer_read();
- while (!(TWCR & (1 << TWINT))) {
- if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
- return I2C_STATUS_TIMEOUT;
- }
- }
-
- // check if the start condition was successfully transmitted
- if (((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)) {
- return I2C_STATUS_ERROR;
- }
-
- // load slave address into data register
- TWDR = address;
- // start transmission of address
- TWCR = (1 << TWINT) | (1 << TWEN);
-
- timeout_timer = timer_read();
- while (!(TWCR & (1 << TWINT))) {
- if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
- return I2C_STATUS_TIMEOUT;
- }
- }
-
- // check if the device has acknowledged the READ / WRITE mode
- uint8_t twst = TW_STATUS & 0xF8;
- if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
- return I2C_STATUS_ERROR;
- }
-
- return I2C_STATUS_SUCCESS;
-}
-
-i2c_status_t i2c_start(uint8_t address, uint16_t timeout) {
- // Retry i2c_start_impl a bunch times in case the remote side has interrupts disabled.
- uint16_t timeout_timer = timer_read();
- uint16_t time_slice = MAX(1, (timeout == (I2C_TIMEOUT_INFINITE)) ? 5 : (timeout / (I2C_START_RETRY_COUNT))); // if it's infinite, wait 1ms between attempts, otherwise split up the entire timeout into the number of retries
- i2c_status_t status;
- do {
- status = i2c_start_impl(address, time_slice);
- } while ((status < 0) && ((timeout == I2C_TIMEOUT_INFINITE) || (timer_elapsed(timeout_timer) < timeout)));
- return status;
-}
-
-i2c_status_t i2c_write(uint8_t data, uint16_t timeout) {
- // load data into data register
- TWDR = data;
- // start transmission of data
- TWCR = (1 << TWINT) | (1 << TWEN);
-
- uint16_t timeout_timer = timer_read();
- while (!(TWCR & (1 << TWINT))) {
- if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
- return I2C_STATUS_TIMEOUT;
- }
- }
-
- if ((TW_STATUS & 0xF8) != TW_MT_DATA_ACK) {
- return I2C_STATUS_ERROR;
- }
-
- return I2C_STATUS_SUCCESS;
-}
-
-int16_t i2c_read_ack(uint16_t timeout) {
- // start TWI module and acknowledge data after reception
- TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
-
- uint16_t timeout_timer = timer_read();
- while (!(TWCR & (1 << TWINT))) {
- if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
- return I2C_STATUS_TIMEOUT;
- }
- }
-
- // return received data from TWDR
- return TWDR;
-}
-
-int16_t i2c_read_nack(uint16_t timeout) {
- // start receiving without acknowledging reception
- TWCR = (1 << TWINT) | (1 << TWEN);
-
- uint16_t timeout_timer = timer_read();
- while (!(TWCR & (1 << TWINT))) {
- if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
- return I2C_STATUS_TIMEOUT;
- }
- }
-
- // return received data from TWDR
- return TWDR;
-}
-
-i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
-
- for (uint16_t i = 0; i < length && status >= 0; i++) {
- status = i2c_write(data[i], timeout);
- }
-
- i2c_stop();
-
- return status;
-}
-
-i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_status_t status = i2c_start(address | I2C_READ, timeout);
-
- for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
- status = i2c_read_ack(timeout);
- if (status >= 0) {
- data[i] = status;
- }
- }
-
- if (status >= 0) {
- status = i2c_read_nack(timeout);
- if (status >= 0) {
- data[(length - 1)] = status;
- }
- }
-
- i2c_stop();
-
- return (status < 0) ? status : I2C_STATUS_SUCCESS;
-}
-
-i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_status_t status = i2c_start(devaddr | 0x00, timeout);
- if (status >= 0) {
- status = i2c_write(regaddr, timeout);
-
- for (uint16_t i = 0; i < length && status >= 0; i++) {
- status = i2c_write(data[i], timeout);
- }
- }
-
- i2c_stop();
-
- return status;
-}
-
-i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_status_t status = i2c_start(devaddr, timeout);
- if (status < 0) {
- goto error;
- }
-
- status = i2c_write(regaddr, timeout);
- if (status < 0) {
- goto error;
- }
-
- status = i2c_start(devaddr | 0x01, timeout);
-
- for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
- status = i2c_read_ack(timeout);
- if (status >= 0) {
- data[i] = status;
- }
- }
-
- if (status >= 0) {
- status = i2c_read_nack(timeout);
- if (status >= 0) {
- data[(length - 1)] = status;
- }
- }
-
-error:
- i2c_stop();
-
- return (status < 0) ? status : I2C_STATUS_SUCCESS;
-}
-
-void i2c_stop(void) {
- // transmit STOP condition
- TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
-}
diff --git a/drivers/avr/i2c_master.h b/drivers/avr/i2c_master.h
deleted file mode 100644
index e5af73364b..0000000000
--- a/drivers/avr/i2c_master.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Copyright (C) 2019 Elia Ritterbusch
- +
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-/* Library made by: g4lvanix
- * GitHub repository: https://github.com/g4lvanix/I2C-master-lib
- */
-
-#pragma once
-
-#define I2C_READ 0x01
-#define I2C_WRITE 0x00
-
-typedef int16_t i2c_status_t;
-
-#define I2C_STATUS_SUCCESS (0)
-#define I2C_STATUS_ERROR (-1)
-#define I2C_STATUS_TIMEOUT (-2)
-
-#define I2C_TIMEOUT_IMMEDIATE (0)
-#define I2C_TIMEOUT_INFINITE (0xFFFF)
-
-void i2c_init(void);
-i2c_status_t i2c_start(uint8_t address, uint16_t timeout);
-i2c_status_t i2c_write(uint8_t data, uint16_t timeout);
-int16_t i2c_read_ack(uint16_t timeout);
-int16_t i2c_read_nack(uint16_t timeout);
-i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout);
-i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
-i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
-i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
-void i2c_stop(void);
diff --git a/drivers/avr/i2c_slave.c b/drivers/avr/i2c_slave.c
deleted file mode 100644
index 2907f164c0..0000000000
--- a/drivers/avr/i2c_slave.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/* Copyright (C) 2019 Elia Ritterbusch
- +
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-/* Library made by: g4lvanix
- * GitHub repository: https://github.com/g4lvanix/I2C-slave-lib
- */
-
-#include
-#include
-#include
-#include
-#include
-
-#include "i2c_slave.h"
-
-#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
-# include "transactions.h"
-
-static volatile bool is_callback_executor = false;
-#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
-
-volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
-
-static volatile uint8_t buffer_address;
-static volatile bool slave_has_register_set = false;
-
-void i2c_slave_init(uint8_t address) {
- // load address into TWI address register
- TWAR = address;
- // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt
- TWCR = (1 << TWIE) | (1 << TWEA) | (1 << TWINT) | (1 << TWEN);
-}
-
-void i2c_slave_stop(void) {
- // clear acknowledge and enable bits
- TWCR &= ~((1 << TWEA) | (1 << TWEN));
-}
-
-ISR(TWI_vect) {
- uint8_t ack = 1;
-
- switch (TW_STATUS) {
- case TW_SR_SLA_ACK:
- // The device is now a slave receiver
- slave_has_register_set = false;
-#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
- is_callback_executor = false;
-#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
- break;
-
- case TW_SR_DATA_ACK:
- // This device is a slave receiver and has received data
- // First byte is the location then the bytes will be writen in buffer with auto-increment
- if (!slave_has_register_set) {
- buffer_address = TWDR;
-
- if (buffer_address >= I2C_SLAVE_REG_COUNT) { // address out of bounds dont ack
- ack = 0;
- buffer_address = 0;
- }
- slave_has_register_set = true; // address has been received now fill in buffer
-
-#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
- // Work out if we're attempting to execute a callback
- is_callback_executor = buffer_address == split_transaction_table[I2C_EXECUTE_CALLBACK].initiator2target_offset;
-#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
- } else {
- i2c_slave_reg[buffer_address] = TWDR;
- buffer_address++;
-
-#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
- // If we're intending to execute a transaction callback, do so, as we've just received the transaction ID
- if (is_callback_executor) {
- split_transaction_desc_t *trans = &split_transaction_table[split_shmem->transaction_id];
- if (trans->slave_callback) {
- trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
- }
- }
-#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
- }
- break;
-
- case TW_ST_SLA_ACK:
- case TW_ST_DATA_ACK:
- // This device is a slave transmitter and master has requested data
- TWDR = i2c_slave_reg[buffer_address];
- buffer_address++;
- break;
-
- case TW_BUS_ERROR:
- // We got an error, reset i2c
- TWCR = 0;
- default:
- break;
- }
-
- // Reset i2c state machine to be ready for next interrupt
- TWCR |= (1 << TWIE) | (1 << TWINT) | (ack << TWEA) | (1 << TWEN);
-}
diff --git a/drivers/avr/i2c_slave.h b/drivers/avr/i2c_slave.h
deleted file mode 100644
index a8647c9da3..0000000000
--- a/drivers/avr/i2c_slave.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Copyright (C) 2019 Elia Ritterbusch
- +
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-/* Library made by: g4lvanix
- * GitHub repository: https://github.com/g4lvanix/I2C-slave-lib
-
- Info: Inititate the library by giving the required address.
- Read or write to the necessary buffer according to the opperation.
- */
-
-#pragma once
-
-#ifndef I2C_SLAVE_REG_COUNT
-
-# if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
-# include "transport.h"
-# define I2C_SLAVE_REG_COUNT sizeof(split_shared_memory_t)
-# else // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
-# define I2C_SLAVE_REG_COUNT 30
-# endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
-
-#endif // I2C_SLAVE_REG_COUNT
-
-_Static_assert(I2C_SLAVE_REG_COUNT < 256, "I2C target registers must be single byte");
-
-extern volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
-
-void i2c_slave_init(uint8_t address);
-void i2c_slave_stop(void);
diff --git a/drivers/avr/serial.c b/drivers/avr/serial.c
deleted file mode 100644
index 9a7345a53d..0000000000
--- a/drivers/avr/serial.c
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * WARNING: be careful changing this code, it is very timing dependent
- *
- * 2018-10-28 checked
- * avr-gcc 4.9.2
- * avr-gcc 5.4.0
- * avr-gcc 7.3.0
- */
-
-#ifndef F_CPU
-# define F_CPU 16000000
-#endif
-
-#include
-#include
-#include
-#include
-#include
-#include "serial.h"
-
-#ifdef SOFT_SERIAL_PIN
-
-# if !(defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
-# error serial.c is not supported for the currently selected MCU
-# endif
-// if using ATmega32U4/2, AT90USBxxx I2C, can not use PD0 and PD1 in soft serial.
-# if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
-# if defined(USE_AVR_I2C) && (SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1)
-# error Using I2C, so can not use PD0, PD1
-# endif
-# endif
-// PD0..PD3, common config
-# if SOFT_SERIAL_PIN == D0
-# define EIMSK_BIT _BV(INT0)
-# define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01)))
-# define SERIAL_PIN_INTERRUPT INT0_vect
-# define EICRx EICRA
-# elif SOFT_SERIAL_PIN == D1
-# define EIMSK_BIT _BV(INT1)
-# define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11)))
-# define SERIAL_PIN_INTERRUPT INT1_vect
-# define EICRx EICRA
-# elif SOFT_SERIAL_PIN == D2
-# define EIMSK_BIT _BV(INT2)
-# define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21)))
-# define SERIAL_PIN_INTERRUPT INT2_vect
-# define EICRx EICRA
-# elif SOFT_SERIAL_PIN == D3
-# define EIMSK_BIT _BV(INT3)
-# define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31)))
-# define SERIAL_PIN_INTERRUPT INT3_vect
-# define EICRx EICRA
-# endif
-
-// ATmegaxxU2/AT90USB162 specific config
-# if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_AT90USB162__)
-// PD4(INT5), PD6(INT6), PD7(INT7), PC7(INT4)
-# if SOFT_SERIAL_PIN == D4
-# define EIMSK_BIT _BV(INT5)
-# define EICRx_BIT (~(_BV(ISC50) | _BV(ISC51)))
-# define SERIAL_PIN_INTERRUPT INT5_vect
-# define EICRx EICRB
-# elif SOFT_SERIAL_PIN == D6
-# define EIMSK_BIT _BV(INT6)
-# define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
-# define SERIAL_PIN_INTERRUPT INT6_vect
-# define EICRx EICRB
-# elif SOFT_SERIAL_PIN == D7
-# define EIMSK_BIT _BV(INT7)
-# define EICRx_BIT (~(_BV(ISC70) | _BV(ISC71)))
-# define SERIAL_PIN_INTERRUPT INT7_vect
-# define EICRx EICRB
-# elif SOFT_SERIAL_PIN == C7
-# define EIMSK_BIT _BV(INT4)
-# define EICRx_BIT (~(_BV(ISC40) | _BV(ISC41)))
-# define SERIAL_PIN_INTERRUPT INT4_vect
-# define EICRx EICRB
-# endif
-# endif
-
-// ATmegaxxU4 specific config
-# if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
-// PE6(INT6)
-# if SOFT_SERIAL_PIN == E6
-# define EIMSK_BIT _BV(INT6)
-# define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
-# define SERIAL_PIN_INTERRUPT INT6_vect
-# define EICRx EICRB
-# endif
-# endif
-
-// AT90USBxxx specific config
-# if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
-// PE4..PE7(INT4..INT7)
-# if SOFT_SERIAL_PIN == E4
-# define EIMSK_BIT _BV(INT4)
-# define EICRx_BIT (~(_BV(ISC40) | _BV(ISC41)))
-# define SERIAL_PIN_INTERRUPT INT4_vect
-# define EICRx EICRB
-# elif SOFT_SERIAL_PIN == E5
-# define EIMSK_BIT _BV(INT5)
-# define EICRx_BIT (~(_BV(ISC50) | _BV(ISC51)))
-# define SERIAL_PIN_INTERRUPT INT5_vect
-# define EICRx EICRB
-# elif SOFT_SERIAL_PIN == E6
-# define EIMSK_BIT _BV(INT6)
-# define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
-# define SERIAL_PIN_INTERRUPT INT6_vect
-# define EICRx EICRB
-# elif SOFT_SERIAL_PIN == E7
-# define EIMSK_BIT _BV(INT7)
-# define EICRx_BIT (~(_BV(ISC70) | _BV(ISC71)))
-# define SERIAL_PIN_INTERRUPT INT7_vect
-# define EICRx EICRB
-# endif
-# endif
-
-# ifndef SERIAL_PIN_INTERRUPT
-# error invalid SOFT_SERIAL_PIN value
-# endif
-
-# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
-# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
-
-# define ALWAYS_INLINE __attribute__((always_inline))
-# define NO_INLINE __attribute__((noinline))
-# define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
-
-// parity check
-# define ODD_PARITY 1
-# define EVEN_PARITY 0
-# define PARITY EVEN_PARITY
-
-# ifdef SERIAL_DELAY
-// custom setup in config.h
-// #define TID_SEND_ADJUST 2
-// #define SERIAL_DELAY 6 // micro sec
-// #define READ_WRITE_START_ADJUST 30 // cycles
-// #define READ_WRITE_WIDTH_ADJUST 8 // cycles
-# else
-// ============ Standard setups ============
-
-# ifndef SELECT_SOFT_SERIAL_SPEED
-# define SELECT_SOFT_SERIAL_SPEED 1
-// 0: about 189kbps (Experimental only)
-// 1: about 137kbps (default)
-// 2: about 75kbps
-// 3: about 39kbps
-// 4: about 26kbps
-// 5: about 20kbps
-# endif
-
-# if __GNUC__ < 6
-# define TID_SEND_ADJUST 14
-# else
-# define TID_SEND_ADJUST 2
-# endif
-
-# if SELECT_SOFT_SERIAL_SPEED == 0
-// Very High speed
-# define SERIAL_DELAY 4 // micro sec
-# if __GNUC__ < 6
-# define READ_WRITE_START_ADJUST 33 // cycles
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_START_ADJUST 34 // cycles
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 1
-// High speed
-# define SERIAL_DELAY 6 // micro sec
-# if __GNUC__ < 6
-# define READ_WRITE_START_ADJUST 30 // cycles
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_START_ADJUST 33 // cycles
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 2
-// Middle speed
-# define SERIAL_DELAY 12 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
-# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 3
-// Low speed
-# define SERIAL_DELAY 24 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
-# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 4
-// Very Low speed
-# define SERIAL_DELAY 36 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
-# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 5
-// Ultra Low speed
-# define SERIAL_DELAY 48 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
-# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# else
-# error invalid SELECT_SOFT_SERIAL_SPEED value
-# endif /* SELECT_SOFT_SERIAL_SPEED */
-# endif /* SERIAL_DELAY */
-
-# define SERIAL_DELAY_HALF1 (SERIAL_DELAY / 2)
-# define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY / 2)
-
-# define SLAVE_INT_WIDTH_US 1
-# define SLAVE_INT_ACK_WIDTH_UNIT 2
-# define SLAVE_INT_ACK_WIDTH 4
-
-inline static void serial_delay(void) ALWAYS_INLINE;
-inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
-
-inline static void serial_delay_half1(void) ALWAYS_INLINE;
-inline static void serial_delay_half1(void) { _delay_us(SERIAL_DELAY_HALF1); }
-
-inline static void serial_delay_half2(void) ALWAYS_INLINE;
-inline static void serial_delay_half2(void) { _delay_us(SERIAL_DELAY_HALF2); }
-
-inline static void serial_output(void) ALWAYS_INLINE;
-inline static void serial_output(void) { setPinOutput(SOFT_SERIAL_PIN); }
-
-// make the serial pin an input with pull-up resistor
-inline static void serial_input_with_pullup(void) ALWAYS_INLINE;
-inline static void serial_input_with_pullup(void) { setPinInputHigh(SOFT_SERIAL_PIN); }
-
-inline static uint8_t serial_read_pin(void) ALWAYS_INLINE;
-inline static uint8_t serial_read_pin(void) { return !!readPin(SOFT_SERIAL_PIN); }
-
-inline static void serial_low(void) ALWAYS_INLINE;
-inline static void serial_low(void) { writePinLow(SOFT_SERIAL_PIN); }
-
-inline static void serial_high(void) ALWAYS_INLINE;
-inline static void serial_high(void) { writePinHigh(SOFT_SERIAL_PIN); }
-
-void soft_serial_initiator_init(void) {
- serial_output();
- serial_high();
-}
-
-void soft_serial_target_init(void) {
- serial_input_with_pullup();
-
- // Enable INT0-INT7
- EIMSK |= EIMSK_BIT;
- EICRx &= EICRx_BIT;
-}
-
-// Used by the sender to synchronize timing with the reciver.
-static void sync_recv(void) NO_INLINE;
-static void sync_recv(void) {
- for (uint8_t i = 0; i < SERIAL_DELAY * 5 && serial_read_pin(); i++) {
- }
- // This shouldn't hang if the target disconnects because the
- // serial line will float to high if the target does disconnect.
- while (!serial_read_pin())
- ;
-}
-
-// Used by the reciver to send a synchronization signal to the sender.
-static void sync_send(void) NO_INLINE;
-static void sync_send(void) {
- serial_low();
- serial_delay();
- serial_high();
-}
-
-// Reads a byte from the serial line
-static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) NO_INLINE;
-static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
- uint8_t byte, i, p, pb;
-
- _delay_sub_us(READ_WRITE_START_ADJUST);
- for (i = 0, byte = 0, p = PARITY; i < bit; i++) {
- serial_delay_half1(); // read the middle of pulses
- if (serial_read_pin()) {
- byte = (byte << 1) | 1;
- p ^= 1;
- } else {
- byte = (byte << 1) | 0;
- p ^= 0;
- }
- _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
- serial_delay_half2();
- }
- /* recive parity bit */
- serial_delay_half1(); // read the middle of pulses
- pb = serial_read_pin();
- _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
- serial_delay_half2();
-
- *pterrcount += (p != pb) ? 1 : 0;
-
- return byte;
-}
-
-// Sends a byte with MSB ordering
-void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE;
-void serial_write_chunk(uint8_t data, uint8_t bit) {
- uint8_t b, p;
- for (p = PARITY, b = 1 << (bit - 1); b; b >>= 1) {
- if (data & b) {
- serial_high();
- p ^= 1;
- } else {
- serial_low();
- p ^= 0;
- }
- serial_delay();
- }
- /* send parity bit */
- if (p & 1) {
- serial_high();
- } else {
- serial_low();
- }
- serial_delay();
-
- serial_low(); // sync_send() / senc_recv() need raise edge
-}
-
-static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
-static void serial_send_packet(uint8_t *buffer, uint8_t size) {
- for (uint8_t i = 0; i < size; ++i) {
- uint8_t data;
- data = buffer[i];
- sync_send();
- serial_write_chunk(data, 8);
- }
-}
-
-static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
-static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
- uint8_t pecount = 0;
- for (uint8_t i = 0; i < size; ++i) {
- uint8_t data;
- sync_recv();
- data = serial_read_chunk(&pecount, 8);
- buffer[i] = data;
- }
- return pecount == 0;
-}
-
-inline static void change_sender2reciver(void) {
- sync_send(); // 0
- serial_delay_half1(); // 1
- serial_low(); // 2
- serial_input_with_pullup(); // 2
- serial_delay_half1(); // 3
-}
-
-inline static void change_reciver2sender(void) {
- sync_recv(); // 0
- serial_delay(); // 1
- serial_low(); // 3
- serial_output(); // 3
- serial_delay_half1(); // 4
-}
-
-static inline uint8_t nibble_bits_count(uint8_t bits) {
- bits = (bits & 0x5) + (bits >> 1 & 0x5);
- bits = (bits & 0x3) + (bits >> 2 & 0x3);
- return bits;
-}
-
-// interrupt handle to be used by the target device
-ISR(SERIAL_PIN_INTERRUPT) {
- // recive transaction table index
- uint8_t tid, bits;
- uint8_t pecount = 0;
- sync_recv();
- bits = serial_read_chunk(&pecount, 8);
- tid = bits >> 3;
- bits = (bits & 7) != (nibble_bits_count(tid) & 7);
- if (bits || pecount > 0 || tid > NUM_TOTAL_TRANSACTIONS) {
- return;
- }
- serial_delay_half1();
-
- serial_high(); // response step1 low->high
- serial_output();
- _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT * SLAVE_INT_ACK_WIDTH);
- split_transaction_desc_t *trans = &split_transaction_table[tid];
- serial_low(); // response step2 ack high->low
-
- // If the transaction has a callback, we can execute it now
- if (trans->slave_callback) {
- trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
- }
-
- // target send phase
- if (trans->target2initiator_buffer_size > 0) serial_send_packet((uint8_t *)split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size);
- // target switch to input
- change_sender2reciver();
-
- // target recive phase
- if (trans->initiator2target_buffer_size > 0) {
- if (serial_recive_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
- *trans->status = TRANSACTION_ACCEPTED;
- } else {
- *trans->status = TRANSACTION_DATA_ERROR;
- }
- } else {
- *trans->status = TRANSACTION_ACCEPTED;
- }
-
- sync_recv(); // weit initiator output to high
-}
-
-/////////
-// start transaction by initiator
-//
-// int soft_serial_transaction(int sstd_index)
-//
-// Returns:
-// TRANSACTION_END
-// TRANSACTION_NO_RESPONSE
-// TRANSACTION_DATA_ERROR
-// this code is very time dependent, so we need to disable interrupts
-int soft_serial_transaction(int sstd_index) {
- if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
- split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
-
- if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
-
- cli();
-
- // signal to the target that we want to start a transaction
- serial_output();
- serial_low();
- _delay_us(SLAVE_INT_WIDTH_US);
-
- // send transaction table index
- int tid = (sstd_index << 3) | (7 & nibble_bits_count(sstd_index));
- sync_send();
- _delay_sub_us(TID_SEND_ADJUST);
- serial_write_chunk(tid, 8);
- serial_delay_half1();
-
- // wait for the target response (step1 low->high)
- serial_input_with_pullup();
- while (!serial_read_pin()) {
- _delay_sub_us(2);
- }
-
- // check if the target is present (step2 high->low)
- for (int i = 0; serial_read_pin(); i++) {
- if (i > SLAVE_INT_ACK_WIDTH + 1) {
- // slave failed to pull the line low, assume not present
- serial_output();
- serial_high();
- *trans->status = TRANSACTION_NO_RESPONSE;
- sei();
- return TRANSACTION_NO_RESPONSE;
- }
- _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
- }
-
- // initiator recive phase
- // if the target is present syncronize with it
- if (trans->target2initiator_buffer_size > 0) {
- if (!serial_recive_packet((uint8_t *)split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
- serial_output();
- serial_high();
- *trans->status = TRANSACTION_DATA_ERROR;
- sei();
- return TRANSACTION_DATA_ERROR;
- }
- }
-
- // initiator switch to output
- change_reciver2sender();
-
- // initiator send phase
- if (trans->initiator2target_buffer_size > 0) {
- serial_send_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size);
- }
-
- // always, release the line when not in use
- sync_send();
-
- *trans->status = TRANSACTION_END;
- sei();
- return TRANSACTION_END;
-}
-
-int soft_serial_get_and_clean_status(int sstd_index) {
- split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
- cli();
- int retval = *trans->status;
- *trans->status = 0;
- ;
- sei();
- return retval;
-}
-#endif
-
-// Helix serial.c history
-// 2018-1-29 fork from let's split and add PD2, modify sync_recv() (#2308, bceffdefc)
-// 2018-6-28 bug fix master to slave comm and speed up (#3255, 1038bbef4)
-// (adjusted with avr-gcc 4.9.2)
-// 2018-7-13 remove USE_SERIAL_PD2 macro (#3374, f30d6dd78)
-// (adjusted with avr-gcc 4.9.2)
-// 2018-8-11 add support multi-type transaction (#3608, feb5e4aae)
-// (adjusted with avr-gcc 4.9.2)
-// 2018-10-21 fix serial and RGB animation conflict (#4191, 4665e4fff)
-// (adjusted with avr-gcc 7.3.0)
-// 2018-10-28 re-adjust compiler depend value of delay (#4269, 8517f8a66)
-// (adjusted with avr-gcc 5.4.0, 7.3.0)
-// 2018-12-17 copy to TOP/quantum/split_common/ and remove backward compatibility code (#4669)
diff --git a/drivers/avr/spi_master.c b/drivers/avr/spi_master.c
deleted file mode 100644
index 4e8fd3bcdf..0000000000
--- a/drivers/avr/spi_master.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/* Copyright 2020
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "spi_master.h"
-
-#include "timer.h"
-
-#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
-# define SPI_SCK_PIN B1
-# define SPI_MOSI_PIN B2
-# define SPI_MISO_PIN B3
-#elif defined(__AVR_ATmega32A__)
-# define SPI_SCK_PIN B7
-# define SPI_MOSI_PIN B5
-# define SPI_MISO_PIN B6
-#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
-# define SPI_SCK_PIN B5
-# define SPI_MOSI_PIN B3
-# define SPI_MISO_PIN B4
-#endif
-
-#ifndef SPI_TIMEOUT
-# define SPI_TIMEOUT 100
-#endif
-
-static pin_t currentSlavePin = NO_PIN;
-static uint8_t currentSlaveConfig = 0;
-static bool currentSlave2X = false;
-
-void spi_init(void) {
- writePinHigh(SPI_SS_PIN);
- setPinOutput(SPI_SCK_PIN);
- setPinOutput(SPI_MOSI_PIN);
- setPinInput(SPI_MISO_PIN);
-
- SPCR = (_BV(SPE) | _BV(MSTR));
-}
-
-bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) {
- if (currentSlavePin != NO_PIN || slavePin == NO_PIN) {
- return false;
- }
-
- currentSlaveConfig = 0;
-
- if (lsbFirst) {
- currentSlaveConfig |= _BV(DORD);
- }
-
- switch (mode) {
- case 1:
- currentSlaveConfig |= _BV(CPHA);
- break;
- case 2:
- currentSlaveConfig |= _BV(CPOL);
- break;
- case 3:
- currentSlaveConfig |= (_BV(CPOL) | _BV(CPHA));
- break;
- }
-
- uint16_t roundedDivisor = 1;
- while (roundedDivisor < divisor) {
- roundedDivisor <<= 1;
- }
-
- switch (roundedDivisor) {
- case 16:
- currentSlaveConfig |= _BV(SPR0);
- break;
- case 64:
- currentSlaveConfig |= _BV(SPR1);
- break;
- case 128:
- currentSlaveConfig |= (_BV(SPR1) | _BV(SPR0));
- break;
- case 2:
- currentSlave2X = true;
- break;
- case 8:
- currentSlave2X = true;
- currentSlaveConfig |= _BV(SPR0);
- break;
- case 32:
- currentSlave2X = true;
- currentSlaveConfig |= _BV(SPR1);
- break;
- }
-
- SPCR |= currentSlaveConfig;
- if (currentSlave2X) {
- SPSR |= _BV(SPI2X);
- }
- currentSlavePin = slavePin;
- setPinOutput(currentSlavePin);
- writePinLow(currentSlavePin);
-
- return true;
-}
-
-spi_status_t spi_write(uint8_t data) {
- SPDR = data;
-
- uint16_t timeout_timer = timer_read();
- while (!(SPSR & _BV(SPIF))) {
- if ((timer_read() - timeout_timer) >= SPI_TIMEOUT) {
- return SPI_STATUS_TIMEOUT;
- }
- }
-
- return SPDR;
-}
-
-spi_status_t spi_read() {
- SPDR = 0x00; // Dummy
-
- uint16_t timeout_timer = timer_read();
- while (!(SPSR & _BV(SPIF))) {
- if ((timer_read() - timeout_timer) >= SPI_TIMEOUT) {
- return SPI_STATUS_TIMEOUT;
- }
- }
-
- return SPDR;
-}
-
-spi_status_t spi_transmit(const uint8_t *data, uint16_t length) {
- spi_status_t status;
-
- for (uint16_t i = 0; i < length; i++) {
- status = spi_write(data[i]);
-
- if (status < 0) {
- return status;
- }
- }
-
- return SPI_STATUS_SUCCESS;
-}
-
-spi_status_t spi_receive(uint8_t *data, uint16_t length) {
- spi_status_t status;
-
- for (uint16_t i = 0; i < length; i++) {
- status = spi_read();
-
- if (status >= 0) {
- data[i] = status;
- } else {
- return status;
- }
- }
-
- return SPI_STATUS_SUCCESS;
-}
-
-void spi_stop(void) {
- if (currentSlavePin != NO_PIN) {
- setPinOutput(currentSlavePin);
- writePinHigh(currentSlavePin);
- currentSlavePin = NO_PIN;
- SPSR &= ~(_BV(SPI2X));
- SPCR &= ~(currentSlaveConfig);
- currentSlaveConfig = 0;
- currentSlave2X = false;
- }
-}
diff --git a/drivers/avr/spi_master.h b/drivers/avr/spi_master.h
deleted file mode 100644
index 8a30f47ae4..0000000000
--- a/drivers/avr/spi_master.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Copyright 2020
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-
-#include "gpio.h"
-
-typedef int16_t spi_status_t;
-
-// Hardware SS pin is defined in the header so that user code can refer to it
-#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
-# define SPI_SS_PIN B0
-#elif defined(__AVR_ATmega32A__)
-# define SPI_SS_PIN B4
-#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
-# define SPI_SS_PIN B2
-#endif
-
-#define SPI_STATUS_SUCCESS (0)
-#define SPI_STATUS_ERROR (-1)
-#define SPI_STATUS_TIMEOUT (-2)
-
-#define SPI_TIMEOUT_IMMEDIATE (0)
-#define SPI_TIMEOUT_INFINITE (0xFFFF)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-void spi_init(void);
-
-bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor);
-
-spi_status_t spi_write(uint8_t data);
-
-spi_status_t spi_read(void);
-
-spi_status_t spi_transmit(const uint8_t *data, uint16_t length);
-
-spi_status_t spi_receive(uint8_t *data, uint16_t length);
-
-void spi_stop(void);
-#ifdef __cplusplus
-}
-#endif
diff --git a/drivers/avr/ssd1306.c b/drivers/avr/ssd1306.c
deleted file mode 100644
index 1a09a2bcb7..0000000000
--- a/drivers/avr/ssd1306.c
+++ /dev/null
@@ -1,319 +0,0 @@
-#ifdef SSD1306OLED
-
-# include "ssd1306.h"
-# include "i2c.h"
-# include
-# include "print.h"
-# include "glcdfont.c"
-# ifdef PROTOCOL_LUFA
-# include "lufa.h"
-# endif
-# include "sendchar.h"
-# include "timer.h"
-
-struct CharacterMatrix display;
-
-// Set this to 1 to help diagnose early startup problems
-// when testing power-on with ble. Turn it off otherwise,
-// as the latency of printing most of the debug info messes
-// with the matrix scan, causing keys to drop.
-# define DEBUG_TO_SCREEN 0
-
-// static uint16_t last_battery_update;
-// static uint32_t vbat;
-//#define BatteryUpdateInterval 10000 /* milliseconds */
-# define ScreenOffInterval 300000 /* milliseconds */
-# if DEBUG_TO_SCREEN
-static uint8_t displaying;
-# endif
-static uint16_t last_flush;
-
-// Write command sequence.
-// Returns true on success.
-static inline bool _send_cmd1(uint8_t cmd) {
- bool res = false;
-
- if (i2c_start_write(SSD1306_ADDRESS)) {
- xprintf("failed to start write to %d\n", SSD1306_ADDRESS);
- goto done;
- }
-
- if (i2c_master_write(0x0 /* command byte follows */)) {
- print("failed to write control byte\n");
-
- goto done;
- }
-
- if (i2c_master_write(cmd)) {
- xprintf("failed to write command %d\n", cmd);
- goto done;
- }
- res = true;
-done:
- i2c_master_stop();
- return res;
-}
-
-// Write 2-byte command sequence.
-// Returns true on success
-static inline bool _send_cmd2(uint8_t cmd, uint8_t opr) {
- if (!_send_cmd1(cmd)) {
- return false;
- }
- return _send_cmd1(opr);
-}
-
-// Write 3-byte command sequence.
-// Returns true on success
-static inline bool _send_cmd3(uint8_t cmd, uint8_t opr1, uint8_t opr2) {
- if (!_send_cmd1(cmd)) {
- return false;
- }
- if (!_send_cmd1(opr1)) {
- return false;
- }
- return _send_cmd1(opr2);
-}
-
-# define send_cmd1(c) \
- if (!_send_cmd1(c)) { \
- goto done; \
- }
-# define send_cmd2(c, o) \
- if (!_send_cmd2(c, o)) { \
- goto done; \
- }
-# define send_cmd3(c, o1, o2) \
- if (!_send_cmd3(c, o1, o2)) { \
- goto done; \
- }
-
-static void clear_display(void) {
- matrix_clear(&display);
-
- // Clear all of the display bits (there can be random noise
- // in the RAM on startup)
- send_cmd3(PageAddr, 0, (DisplayHeight / 8) - 1);
- send_cmd3(ColumnAddr, 0, DisplayWidth - 1);
-
- if (i2c_start_write(SSD1306_ADDRESS)) {
- goto done;
- }
- if (i2c_master_write(0x40)) {
- // Data mode
- goto done;
- }
- for (uint8_t row = 0; row < MatrixRows; ++row) {
- for (uint8_t col = 0; col < DisplayWidth; ++col) {
- i2c_master_write(0);
- }
- }
-
- display.dirty = false;
-
-done:
- i2c_master_stop();
-}
-
-# if DEBUG_TO_SCREEN
-# undef sendchar
-static int8_t capture_sendchar(uint8_t c) {
- sendchar(c);
- iota_gfx_write_char(c);
-
- if (!displaying) {
- iota_gfx_flush();
- }
- return 0;
-}
-# endif
-
-bool iota_gfx_init(void) {
- bool success = false;
-
- send_cmd1(DisplayOff);
- send_cmd2(SetDisplayClockDiv, 0x80);
- send_cmd2(SetMultiPlex, DisplayHeight - 1);
-
- send_cmd2(SetDisplayOffset, 0);
-
- send_cmd1(SetStartLine | 0x0);
- send_cmd2(SetChargePump, 0x14 /* Enable */);
- send_cmd2(SetMemoryMode, 0 /* horizontal addressing */);
-
-# ifdef OLED_ROTATE180
- // the following Flip the display orientation 180 degrees
- send_cmd1(SegRemap);
- send_cmd1(ComScanInc);
-# endif
-# ifndef OLED_ROTATE180
- // Flips the display orientation 0 degrees
- send_cmd1(SegRemap | 0x1);
- send_cmd1(ComScanDec);
-# endif
-
- send_cmd2(SetComPins, 0x2);
- send_cmd2(SetContrast, 0x8f);
- send_cmd2(SetPreCharge, 0xf1);
- send_cmd2(SetVComDetect, 0x40);
- send_cmd1(DisplayAllOnResume);
- send_cmd1(NormalDisplay);
- send_cmd1(DeActivateScroll);
- send_cmd1(DisplayOn);
-
- send_cmd2(SetContrast, 0); // Dim
-
- clear_display();
-
- success = true;
-
- iota_gfx_flush();
-
-# if DEBUG_TO_SCREEN
- print_set_sendchar(capture_sendchar);
-# endif
-
-done:
- return success;
-}
-
-bool iota_gfx_off(void) {
- bool success = false;
-
- send_cmd1(DisplayOff);
- success = true;
-
-done:
- return success;
-}
-
-bool iota_gfx_on(void) {
- bool success = false;
-
- send_cmd1(DisplayOn);
- success = true;
-
-done:
- return success;
-}
-
-void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c) {
- *matrix->cursor = c;
- ++matrix->cursor;
-
- if (matrix->cursor - &matrix->display[0][0] == sizeof(matrix->display)) {
- // We went off the end; scroll the display upwards by one line
- memmove(&matrix->display[0], &matrix->display[1], MatrixCols * (MatrixRows - 1));
- matrix->cursor = &matrix->display[MatrixRows - 1][0];
- memset(matrix->cursor, ' ', MatrixCols);
- }
-}
-
-void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c) {
- matrix->dirty = true;
-
- if (c == '\n') {
- // Clear to end of line from the cursor and then move to the
- // start of the next line
- uint8_t cursor_col = (matrix->cursor - &matrix->display[0][0]) % MatrixCols;
-
- while (cursor_col++ < MatrixCols) {
- matrix_write_char_inner(matrix, ' ');
- }
- return;
- }
-
- matrix_write_char_inner(matrix, c);
-}
-
-void iota_gfx_write_char(uint8_t c) { matrix_write_char(&display, c); }
-
-void matrix_write(struct CharacterMatrix *matrix, const char *data) {
- const char *end = data + strlen(data);
- while (data < end) {
- matrix_write_char(matrix, *data);
- ++data;
- }
-}
-
-void iota_gfx_write(const char *data) { matrix_write(&display, data); }
-
-void matrix_write_P(struct CharacterMatrix *matrix, const char *data) {
- while (true) {
- uint8_t c = pgm_read_byte(data);
- if (c == 0) {
- return;
- }
- matrix_write_char(matrix, c);
- ++data;
- }
-}
-
-void iota_gfx_write_P(const char *data) { matrix_write_P(&display, data); }
-
-void matrix_clear(struct CharacterMatrix *matrix) {
- memset(matrix->display, ' ', sizeof(matrix->display));
- matrix->cursor = &matrix->display[0][0];
- matrix->dirty = true;
-}
-
-void iota_gfx_clear_screen(void) { matrix_clear(&display); }
-
-void matrix_render(struct CharacterMatrix *matrix) {
- last_flush = timer_read();
- iota_gfx_on();
-# if DEBUG_TO_SCREEN
- ++displaying;
-# endif
-
- // Move to the home position
- send_cmd3(PageAddr, 0, MatrixRows - 1);
- send_cmd3(ColumnAddr, 0, (MatrixCols * FontWidth) - 1);
-
- if (i2c_start_write(SSD1306_ADDRESS)) {
- goto done;
- }
- if (i2c_master_write(0x40)) {
- // Data mode
- goto done;
- }
-
- for (uint8_t row = 0; row < MatrixRows; ++row) {
- for (uint8_t col = 0; col < MatrixCols; ++col) {
- const uint8_t *glyph = font + (matrix->display[row][col] * (FontWidth - 1));
-
- for (uint8_t glyphCol = 0; glyphCol < FontWidth - 1; ++glyphCol) {
- uint8_t colBits = pgm_read_byte(glyph + glyphCol);
- i2c_master_write(colBits);
- }
-
- // 1 column of space between chars (it's not included in the glyph)
- i2c_master_write(0);
- }
- }
-
- matrix->dirty = false;
-
-done:
- i2c_master_stop();
-# if DEBUG_TO_SCREEN
- --displaying;
-# endif
-}
-
-void iota_gfx_flush(void) { matrix_render(&display); }
-
-__attribute__((weak)) void iota_gfx_task_user(void) {}
-
-void iota_gfx_task(void) {
- iota_gfx_task_user();
-
- if (display.dirty) {
- iota_gfx_flush();
- }
-
- if (timer_elapsed(last_flush) > ScreenOffInterval) {
- iota_gfx_off();
- }
-}
-#endif
diff --git a/drivers/avr/ssd1306.h b/drivers/avr/ssd1306.h
deleted file mode 100644
index 6eecdcfaa4..0000000000
--- a/drivers/avr/ssd1306.h
+++ /dev/null
@@ -1,87 +0,0 @@
-#pragma once
-
-#include
-#include
-#include "config.h"
-
-enum ssd1306_cmds {
- DisplayOff = 0xAE,
- DisplayOn = 0xAF,
-
- SetContrast = 0x81,
- DisplayAllOnResume = 0xA4,
-
- DisplayAllOn = 0xA5,
- NormalDisplay = 0xA6,
- InvertDisplay = 0xA7,
- SetDisplayOffset = 0xD3,
- SetComPins = 0xda,
- SetVComDetect = 0xdb,
- SetDisplayClockDiv = 0xD5,
- SetPreCharge = 0xd9,
- SetMultiPlex = 0xa8,
- SetLowColumn = 0x00,
- SetHighColumn = 0x10,
- SetStartLine = 0x40,
-
- SetMemoryMode = 0x20,
- ColumnAddr = 0x21,
- PageAddr = 0x22,
-
- ComScanInc = 0xc0,
- ComScanDec = 0xc8,
- SegRemap = 0xa0,
- SetChargePump = 0x8d,
- ExternalVcc = 0x01,
- SwitchCapVcc = 0x02,
-
- ActivateScroll = 0x2f,
- DeActivateScroll = 0x2e,
- SetVerticalScrollArea = 0xa3,
- RightHorizontalScroll = 0x26,
- LeftHorizontalScroll = 0x27,
- VerticalAndRightHorizontalScroll = 0x29,
- VerticalAndLeftHorizontalScroll = 0x2a,
-};
-
-// Controls the SSD1306 128x32 OLED display via i2c
-
-#ifndef SSD1306_ADDRESS
-# define SSD1306_ADDRESS 0x3C
-#endif
-
-#define DisplayHeight 32
-#define DisplayWidth 128
-
-#define FontHeight 8
-#define FontWidth 6
-
-#define MatrixRows (DisplayHeight / FontHeight)
-#define MatrixCols (DisplayWidth / FontWidth)
-
-struct CharacterMatrix {
- uint8_t display[MatrixRows][MatrixCols];
- uint8_t *cursor;
- bool dirty;
-};
-
-extern struct CharacterMatrix display;
-
-bool iota_gfx_init(void);
-void iota_gfx_task(void);
-bool iota_gfx_off(void);
-bool iota_gfx_on(void);
-void iota_gfx_flush(void);
-void iota_gfx_write_char(uint8_t c);
-void iota_gfx_write(const char *data);
-void iota_gfx_write_P(const char *data);
-void iota_gfx_clear_screen(void);
-
-void iota_gfx_task_user(void);
-
-void matrix_clear(struct CharacterMatrix *matrix);
-void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c);
-void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c);
-void matrix_write(struct CharacterMatrix *matrix, const char *data);
-void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
-void matrix_render(struct CharacterMatrix *matrix);
diff --git a/drivers/avr/uart.c b/drivers/avr/uart.c
deleted file mode 100644
index c6abcb6fe0..0000000000
--- a/drivers/avr/uart.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/* UART Example for Teensy USB Development Board
- * http://www.pjrc.com/teensy/
- * Copyright (c) 2009 PJRC.COM, LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-// Version 1.0: Initial Release
-// Version 1.1: Add support for Teensy 2.0, minor optimizations
-
-#include
-#include
-
-#include "uart.h"
-
-#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
-# define UDRn UDR1
-# define UBRRnL UBRR1L
-# define UCSRnA UCSR1A
-# define UCSRnB UCSR1B
-# define UCSRnC UCSR1C
-# define U2Xn U2X1
-# define RXENn RXEN1
-# define TXENn TXEN1
-# define RXCIEn RXCIE1
-# define UCSZn1 UCSZ11
-# define UCSZn0 UCSZ10
-# define UDRIEn UDRIE1
-# define USARTn_UDRE_vect USART1_UDRE_vect
-# define USARTn_RX_vect USART1_RX_vect
-#elif defined(__AVR_ATmega32A__)
-# define UDRn UDR
-# define UBRRnL UBRRL
-# define UCSRnA UCSRA
-# define UCSRnB UCSRB
-# define UCSRnC UCSRC
-# define U2Xn U2X
-# define RXENn RXEN
-# define TXENn TXEN
-# define RXCIEn RXCIE
-# define UCSZn1 UCSZ1
-# define UCSZn0 UCSZ0
-# define UDRIEn UDRIE
-# define USARTn_UDRE_vect USART_UDRE_vect
-# define USARTn_RX_vect USART_RX_vect
-#elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
-# define UDRn UDR0
-# define UBRRnL UBRR0L
-# define UCSRnA UCSR0A
-# define UCSRnB UCSR0B
-# define UCSRnC UCSR0C
-# define U2Xn U2X0
-# define RXENn RXEN0
-# define TXENn TXEN0
-# define RXCIEn RXCIE0
-# define UCSZn1 UCSZ01
-# define UCSZn0 UCSZ00
-# define UDRIEn UDRIE0
-# define USARTn_UDRE_vect USART_UDRE_vect
-# define USARTn_RX_vect USART_RX_vect
-#endif
-
-// These buffers may be any size from 2 to 256 bytes.
-#define RX_BUFFER_SIZE 64
-#define TX_BUFFER_SIZE 256
-
-static volatile uint8_t tx_buffer[TX_BUFFER_SIZE];
-static volatile uint8_t tx_buffer_head;
-static volatile uint8_t tx_buffer_tail;
-static volatile uint8_t rx_buffer[RX_BUFFER_SIZE];
-static volatile uint8_t rx_buffer_head;
-static volatile uint8_t rx_buffer_tail;
-
-// Initialize the UART
-void uart_init(uint32_t baud) {
- cli();
- UBRRnL = (F_CPU / 4 / baud - 1) / 2;
- UCSRnA = (1 << U2Xn);
- UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
- UCSRnC = (1 << UCSZn1) | (1 << UCSZn0);
- tx_buffer_head = tx_buffer_tail = 0;
- rx_buffer_head = rx_buffer_tail = 0;
- sei();
-}
-
-// Transmit a byte
-void uart_putchar(uint8_t c) {
- uint8_t i;
-
- i = tx_buffer_head + 1;
- if (i >= TX_BUFFER_SIZE) i = 0;
- // return immediately to avoid deadlock when interrupt is disabled(called from ISR)
- if (tx_buffer_tail == i && (SREG & (1 << SREG_I)) == 0) return;
- while (tx_buffer_tail == i)
- ; // wait until space in buffer
- // cli();
- tx_buffer[i] = c;
- tx_buffer_head = i;
- UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn) | (1 << UDRIEn);
- // sei();
-}
-
-// Receive a byte
-uint8_t uart_getchar(void) {
- uint8_t c, i;
-
- while (rx_buffer_head == rx_buffer_tail)
- ; // wait for character
- i = rx_buffer_tail + 1;
- if (i >= RX_BUFFER_SIZE) i = 0;
- c = rx_buffer[i];
- rx_buffer_tail = i;
- return c;
-}
-
-// Return whether the number of bytes waiting in the receive buffer is nonzero.
-// Call this before uart_getchar() to check if it will need
-// to wait for a byte to arrive.
-bool uart_available(void) {
- uint8_t head, tail;
-
- head = rx_buffer_head;
- tail = rx_buffer_tail;
- if (head >= tail) return (head - tail) > 0;
- return (RX_BUFFER_SIZE + head - tail) > 0;
-}
-
-// Transmit Interrupt
-ISR(USARTn_UDRE_vect) {
- uint8_t i;
-
- if (tx_buffer_head == tx_buffer_tail) {
- // buffer is empty, disable transmit interrupt
- UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
- } else {
- i = tx_buffer_tail + 1;
- if (i >= TX_BUFFER_SIZE) i = 0;
- UDRn = tx_buffer[i];
- tx_buffer_tail = i;
- }
-}
-
-// Receive Interrupt
-ISR(USARTn_RX_vect) {
- uint8_t c, i;
-
- c = UDRn;
- i = rx_buffer_head + 1;
- if (i >= RX_BUFFER_SIZE) i = 0;
- if (i != rx_buffer_tail) {
- rx_buffer[i] = c;
- rx_buffer_head = i;
- }
-}
diff --git a/drivers/avr/uart.h b/drivers/avr/uart.h
deleted file mode 100644
index 602eb3d8b0..0000000000
--- a/drivers/avr/uart.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* UART Example for Teensy USB Development Board
- * http://www.pjrc.com/teensy/
- * Copyright (c) 2009 PJRC.COM, LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#pragma once
-
-#include
-#include
-
-void uart_init(uint32_t baud);
-
-void uart_putchar(uint8_t c);
-
-uint8_t uart_getchar(void);
-
-bool uart_available(void);
diff --git a/drivers/avr/ws2812.c b/drivers/avr/ws2812.c
deleted file mode 100644
index 77c492cd4c..0000000000
--- a/drivers/avr/ws2812.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * light weight WS2812 lib V2.0b
- *
- * Controls WS2811/WS2812/WS2812B RGB-LEDs
- * Author: Tim (cpldcpu@gmail.com)
- *
- * Jan 18th, 2014 v2.0b Initial Version
- * Nov 29th, 2015 v2.3 Added SK6812RGBW support
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-#include "ws2812.h"
-#include
-#include
-#include
-
-#define pinmask(pin) (_BV((pin)&0xF))
-
-/*
- * Forward declare internal functions
- *
- * The functions take a byte-array and send to the data output as WS2812 bitstream.
- * The length is the number of bytes to send - three per LED.
- */
-
-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) {
- DDRx_ADDRESS(RGB_DI_PIN) |= pinmask(RGB_DI_PIN);
-
- uint8_t masklo = ~(pinmask(RGB_DI_PIN)) & PORTx_ADDRESS(RGB_DI_PIN);
- uint8_t maskhi = pinmask(RGB_DI_PIN) | PORTx_ADDRESS(RGB_DI_PIN);
-
- ws2812_sendarray_mask((uint8_t *)ledarray, number_of_leds * sizeof(LED_TYPE), masklo, maskhi);
-
- _delay_us(WS2812_TRST_US);
-}
-
-/*
- This routine writes an array of bytes with RGB values to the Dataout pin
- using the fast 800kHz clockless WS2811/2812 protocol.
-*/
-
-// Timing in ns
-#define w_zeropulse 350
-#define w_onepulse 900
-#define w_totalperiod 1250
-
-// Fixed cycles used by the inner loop
-#define w_fixedlow 2
-#define w_fixedhigh 4
-#define w_fixedtotal 8
-
-// Insert NOPs to match the timing, if possible
-#define w_zerocycles (((F_CPU / 1000) * w_zeropulse) / 1000000)
-#define w_onecycles (((F_CPU / 1000) * w_onepulse + 500000) / 1000000)
-#define w_totalcycles (((F_CPU / 1000) * w_totalperiod + 500000) / 1000000)
-
-// w1_nops - nops between rising edge and falling edge - low
-#if w_zerocycles >= w_fixedlow
-# define w1_nops (w_zerocycles - w_fixedlow)
-#else
-# define w1_nops 0
-#endif
-
-// w2_nops - nops between fe low and fe high
-#if w_onecycles >= (w_fixedhigh + w1_nops)
-# define w2_nops (w_onecycles - w_fixedhigh - w1_nops)
-#else
-# define w2_nops 0
-#endif
-
-// w3_nops - nops to complete loop
-#if w_totalcycles >= (w_fixedtotal + w1_nops + w2_nops)
-# define w3_nops (w_totalcycles - w_fixedtotal - w1_nops - w2_nops)
-#else
-# define w3_nops 0
-#endif
-
-// The only critical timing parameter is the minimum pulse length of the "0"
-// Warn or throw error if this timing can not be met with current F_CPU settings.
-#define w_lowtime ((w1_nops + w_fixedlow) * 1000000) / (F_CPU / 1000)
-#if w_lowtime > 550
-# error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?"
-#elif w_lowtime > 450
-# warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)."
-# warning "Please consider a higher clockspeed, if possible"
-#endif
-
-#define w_nop1 "nop \n\t"
-#define w_nop2 "rjmp .+0 \n\t"
-#define w_nop4 w_nop2 w_nop2
-#define w_nop8 w_nop4 w_nop4
-#define w_nop16 w_nop8 w_nop8
-
-static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi) {
- uint8_t curbyte, ctr, sreg_prev;
-
- sreg_prev = SREG;
- cli();
-
- while (datlen--) {
- curbyte = (*data++);
-
- asm volatile(" ldi %0,8 \n\t"
- "loop%=: \n\t"
- " out %2,%3 \n\t" // '1' [01] '0' [01] - re
-#if (w1_nops & 1)
- w_nop1
-#endif
-#if (w1_nops & 2)
- w_nop2
-#endif
-#if (w1_nops & 4)
- w_nop4
-#endif
-#if (w1_nops & 8)
- w_nop8
-#endif
-#if (w1_nops & 16)
- w_nop16
-#endif
- " sbrs %1,7 \n\t" // '1' [03] '0' [02]
- " out %2,%4 \n\t" // '1' [--] '0' [03] - fe-low
- " lsl %1 \n\t" // '1' [04] '0' [04]
-#if (w2_nops & 1)
- w_nop1
-#endif
-#if (w2_nops & 2)
- w_nop2
-#endif
-#if (w2_nops & 4)
- w_nop4
-#endif
-#if (w2_nops & 8)
- w_nop8
-#endif
-#if (w2_nops & 16)
- w_nop16
-#endif
- " out %2,%4 \n\t" // '1' [+1] '0' [+1] - fe-high
-#if (w3_nops & 1)
- w_nop1
-#endif
-#if (w3_nops & 2)
- w_nop2
-#endif
-#if (w3_nops & 4)
- w_nop4
-#endif
-#if (w3_nops & 8)
- w_nop8
-#endif
-#if (w3_nops & 16)
- w_nop16
-#endif
-
- " dec %0 \n\t" // '1' [+2] '0' [+2]
- " brne loop%=\n\t" // '1' [+3] '0' [+4]
- : "=&d"(ctr)
- : "r"(curbyte), "I"(_SFR_IO_ADDR(PORTx_ADDRESS(RGB_DI_PIN))), "r"(maskhi), "r"(masklo));
- }
-
- SREG = sreg_prev;
-}
diff --git a/drivers/avr/ws2812_i2c.c b/drivers/avr/ws2812_i2c.c
deleted file mode 100644
index 1c332e24b6..0000000000
--- a/drivers/avr/ws2812_i2c.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "ws2812.h"
-#include "i2c_master.h"
-
-#ifdef RGBW
-# error "RGBW not supported"
-#endif
-
-#ifndef WS2812_ADDRESS
-# define WS2812_ADDRESS 0xb0
-#endif
-
-#ifndef WS2812_TIMEOUT
-# define WS2812_TIMEOUT 100
-#endif
-
-void ws2812_init(void) { i2c_init(); }
-
-// Setleds for standard RGB
-void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
- static bool s_init = false;
- if (!s_init) {
- ws2812_init();
- s_init = true;
- }
-
- i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT);
-}
diff --git a/drivers/chibios/analog.c b/drivers/chibios/analog.c
deleted file mode 100644
index 8c476fcac2..0000000000
--- a/drivers/chibios/analog.c
+++ /dev/null
@@ -1,321 +0,0 @@
-/* Copyright 2019 Drew Mills
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "quantum.h"
-#include "analog.h"
-#include
-#include
-
-#if !HAL_USE_ADC
-# error "You need to set HAL_USE_ADC to TRUE in your halconf.h to use the ADC."
-#endif
-
-#if !STM32_ADC_USE_ADC1 && !STM32_ADC_USE_ADC2 && !STM32_ADC_USE_ADC3 && !STM32_ADC_USE_ADC4
-# error "You need to set one of the 'STM32_ADC_USE_ADCx' settings to TRUE in your mcuconf.h to use the ADC."
-#endif
-
-#if STM32_ADC_DUAL_MODE
-# error "STM32 ADC Dual Mode is not supported at this time."
-#endif
-
-#if STM32_ADCV3_OVERSAMPLING
-# error "STM32 ADCV3 Oversampling is not supported at this time."
-#endif
-
-// Otherwise assume V3
-#if defined(STM32F0XX) || defined(STM32L0XX)
-# define USE_ADCV1
-#elif defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX)
-# define USE_ADCV2
-#endif
-
-// BODGE to make v2 look like v1,3 and 4
-#ifdef USE_ADCV2
-# if !defined(ADC_SMPR_SMP_1P5) && defined(ADC_SAMPLE_3)
-# define ADC_SMPR_SMP_1P5 ADC_SAMPLE_3
-# define ADC_SMPR_SMP_7P5 ADC_SAMPLE_15
-# define ADC_SMPR_SMP_13P5 ADC_SAMPLE_28
-# define ADC_SMPR_SMP_28P5 ADC_SAMPLE_56
-# define ADC_SMPR_SMP_41P5 ADC_SAMPLE_84
-# define ADC_SMPR_SMP_55P5 ADC_SAMPLE_112
-# define ADC_SMPR_SMP_71P5 ADC_SAMPLE_144
-# define ADC_SMPR_SMP_239P5 ADC_SAMPLE_480
-# endif
-
-# if !defined(ADC_SMPR_SMP_1P5) && defined(ADC_SAMPLE_1P5)
-# define ADC_SMPR_SMP_1P5 ADC_SAMPLE_1P5
-# define ADC_SMPR_SMP_7P5 ADC_SAMPLE_7P5
-# define ADC_SMPR_SMP_13P5 ADC_SAMPLE_13P5
-# define ADC_SMPR_SMP_28P5 ADC_SAMPLE_28P5
-# define ADC_SMPR_SMP_41P5 ADC_SAMPLE_41P5
-# define ADC_SMPR_SMP_55P5 ADC_SAMPLE_55P5
-# define ADC_SMPR_SMP_71P5 ADC_SAMPLE_71P5
-# define ADC_SMPR_SMP_239P5 ADC_SAMPLE_239P5
-# endif
-
-// we still sample at 12bit, but scale down to the requested bit range
-# define ADC_CFGR1_RES_12BIT 12
-# define ADC_CFGR1_RES_10BIT 10
-# define ADC_CFGR1_RES_8BIT 8
-# define ADC_CFGR1_RES_6BIT 6
-#endif
-
-/* User configurable ADC options */
-#ifndef ADC_COUNT
-# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F4XX)
-# define ADC_COUNT 1
-# elif defined(STM32F3XX)
-# define ADC_COUNT 4
-# else
-# error "ADC_COUNT has not been set for this ARM microcontroller."
-# endif
-#endif
-
-#ifndef ADC_NUM_CHANNELS
-# define ADC_NUM_CHANNELS 1
-#elif ADC_NUM_CHANNELS != 1
-# error "The ARM ADC implementation currently only supports reading one channel at a time."
-#endif
-
-#ifndef ADC_BUFFER_DEPTH
-# define ADC_BUFFER_DEPTH 1
-#endif
-
-// For more sampling rate options, look at hal_adc_lld.h in ChibiOS
-#ifndef ADC_SAMPLING_RATE
-# define ADC_SAMPLING_RATE ADC_SMPR_SMP_1P5
-#endif
-
-// Options are 12, 10, 8, and 6 bit.
-#ifndef ADC_RESOLUTION
-# ifdef ADC_CFGR_RES_10BITS // ADCv3, ADCv4
-# define ADC_RESOLUTION ADC_CFGR_RES_10BITS
-# else // ADCv1, ADCv5, or the bodge for ADCv2 above
-# define ADC_RESOLUTION ADC_CFGR1_RES_10BIT
-# endif
-#endif
-
-static ADCConfig adcCfg = {};
-static adcsample_t sampleBuffer[ADC_NUM_CHANNELS * ADC_BUFFER_DEPTH];
-
-// Initialize to max number of ADCs, set to empty object to initialize all to false.
-static bool adcInitialized[ADC_COUNT] = {};
-
-// TODO: add back TR handling???
-static ADCConversionGroup adcConversionGroup = {
- .circular = FALSE,
- .num_channels = (uint16_t)(ADC_NUM_CHANNELS),
-#if defined(USE_ADCV1)
- .cfgr1 = ADC_CFGR1_CONT | ADC_RESOLUTION,
- .smpr = ADC_SAMPLING_RATE,
-#elif defined(USE_ADCV2)
-# if !defined(STM32F1XX)
- .cr2 = ADC_CR2_SWSTART, // F103 seem very unhappy with, F401 seems very unhappy without...
-# endif
- .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),
- .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),
-#else
- .cfgr = ADC_CFGR_CONT | ADC_RESOLUTION,
- .smpr = {ADC_SMPR1_SMP_AN0(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN1(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN2(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN3(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN4(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN5(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN6(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN7(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN8(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN9(ADC_SAMPLING_RATE), ADC_SMPR2_SMP_AN10(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN11(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN12(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN13(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN14(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN15(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN16(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN17(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN18(ADC_SAMPLING_RATE)},
-#endif
-};
-
-// clang-format off
-__attribute__((weak)) adc_mux pinToMux(pin_t pin) {
- switch (pin) {
-#if defined(STM32F0XX)
- case A0: return TO_MUX( ADC_CHSELR_CHSEL0, 0 );
- case A1: return TO_MUX( ADC_CHSELR_CHSEL1, 0 );
- case A2: return TO_MUX( ADC_CHSELR_CHSEL2, 0 );
- case A3: return TO_MUX( ADC_CHSELR_CHSEL3, 0 );
- case A4: return TO_MUX( ADC_CHSELR_CHSEL4, 0 );
- case A5: return TO_MUX( ADC_CHSELR_CHSEL5, 0 );
- case A6: return TO_MUX( ADC_CHSELR_CHSEL6, 0 );
- case A7: return TO_MUX( ADC_CHSELR_CHSEL7, 0 );
- case B0: return TO_MUX( ADC_CHSELR_CHSEL8, 0 );
- case B1: return TO_MUX( ADC_CHSELR_CHSEL9, 0 );
- case C0: return TO_MUX( ADC_CHSELR_CHSEL10, 0 );
- case C1: return TO_MUX( ADC_CHSELR_CHSEL11, 0 );
- case C2: return TO_MUX( ADC_CHSELR_CHSEL12, 0 );
- case C3: return TO_MUX( ADC_CHSELR_CHSEL13, 0 );
- case C4: return TO_MUX( ADC_CHSELR_CHSEL14, 0 );
- case C5: return TO_MUX( ADC_CHSELR_CHSEL15, 0 );
-#elif defined(STM32F3XX)
- case A0: return TO_MUX( ADC_CHANNEL_IN1, 0 );
- case A1: return TO_MUX( ADC_CHANNEL_IN2, 0 );
- case A2: return TO_MUX( ADC_CHANNEL_IN3, 0 );
- case A3: return TO_MUX( ADC_CHANNEL_IN4, 0 );
- case A4: return TO_MUX( ADC_CHANNEL_IN1, 1 );
- case A5: return TO_MUX( ADC_CHANNEL_IN2, 1 );
- case A6: return TO_MUX( ADC_CHANNEL_IN3, 1 );
- case A7: return TO_MUX( ADC_CHANNEL_IN4, 1 );
- case B0: return TO_MUX( ADC_CHANNEL_IN12, 2 );
- case B1: return TO_MUX( ADC_CHANNEL_IN1, 2 );
- case B2: return TO_MUX( ADC_CHANNEL_IN12, 1 );
- case B12: return TO_MUX( ADC_CHANNEL_IN3, 3 );
- case B13: return TO_MUX( ADC_CHANNEL_IN5, 2 );
- case B14: return TO_MUX( ADC_CHANNEL_IN4, 3 );
- case B15: return TO_MUX( ADC_CHANNEL_IN5, 3 );
- case C0: return TO_MUX( ADC_CHANNEL_IN6, 0 ); // Can also be ADC2
- case C1: return TO_MUX( ADC_CHANNEL_IN7, 0 ); // Can also be ADC2
- case C2: return TO_MUX( ADC_CHANNEL_IN8, 0 ); // Can also be ADC2
- case C3: return TO_MUX( ADC_CHANNEL_IN9, 0 ); // Can also be ADC2
- case C4: return TO_MUX( ADC_CHANNEL_IN5, 1 );
- case C5: return TO_MUX( ADC_CHANNEL_IN11, 1 );
- case D8: return TO_MUX( ADC_CHANNEL_IN12, 3 );
- case D9: return TO_MUX( ADC_CHANNEL_IN13, 3 );
- case D10: return TO_MUX( ADC_CHANNEL_IN7, 2 ); // Can also be ADC4
- case D11: return TO_MUX( ADC_CHANNEL_IN8, 2 ); // Can also be ADC4
- case D12: return TO_MUX( ADC_CHANNEL_IN9, 2 ); // Can also be ADC4
- case D13: return TO_MUX( ADC_CHANNEL_IN10, 2 ); // Can also be ADC4
- case D14: return TO_MUX( ADC_CHANNEL_IN11, 2 ); // Can also be ADC4
- case E7: return TO_MUX( ADC_CHANNEL_IN13, 2 );
- case E8: return TO_MUX( ADC_CHANNEL_IN6, 2 ); // Can also be ADC4
- case E9: return TO_MUX( ADC_CHANNEL_IN2, 2 );
- case E10: return TO_MUX( ADC_CHANNEL_IN14, 2 );
- case E11: return TO_MUX( ADC_CHANNEL_IN15, 2 );
- case E12: return TO_MUX( ADC_CHANNEL_IN16, 2 );
- case E13: return TO_MUX( ADC_CHANNEL_IN3, 2 );
- case E14: return TO_MUX( ADC_CHANNEL_IN1, 3 );
- case E15: return TO_MUX( ADC_CHANNEL_IN2, 3 );
- case F2: return TO_MUX( ADC_CHANNEL_IN10, 0 ); // Can also be ADC2
- case F4: return TO_MUX( ADC_CHANNEL_IN5, 0 );
-#elif defined(STM32F4XX)
- case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
- case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
- case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
- case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 );
- case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 );
- case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 );
- case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 );
- case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 );
- case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 );
- case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 );
- case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 );
- case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 );
- case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 );
- case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 );
- case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 );
- case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 );
-# if STM32_ADC_USE_ADC3
- case F3: return TO_MUX( ADC_CHANNEL_IN9, 2 );
- case F4: return TO_MUX( ADC_CHANNEL_IN14, 2 );
- case F5: return TO_MUX( ADC_CHANNEL_IN15, 2 );
- case F6: return TO_MUX( ADC_CHANNEL_IN4, 2 );
- case F7: return TO_MUX( ADC_CHANNEL_IN5, 2 );
- case F8: return TO_MUX( ADC_CHANNEL_IN6, 2 );
- case F9: return TO_MUX( ADC_CHANNEL_IN7, 2 );
- case F10: return TO_MUX( ADC_CHANNEL_IN8, 2 );
-# endif
-#elif defined(STM32F1XX)
- case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
- case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
- case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
- case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 );
- case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 );
- case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 );
- case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 );
- case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 );
- case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 );
- case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 );
- case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 );
- case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 );
- case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 );
- case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 );
- case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 );
- case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 );
- // STM32F103x[C-G] in 144-pin packages also have analog inputs on F6...F10, but they are on ADC3, and the
- // ChibiOS ADC driver for STM32F1xx currently supports only ADC1, therefore these pins are not usable.
-#endif
- }
-
- // return an adc that would never be used so intToADCDriver will bail out
- return TO_MUX(0, 0xFF);
-}
-// clang-format on
-
-static inline ADCDriver* intToADCDriver(uint8_t adcInt) {
- switch (adcInt) {
-#if STM32_ADC_USE_ADC1
- case 0:
- return &ADCD1;
-#endif
-#if STM32_ADC_USE_ADC2
- case 1:
- return &ADCD2;
-#endif
-#if STM32_ADC_USE_ADC3
- case 2:
- return &ADCD3;
-#endif
-#if STM32_ADC_USE_ADC4
- case 3:
- return &ADCD4;
-#endif
- }
-
- return NULL;
-}
-
-static inline void manageAdcInitializationDriver(uint8_t adc, ADCDriver* adcDriver) {
- if (!adcInitialized[adc]) {
- adcStart(adcDriver, &adcCfg);
- adcInitialized[adc] = true;
- }
-}
-
-int16_t analogReadPin(pin_t pin) {
- palSetLineMode(pin, PAL_MODE_INPUT_ANALOG);
-
- return adc_read(pinToMux(pin));
-}
-
-int16_t analogReadPinAdc(pin_t pin, uint8_t adc) {
- palSetLineMode(pin, PAL_MODE_INPUT_ANALOG);
-
- adc_mux target = pinToMux(pin);
- target.adc = adc;
- return adc_read(target);
-}
-
-int16_t adc_read(adc_mux mux) {
-#if defined(USE_ADCV1)
- // TODO: fix previous assumption of only 1 input...
- adcConversionGroup.chselr = 1 << mux.input; /*no macro to convert N to ADC_CHSELR_CHSEL1*/
-#elif defined(USE_ADCV2)
- adcConversionGroup.sqr3 = ADC_SQR3_SQ1_N(mux.input);
-#else
- adcConversionGroup.sqr[0] = ADC_SQR1_SQ1_N(mux.input);
-#endif
-
- ADCDriver* targetDriver = intToADCDriver(mux.adc);
- if (!targetDriver) {
- return 0;
- }
-
- manageAdcInitializationDriver(mux.adc, targetDriver);
- if (adcConvert(targetDriver, &adcConversionGroup, &sampleBuffer[0], ADC_BUFFER_DEPTH) != MSG_OK) {
- return 0;
- }
-
-#ifdef USE_ADCV2
- // fake 12-bit -> N-bit scale
- return (*sampleBuffer) >> (12 - ADC_RESOLUTION);
-#else
- // already handled as part of adcConvert
- return *sampleBuffer;
-#endif
-}
diff --git a/drivers/chibios/analog.h b/drivers/chibios/analog.h
deleted file mode 100644
index e61c394265..0000000000
--- a/drivers/chibios/analog.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Copyright 2019 Drew Mills
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include "quantum.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- uint16_t input;
- uint8_t adc;
-} adc_mux;
-#define TO_MUX(i, a) \
- (adc_mux) { i, a }
-
-int16_t analogReadPin(pin_t pin);
-int16_t analogReadPinAdc(pin_t pin, uint8_t adc);
-adc_mux pinToMux(pin_t pin);
-
-int16_t adc_read(adc_mux mux);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/drivers/chibios/i2c_master.c b/drivers/chibios/i2c_master.c
deleted file mode 100644
index fc4bb2ab37..0000000000
--- a/drivers/chibios/i2c_master.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/* Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/* This library is only valid for STM32 processors.
- * This library follows the convention of the AVR i2c_master library.
- * As a result addresses are expected to be already shifted (addr << 1).
- * I2CD1 is the default driver which corresponds to pins B6 and B7. This
- * can be changed.
- * Please ensure that HAL_USE_I2C is TRUE in the halconf.h file and that
- * STM32_I2C_USE_I2C1 is TRUE in the mcuconf.h file. Pins B6 and B7 are used
- * but using any other I2C pins should be trivial.
- */
-#include "quantum.h"
-#include "i2c_master.h"
-#include
-#include
-
-static uint8_t i2c_address;
-
-static const I2CConfig i2cconfig = {
-#if defined(USE_I2CV1_CONTRIB)
- I2C1_CLOCK_SPEED,
-#elif defined(USE_I2CV1)
- I2C1_OPMODE,
- I2C1_CLOCK_SPEED,
- I2C1_DUTY_CYCLE,
-#else
- // This configures the I2C clock to 400khz assuming a 72Mhz clock
- // For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
- STM32_TIMINGR_PRESC(I2C1_TIMINGR_PRESC) | STM32_TIMINGR_SCLDEL(I2C1_TIMINGR_SCLDEL) | STM32_TIMINGR_SDADEL(I2C1_TIMINGR_SDADEL) | STM32_TIMINGR_SCLH(I2C1_TIMINGR_SCLH) | STM32_TIMINGR_SCLL(I2C1_TIMINGR_SCLL), 0, 0
-#endif
-};
-
-static i2c_status_t chibios_to_qmk(const msg_t* status) {
- switch (*status) {
- case I2C_NO_ERROR:
- return I2C_STATUS_SUCCESS;
- case I2C_TIMEOUT:
- return I2C_STATUS_TIMEOUT;
- // I2C_BUS_ERROR, I2C_ARBITRATION_LOST, I2C_ACK_FAILURE, I2C_OVERRUN, I2C_PEC_ERROR, I2C_SMB_ALERT
- default:
- return I2C_STATUS_ERROR;
- }
-}
-
-__attribute__((weak)) void i2c_init(void) {
- static bool is_initialised = false;
- if (!is_initialised) {
- is_initialised = true;
-
- // Try releasing special pins for a short time
- palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT);
- palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
-
- chThdSleepMilliseconds(10);
-#if defined(USE_GPIOV1)
- palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, I2C1_SCL_PAL_MODE);
- palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, I2C1_SDA_PAL_MODE);
-#else
- palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
- palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
-#endif
- }
-}
-
-i2c_status_t i2c_start(uint8_t address) {
- i2c_address = address;
- i2cStart(&I2C_DRIVER, &i2cconfig);
- return I2C_STATUS_SUCCESS;
-}
-
-i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_address = address;
- i2cStart(&I2C_DRIVER, &i2cconfig);
- msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, 0, 0, TIME_MS2I(timeout));
- return chibios_to_qmk(&status);
-}
-
-i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_address = address;
- i2cStart(&I2C_DRIVER, &i2cconfig);
- msg_t status = i2cMasterReceiveTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, TIME_MS2I(timeout));
- return chibios_to_qmk(&status);
-}
-
-i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_address = devaddr;
- i2cStart(&I2C_DRIVER, &i2cconfig);
-
- uint8_t complete_packet[length + 1];
- for (uint8_t i = 0; i < length; i++) {
- complete_packet[i + 1] = data[i];
- }
- complete_packet[0] = regaddr;
-
- msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), complete_packet, length + 1, 0, 0, TIME_MS2I(timeout));
- return chibios_to_qmk(&status);
-}
-
-i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
- i2c_address = devaddr;
- i2cStart(&I2C_DRIVER, &i2cconfig);
- msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), ®addr, 1, data, length, TIME_MS2I(timeout));
- return chibios_to_qmk(&status);
-}
-
-void i2c_stop(void) { i2cStop(&I2C_DRIVER); }
diff --git a/drivers/chibios/i2c_master.h b/drivers/chibios/i2c_master.h
deleted file mode 100644
index c68109acbd..0000000000
--- a/drivers/chibios/i2c_master.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/* Copyright 2018 Jack Humbert
- * Copyright 2018 Yiancar
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/* This library follows the convention of the AVR i2c_master library.
- * As a result addresses are expected to be already shifted (addr << 1).
- * I2CD1 is the default driver which corresponds to pins B6 and B7. This
- * can be changed.
- * Please ensure that HAL_USE_I2C is TRUE in the halconf.h file and that
- * STM32_I2C_USE_I2C1 is TRUE in the mcuconf.h file.
- */
-#pragma once
-
-#include
-#include
-
-#ifdef I2C1_BANK
-# define I2C1_SCL_BANK I2C1_BANK
-# define I2C1_SDA_BANK I2C1_BANK
-#endif
-
-#ifndef I2C1_SCL_BANK
-# define I2C1_SCL_BANK GPIOB
-#endif
-
-#ifndef I2C1_SDA_BANK
-# define I2C1_SDA_BANK GPIOB
-#endif
-
-#ifndef I2C1_SCL
-# define I2C1_SCL 6
-#endif
-#ifndef I2C1_SDA
-# define I2C1_SDA 7
-#endif
-
-#ifdef USE_I2CV1
-# ifndef I2C1_OPMODE
-# define I2C1_OPMODE OPMODE_I2C
-# endif
-# ifndef I2C1_CLOCK_SPEED
-# define I2C1_CLOCK_SPEED 100000 /* 400000 */
-# endif
-# ifndef I2C1_DUTY_CYCLE
-# define I2C1_DUTY_CYCLE STD_DUTY_CYCLE /* FAST_DUTY_CYCLE_2 */
-# endif
-#else
-// The default timing values below configures the I2C clock to 400khz assuming a 72Mhz clock
-// For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
-# ifndef I2C1_TIMINGR_PRESC
-# define I2C1_TIMINGR_PRESC 0U
-# endif
-# ifndef I2C1_TIMINGR_SCLDEL
-# define I2C1_TIMINGR_SCLDEL 7U
-# endif
-# ifndef I2C1_TIMINGR_SDADEL
-# define I2C1_TIMINGR_SDADEL 0U
-# endif
-# ifndef I2C1_TIMINGR_SCLH
-# define I2C1_TIMINGR_SCLH 38U
-# endif
-# ifndef I2C1_TIMINGR_SCLL
-# define I2C1_TIMINGR_SCLL 129U
-# endif
-#endif
-
-#ifndef I2C_DRIVER
-# define I2C_DRIVER I2CD1
-#endif
-
-#ifdef USE_GPIOV1
-# ifndef I2C1_SCL_PAL_MODE
-# define I2C1_SCL_PAL_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
-# endif
-# ifndef I2C1_SDA_PAL_MODE
-# define I2C1_SDA_PAL_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
-# endif
-#else
-// The default PAL alternate modes are used to signal that the pins are used for I2C
-# ifndef I2C1_SCL_PAL_MODE
-# define I2C1_SCL_PAL_MODE 4
-# endif
-# ifndef I2C1_SDA_PAL_MODE
-# define I2C1_SDA_PAL_MODE 4
-# endif
-#endif
-
-typedef int16_t i2c_status_t;
-
-#define I2C_STATUS_SUCCESS (0)
-#define I2C_STATUS_ERROR (-1)
-#define I2C_STATUS_TIMEOUT (-2)
-
-void i2c_init(void);
-i2c_status_t i2c_start(uint8_t address);
-i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout);
-i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
-i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
-i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
-void i2c_stop(void);
diff --git a/drivers/chibios/serial.c b/drivers/chibios/serial.c
deleted file mode 100644
index f54fbcee4e..0000000000
--- a/drivers/chibios/serial.c
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * WARNING: be careful changing this code, it is very timing dependent
- */
-
-#include "quantum.h"
-#include "serial.h"
-#include "wait.h"
-
-#include
-
-// TODO: resolve/remove build warnings
-#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT) && defined(PROTOCOL_CHIBIOS) && defined(WS2812_DRIVER_BITBANG)
-# warning "RGBLED_SPLIT not supported with bitbang WS2812 driver"
-#endif
-
-// default wait implementation cannot be called within interrupt
-// this method seems to be more accurate than GPT timers
-#if PORT_SUPPORTS_RT == FALSE
-# error "chSysPolledDelayX method not supported on this platform"
-#else
-# undef wait_us
-# define wait_us(x) chSysPolledDelayX(US2RTC(STM32_SYSCLK, x))
-#endif
-
-#ifndef SELECT_SOFT_SERIAL_SPEED
-# define SELECT_SOFT_SERIAL_SPEED 1
-// TODO: correct speeds...
-// 0: about 189kbps (Experimental only)
-// 1: about 137kbps (default)
-// 2: about 75kbps
-// 3: about 39kbps
-// 4: about 26kbps
-// 5: about 20kbps
-#endif
-
-// Serial pulse period in microseconds. At the moment, going lower than 12 causes communication failure
-#if SELECT_SOFT_SERIAL_SPEED == 0
-# define SERIAL_DELAY 12
-#elif SELECT_SOFT_SERIAL_SPEED == 1
-# define SERIAL_DELAY 16
-#elif SELECT_SOFT_SERIAL_SPEED == 2
-# define SERIAL_DELAY 24
-#elif SELECT_SOFT_SERIAL_SPEED == 3
-# define SERIAL_DELAY 32
-#elif SELECT_SOFT_SERIAL_SPEED == 4
-# define SERIAL_DELAY 48
-#elif SELECT_SOFT_SERIAL_SPEED == 5
-# define SERIAL_DELAY 64
-#else
-# error invalid SELECT_SOFT_SERIAL_SPEED value
-#endif
-
-inline static void serial_delay(void) { wait_us(SERIAL_DELAY); }
-inline static void serial_delay_half(void) { wait_us(SERIAL_DELAY / 2); }
-inline static void serial_delay_blip(void) { wait_us(1); }
-inline static void serial_output(void) { setPinOutput(SOFT_SERIAL_PIN); }
-inline static void serial_input(void) { setPinInputHigh(SOFT_SERIAL_PIN); }
-inline static bool serial_read_pin(void) { return !!readPin(SOFT_SERIAL_PIN); }
-inline static void serial_low(void) { writePinLow(SOFT_SERIAL_PIN); }
-inline static void serial_high(void) { writePinHigh(SOFT_SERIAL_PIN); }
-
-void interrupt_handler(void *arg);
-
-// Use thread + palWaitLineTimeout instead of palSetLineCallback
-// - Methods like setPinOutput and palEnableLineEvent/palDisableLineEvent
-// cause the interrupt to lock up, which would limit to only receiving data...
-static THD_WORKING_AREA(waThread1, 128);
-static THD_FUNCTION(Thread1, arg) {
- (void)arg;
- chRegSetThreadName("blinker");
- while (true) {
- palWaitLineTimeout(SOFT_SERIAL_PIN, TIME_INFINITE);
- interrupt_handler(NULL);
- }
-}
-
-void soft_serial_initiator_init(void) {
- serial_output();
- serial_high();
-}
-
-void soft_serial_target_init(void) {
- serial_input();
-
- palEnablePadEvent(PAL_PORT(SOFT_SERIAL_PIN), PAL_PAD(SOFT_SERIAL_PIN), PAL_EVENT_MODE_FALLING_EDGE);
- chThdCreateStatic(waThread1, sizeof(waThread1), HIGHPRIO, Thread1, NULL);
-}
-
-// Used by the master to synchronize timing with the slave.
-static void __attribute__((noinline)) sync_recv(void) {
- serial_input();
- // This shouldn't hang if the slave disconnects because the
- // serial line will float to high if the slave does disconnect.
- while (!serial_read_pin()) {
- }
-
- serial_delay();
-}
-
-// Used by the slave to send a synchronization signal to the master.
-static void __attribute__((noinline)) sync_send(void) {
- serial_output();
-
- serial_low();
- serial_delay();
-
- serial_high();
-}
-
-// Reads a byte from the serial line
-static uint8_t __attribute__((noinline)) serial_read_byte(void) {
- uint8_t byte = 0;
- serial_input();
- for (uint8_t i = 0; i < 8; ++i) {
- byte = (byte << 1) | serial_read_pin();
- serial_delay();
- }
-
- return byte;
-}
-
-// Sends a byte with MSB ordering
-static void __attribute__((noinline)) serial_write_byte(uint8_t data) {
- uint8_t b = 8;
- serial_output();
- while (b--) {
- if (data & (1 << b)) {
- serial_high();
- } else {
- serial_low();
- }
- serial_delay();
- }
-}
-
-// interrupt handle to be used by the slave device
-void interrupt_handler(void *arg) {
- chSysLockFromISR();
-
- sync_send();
-
- // read mid pulses
- serial_delay_blip();
-
- uint8_t checksum_computed = 0;
- int sstd_index = 0;
-
- sstd_index = serial_read_byte();
- sync_send();
-
- split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
- for (int i = 0; i < trans->initiator2target_buffer_size; ++i) {
- split_trans_initiator2target_buffer(trans)[i] = serial_read_byte();
- sync_send();
- checksum_computed += split_trans_initiator2target_buffer(trans)[i];
- }
- checksum_computed ^= 7;
- uint8_t checksum_received = serial_read_byte();
- sync_send();
-
- // wait for the sync to finish sending
- serial_delay();
-
- // Allow any slave processing to occur
- if (trans->slave_callback) {
- trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
- }
-
- uint8_t checksum = 0;
- for (int i = 0; i < trans->target2initiator_buffer_size; ++i) {
- serial_write_byte(split_trans_target2initiator_buffer(trans)[i]);
- sync_send();
- serial_delay_half();
- checksum += split_trans_target2initiator_buffer(trans)[i];
- }
- serial_write_byte(checksum ^ 7);
- sync_send();
-
- // wait for the sync to finish sending
- serial_delay();
-
- *trans->status = (checksum_computed == checksum_received) ? TRANSACTION_ACCEPTED : TRANSACTION_DATA_ERROR;
-
- // end transaction
- serial_input();
-
- // TODO: remove extra delay between transactions
- serial_delay();
-
- chSysUnlockFromISR();
-}
-
-/////////
-// start transaction by initiator
-//
-// int soft_serial_transaction(int sstd_index)
-//
-// Returns:
-// TRANSACTION_END
-// TRANSACTION_NO_RESPONSE
-// TRANSACTION_DATA_ERROR
-// this code is very time dependent, so we need to disable interrupts
-int soft_serial_transaction(int sstd_index) {
- if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
- split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
- if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
-
- // TODO: remove extra delay between transactions
- serial_delay();
-
- // this code is very time dependent, so we need to disable interrupts
- chSysLock();
-
- // signal to the slave that we want to start a transaction
- serial_output();
- serial_low();
- serial_delay_blip();
-
- // wait for the slaves response
- serial_input();
- serial_high();
- serial_delay();
-
- // check if the slave is present
- if (serial_read_pin()) {
- // slave failed to pull the line low, assume not present
- dprintf("serial::NO_RESPONSE\n");
- chSysUnlock();
- return TRANSACTION_NO_RESPONSE;
- }
-
- // if the slave is present syncronize with it
-
- uint8_t checksum = 0;
- // send data to the slave
- serial_write_byte(sstd_index); // first chunk is transaction id
- sync_recv();
-
- for (int i = 0; i < trans->initiator2target_buffer_size; ++i) {
- serial_write_byte(split_trans_initiator2target_buffer(trans)[i]);
- sync_recv();
- checksum += split_trans_initiator2target_buffer(trans)[i];
- }
- serial_write_byte(checksum ^ 7);
- sync_recv();
-
- serial_delay();
- serial_delay(); // read mid pulses
-
- // receive data from the slave
- uint8_t checksum_computed = 0;
- for (int i = 0; i < trans->target2initiator_buffer_size; ++i) {
- split_trans_target2initiator_buffer(trans)[i] = serial_read_byte();
- sync_recv();
- checksum_computed += split_trans_target2initiator_buffer(trans)[i];
- }
- checksum_computed ^= 7;
- uint8_t checksum_received = serial_read_byte();
-
- sync_recv();
- serial_delay();
-
- if ((checksum_computed) != (checksum_received)) {
- dprintf("serial::FAIL[%u,%u,%u]\n", checksum_computed, checksum_received, sstd_index);
- serial_output();
- serial_high();
-
- chSysUnlock();
- return TRANSACTION_DATA_ERROR;
- }
-
- // always, release the line when not in use
- serial_high();
- serial_output();
-
- chSysUnlock();
- return TRANSACTION_END;
-}
diff --git a/drivers/chibios/serial_usart.c b/drivers/chibios/serial_usart.c
deleted file mode 100644
index ea4473791c..0000000000
--- a/drivers/chibios/serial_usart.c
+++ /dev/null
@@ -1,318 +0,0 @@
-/* Copyright 2021 QMK
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "serial_usart.h"
-
-#if defined(SERIAL_USART_CONFIG)
-static SerialConfig serial_config = SERIAL_USART_CONFIG;
-#else
-static SerialConfig serial_config = {
- .speed = (SERIAL_USART_SPEED), /* speed - mandatory */
- .cr1 = (SERIAL_USART_CR1),
- .cr2 = (SERIAL_USART_CR2),
-# if !defined(SERIAL_USART_FULL_DUPLEX)
- .cr3 = ((SERIAL_USART_CR3) | USART_CR3_HDSEL) /* activate half-duplex mode */
-# else
- .cr3 = (SERIAL_USART_CR3)
-# endif
-};
-#endif
-
-static SerialDriver* serial_driver = &SERIAL_USART_DRIVER;
-
-static inline bool react_to_transactions(void);
-static inline bool __attribute__((nonnull)) receive(uint8_t* destination, const size_t size);
-static inline bool __attribute__((nonnull)) send(const uint8_t* source, const size_t size);
-static inline int initiate_transaction(uint8_t sstd_index);
-static inline void usart_clear(void);
-
-/**
- * @brief Clear the receive input queue.
- */
-static inline void usart_clear(void) {
- osalSysLock();
- bool volatile queue_not_empty = !iqIsEmptyI(&serial_driver->iqueue);
- osalSysUnlock();
-
- while (queue_not_empty) {
- osalSysLock();
- /* Hard reset the input queue. */
- iqResetI(&serial_driver->iqueue);
- osalSysUnlock();
- /* Allow pending interrupts to preempt.
- * Do not merge the lock/unlock blocks into one
- * or the code will not work properly.
- * The empty read adds a tiny amount of delay. */
- (void)queue_not_empty;
- osalSysLock();
- queue_not_empty = !iqIsEmptyI(&serial_driver->iqueue);
- osalSysUnlock();
- }
-}
-
-/**
- * @brief Blocking send of buffer with timeout.
- *
- * @return true Send success.
- * @return false Send failed.
- */
-static inline bool send(const uint8_t* source, const size_t size) {
- bool success = (size_t)sdWriteTimeout(serial_driver, source, size, TIME_MS2I(SERIAL_USART_TIMEOUT)) == size;
-
-#if !defined(SERIAL_USART_FULL_DUPLEX)
- if (success) {
- /* Half duplex fills the input queue with the data we wrote - just throw it away.
- Under the right circumstances (e.g. bad cables paired with high baud rates)
- less bytes can be present in the input queue, therefore a timeout is needed. */
- uint8_t dump[size];
- return receive(dump, size);
- }
-#endif
-
- return success;
-}
-
-/**
- * @brief Blocking receive of size * bytes with timeout.
- *
- * @return true Receive success.
- * @return false Receive failed.
- */
-static inline bool receive(uint8_t* destination, const size_t size) {
- bool success = (size_t)sdReadTimeout(serial_driver, destination, size, TIME_MS2I(SERIAL_USART_TIMEOUT)) == size;
- return success;
-}
-
-#if !defined(SERIAL_USART_FULL_DUPLEX)
-
-/**
- * @brief Initiate pins for USART peripheral. Half-duplex configuration.
- */
-__attribute__((weak)) void usart_init(void) {
-# if defined(MCU_STM32)
-# if defined(USE_GPIOV1)
- palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
-# else
- palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
-# endif
-
-# if defined(USART_REMAP)
- USART_REMAP;
-# endif
-# else
-# pragma message "usart_init: MCU Familiy not supported by default, please supply your own init code by implementing usart_init() in your keyboard files."
-# endif
-}
-
-#else
-
-/**
- * @brief Initiate pins for USART peripheral. Full-duplex configuration.
- */
-__attribute__((weak)) void usart_init(void) {
-# if defined(MCU_STM32)
-# if defined(USE_GPIOV1)
- palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
- palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);
-# else
- palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_TX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
- palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE(SERIAL_USART_RX_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
-# endif
-
-# if defined(USART_REMAP)
- USART_REMAP;
-# endif
-# else
-# pragma message "usart_init: MCU Familiy not supported by default, please supply your own init code by implementing usart_init() in your keyboard files."
-# endif
-}
-
-#endif
-
-/**
- * @brief Overridable master specific initializations.
- */
-__attribute__((weak, nonnull)) void usart_master_init(SerialDriver** driver) {
- (void)driver;
- usart_init();
-}
-
-/**
- * @brief Overridable slave specific initializations.
- */
-__attribute__((weak, nonnull)) void usart_slave_init(SerialDriver** driver) {
- (void)driver;
- usart_init();
-}
-
-/**
- * @brief This thread runs on the slave and responds to transactions initiated
- * by the master.
- */
-static THD_WORKING_AREA(waSlaveThread, 1024);
-static THD_FUNCTION(SlaveThread, arg) {
- (void)arg;
- chRegSetThreadName("usart_tx_rx");
-
- while (true) {
- if (!react_to_transactions()) {
- /* Clear the receive queue, to start with a clean slate.
- * Parts of failed transactions or spurious bytes could still be in it. */
- usart_clear();
- }
- }
-}
-
-/**
- * @brief Slave specific initializations.
- */
-void soft_serial_target_init(void) {
- usart_slave_init(&serial_driver);
-
- sdStart(serial_driver, &serial_config);
-
- /* Start transport thread. */
- chThdCreateStatic(waSlaveThread, sizeof(waSlaveThread), HIGHPRIO, SlaveThread, NULL);
-}
-
-/**
- * @brief React to transactions started by the master.
- */
-static inline bool react_to_transactions(void) {
- /* Wait until there is a transaction for us. */
- uint8_t sstd_index = (uint8_t)sdGet(serial_driver);
-
- /* Sanity check that we are actually responding to a valid transaction. */
- if (sstd_index >= NUM_TOTAL_TRANSACTIONS) {
- return false;
- }
-
- split_transaction_desc_t* trans = &split_transaction_table[sstd_index];
-
- /* Send back the handshake which is XORed as a simple checksum,
- to signal that the slave is ready to receive possible transaction buffers */
- sstd_index ^= HANDSHAKE_MAGIC;
- if (!send(&sstd_index, sizeof(sstd_index))) {
- *trans->status = TRANSACTION_DATA_ERROR;
- return false;
- }
-
- /* Receive transaction buffer from the master. If this transaction requires it.*/
- if (trans->initiator2target_buffer_size) {
- if (!receive(split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
- *trans->status = TRANSACTION_DATA_ERROR;
- return false;
- }
- }
-
- /* Allow any slave processing to occur. */
- if (trans->slave_callback) {
- trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, split_trans_target2initiator_buffer(trans));
- }
-
- /* Send transaction buffer to the master. If this transaction requires it. */
- if (trans->target2initiator_buffer_size) {
- if (!send(split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
- *trans->status = TRANSACTION_DATA_ERROR;
- return false;
- }
- }
-
- *trans->status = TRANSACTION_ACCEPTED;
- return true;
-}
-
-/**
- * @brief Master specific initializations.
- */
-void soft_serial_initiator_init(void) {
- usart_master_init(&serial_driver);
-
-#if defined(MCU_STM32) && defined(SERIAL_USART_PIN_SWAP)
- serial_config.cr2 |= USART_CR2_SWAP; // master has swapped TX/RX pins
-#endif
-
- sdStart(serial_driver, &serial_config);
-}
-
-/**
- * @brief Start transaction from the master half to the slave half.
- *
- * @param index Transaction Table index of the transaction to start.
- * @return int TRANSACTION_NO_RESPONSE in case of Timeout.
- * TRANSACTION_TYPE_ERROR in case of invalid transaction index.
- * TRANSACTION_END in case of success.
- */
-int soft_serial_transaction(int index) {
- /* Clear the receive queue, to start with a clean slate.
- * Parts of failed transactions or spurious bytes could still be in it. */
- usart_clear();
- return initiate_transaction((uint8_t)index);
-}
-
-/**
- * @brief Initiate transaction to slave half.
- */
-static inline int initiate_transaction(uint8_t sstd_index) {
- /* Sanity check that we are actually starting a valid transaction. */
- if (sstd_index >= NUM_TOTAL_TRANSACTIONS) {
- dprintln("USART: Illegal transaction Id.");
- return TRANSACTION_TYPE_ERROR;
- }
-
- split_transaction_desc_t* trans = &split_transaction_table[sstd_index];
-
- /* Transaction is not registered. Abort. */
- if (!trans->status) {
- dprintln("USART: Transaction not registered.");
- return TRANSACTION_TYPE_ERROR;
- }
-
- /* Send transaction table index to the slave, which doubles as basic handshake token. */
- if (!send(&sstd_index, sizeof(sstd_index))) {
- dprintln("USART: Send Handshake failed.");
- return TRANSACTION_TYPE_ERROR;
- }
-
- uint8_t sstd_index_shake = 0xFF;
-
- /* Which we always read back first so that we can error out correctly.
- * - due to the half duplex limitations on return codes, we always have to read *something*.
- * - without the read, write only transactions *always* succeed, even during the boot process where the slave is not ready.
- */
- if (!receive(&sstd_index_shake, sizeof(sstd_index_shake)) || (sstd_index_shake != (sstd_index ^ HANDSHAKE_MAGIC))) {
- dprintln("USART: Handshake failed.");
- return TRANSACTION_NO_RESPONSE;
- }
-
- /* Send transaction buffer to the slave. If this transaction requires it. */
- if (trans->initiator2target_buffer_size) {
- if (!send(split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
- dprintln("USART: Send failed.");
- return TRANSACTION_NO_RESPONSE;
- }
- }
-
- /* Receive transaction buffer from the slave. If this transaction requires it. */
- if (trans->target2initiator_buffer_size) {
- if (!receive(split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
- dprintln("USART: Receive failed.");
- return TRANSACTION_NO_RESPONSE;
- }
- }
-
- return TRANSACTION_END;
-}
diff --git a/drivers/chibios/serial_usart.h b/drivers/chibios/serial_usart.h
deleted file mode 100644
index c64e15566f..0000000000
--- a/drivers/chibios/serial_usart.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/* Copyright 2021 QMK
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include "quantum.h"
-#include "serial.h"
-#include "printf.h"
-
-#include
-#include
-
-#if !defined(SERIAL_USART_DRIVER)
-# define SERIAL_USART_DRIVER SD1
-#endif
-
-#if !defined(USE_GPIOV1)
-/* The default PAL alternate modes are used to signal that the pins are used for USART. */
-# if !defined(SERIAL_USART_TX_PAL_MODE)
-# define SERIAL_USART_TX_PAL_MODE 7
-# endif
-# if !defined(SERIAL_USART_RX_PAL_MODE)
-# define SERIAL_USART_RX_PAL_MODE 7
-# endif
-#endif
-
-#if defined(SOFT_SERIAL_PIN)
-# define SERIAL_USART_TX_PIN SOFT_SERIAL_PIN
-#endif
-
-#if !defined(SERIAL_USART_TX_PIN)
-# define SERIAL_USART_TX_PIN A9
-#endif
-
-#if !defined(SERIAL_USART_RX_PIN)
-# define SERIAL_USART_RX_PIN A10
-#endif
-
-#if !defined(USART_CR1_M0)
-# define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so
-#endif
-
-#if !defined(SERIAL_USART_CR1)
-# define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length
-#endif
-
-#if !defined(SERIAL_USART_CR2)
-# define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits
-#endif
-
-#if !defined(SERIAL_USART_CR3)
-# define SERIAL_USART_CR3 0
-#endif
-
-#if defined(USART1_REMAP)
-# define USART_REMAP \
- do { \
- (AFIO->MAPR |= AFIO_MAPR_USART1_REMAP); \
- } while (0)
-#elif defined(USART2_REMAP)
-# define USART_REMAP \
- do { \
- (AFIO->MAPR |= AFIO_MAPR_USART2_REMAP); \
- } while (0)
-#elif defined(USART3_PARTIALREMAP)
-# define USART_REMAP \
- do { \
- (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP); \
- } while (0)
-#elif defined(USART3_FULLREMAP)
-# define USART_REMAP \
- do { \
- (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); \
- } while (0)
-#endif
-
-#if !defined(SELECT_SOFT_SERIAL_SPEED)
-# define SELECT_SOFT_SERIAL_SPEED 1
-#endif
-
-#if defined(SERIAL_USART_SPEED)
-// Allow advanced users to directly set SERIAL_USART_SPEED
-#elif SELECT_SOFT_SERIAL_SPEED == 0
-# define SERIAL_USART_SPEED 460800
-#elif SELECT_SOFT_SERIAL_SPEED == 1
-# define SERIAL_USART_SPEED 230400
-#elif SELECT_SOFT_SERIAL_SPEED == 2
-# define SERIAL_USART_SPEED 115200
-#elif SELECT_SOFT_SERIAL_SPEED == 3
-# define SERIAL_USART_SPEED 57600
-#elif SELECT_SOFT_SERIAL_SPEED == 4
-# define SERIAL_USART_SPEED 38400
-#elif SELECT_SOFT_SERIAL_SPEED == 5
-# define SERIAL_USART_SPEED 19200
-#else
-# error invalid SELECT_SOFT_SERIAL_SPEED value
-#endif
-
-#if !defined(SERIAL_USART_TIMEOUT)
-# define SERIAL_USART_TIMEOUT 100
-#endif
-
-#define HANDSHAKE_MAGIC 7
diff --git a/drivers/chibios/spi_master.c b/drivers/chibios/spi_master.c
deleted file mode 100644
index 28ddcbb2ba..0000000000
--- a/drivers/chibios/spi_master.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/* Copyright 2020 Nick Brassel (tzarc)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "spi_master.h"
-
-#include "timer.h"
-
-static pin_t currentSlavePin = NO_PIN;
-
-#if defined(K20x) || defined(KL2x)
-static SPIConfig spiConfig = {NULL, 0, 0, 0};
-#else
-static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0};
-#endif
-
-__attribute__((weak)) void spi_init(void) {
- static bool is_initialised = false;
- if (!is_initialised) {
- is_initialised = true;
-
- // Try releasing special pins for a short time
- setPinInput(SPI_SCK_PIN);
- setPinInput(SPI_MOSI_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);
-#else
- 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);
- 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);
- 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);
-#endif
- }
-}
-
-bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) {
- if (currentSlavePin != NO_PIN || slavePin == NO_PIN) {
- return false;
- }
-
- uint16_t roundedDivisor = 2;
- while (roundedDivisor < divisor) {
- roundedDivisor <<= 1;
- }
-
- if (roundedDivisor < 2 || roundedDivisor > 256) {
- return false;
- }
-
-#if defined(K20x) || defined(KL2x)
- spiConfig.tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(1);
-
- if (lsbFirst) {
- spiConfig.tar0 |= SPIx_CTARn_LSBFE;
- }
-
- switch (mode) {
- case 0:
- break;
- case 1:
- spiConfig.tar0 |= SPIx_CTARn_CPHA;
- break;
- case 2:
- spiConfig.tar0 |= SPIx_CTARn_CPOL;
- break;
- case 3:
- spiConfig.tar0 |= SPIx_CTARn_CPHA | SPIx_CTARn_CPOL;
- break;
- }
-
- switch (roundedDivisor) {
- case 2:
- spiConfig.tar0 |= SPIx_CTARn_BR(0);
- break;
- case 4:
- spiConfig.tar0 |= SPIx_CTARn_BR(1);
- break;
- case 8:
- spiConfig.tar0 |= SPIx_CTARn_BR(3);
- break;
- case 16:
- spiConfig.tar0 |= SPIx_CTARn_BR(4);
- break;
- case 32:
- spiConfig.tar0 |= SPIx_CTARn_BR(5);
- break;
- case 64:
- spiConfig.tar0 |= SPIx_CTARn_BR(6);
- break;
- case 128:
- spiConfig.tar0 |= SPIx_CTARn_BR(7);
- break;
- case 256:
- spiConfig.tar0 |= SPIx_CTARn_BR(8);
- break;
- }
-#else
- spiConfig.cr1 = 0;
-
- if (lsbFirst) {
- spiConfig.cr1 |= SPI_CR1_LSBFIRST;
- }
-
- switch (mode) {
- case 0:
- break;
- case 1:
- spiConfig.cr1 |= SPI_CR1_CPHA;
- break;
- case 2:
- spiConfig.cr1 |= SPI_CR1_CPOL;
- break;
- case 3:
- spiConfig.cr1 |= SPI_CR1_CPHA | SPI_CR1_CPOL;
- break;
- }
-
- switch (roundedDivisor) {
- case 2:
- break;
- case 4:
- spiConfig.cr1 |= SPI_CR1_BR_0;
- break;
- case 8:
- spiConfig.cr1 |= SPI_CR1_BR_1;
- break;
- case 16:
- spiConfig.cr1 |= SPI_CR1_BR_1 | SPI_CR1_BR_0;
- break;
- case 32:
- spiConfig.cr1 |= SPI_CR1_BR_2;
- break;
- case 64:
- spiConfig.cr1 |= SPI_CR1_BR_2 | SPI_CR1_BR_0;
- break;
- case 128:
- spiConfig.cr1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1;
- break;
- case 256:
- spiConfig.cr1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0;
- break;
- }
-#endif
-
- currentSlavePin = slavePin;
- spiConfig.ssport = PAL_PORT(slavePin);
- spiConfig.sspad = PAL_PAD(slavePin);
-
- setPinOutput(slavePin);
- spiStart(&SPI_DRIVER, &spiConfig);
- spiSelect(&SPI_DRIVER);
-
- return true;
-}
-
-spi_status_t spi_write(uint8_t data) {
- uint8_t rxData;
- spiExchange(&SPI_DRIVER, 1, &data, &rxData);
-
- return rxData;
-}
-
-spi_status_t spi_read(void) {
- uint8_t data = 0;
- spiReceive(&SPI_DRIVER, 1, &data);
-
- return data;
-}
-
-spi_status_t spi_transmit(const uint8_t *data, uint16_t length) {
- spiSend(&SPI_DRIVER, length, data);
- return SPI_STATUS_SUCCESS;
-}
-
-spi_status_t spi_receive(uint8_t *data, uint16_t length) {
- spiReceive(&SPI_DRIVER, length, data);
- return SPI_STATUS_SUCCESS;
-}
-
-void spi_stop(void) {
- if (currentSlavePin != NO_PIN) {
- spiUnselect(&SPI_DRIVER);
- spiStop(&SPI_DRIVER);
- currentSlavePin = NO_PIN;
- }
-}
diff --git a/drivers/chibios/spi_master.h b/drivers/chibios/spi_master.h
deleted file mode 100644
index b5a6ef1437..0000000000
--- a/drivers/chibios/spi_master.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/* Copyright 2020 Nick Brassel (tzarc)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-#include
-
-#include "gpio.h"
-#include "chibios_config.h"
-
-#ifndef SPI_DRIVER
-# define SPI_DRIVER SPID2
-#endif
-
-#ifndef SPI_SCK_PIN
-# define SPI_SCK_PIN B13
-#endif
-
-#ifndef SPI_SCK_PAL_MODE
-# if defined(USE_GPIOV1)
-# define SPI_SCK_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
-# else
-# define SPI_SCK_PAL_MODE 5
-# endif
-#endif
-
-#ifndef SPI_MOSI_PIN
-# define SPI_MOSI_PIN B15
-#endif
-
-#ifndef SPI_MOSI_PAL_MODE
-# if defined(USE_GPIOV1)
-# define SPI_MOSI_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
-# else
-# define SPI_MOSI_PAL_MODE 5
-# endif
-#endif
-
-#ifndef SPI_MISO_PIN
-# define SPI_MISO_PIN B14
-#endif
-
-#ifndef SPI_MISO_PAL_MODE
-# if defined(USE_GPIOV1)
-# define SPI_MISO_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
-# else
-# define SPI_MISO_PAL_MODE 5
-# endif
-#endif
-
-typedef int16_t spi_status_t;
-
-#define SPI_STATUS_SUCCESS (0)
-#define SPI_STATUS_ERROR (-1)
-#define SPI_STATUS_TIMEOUT (-2)
-
-#define SPI_TIMEOUT_IMMEDIATE (0)
-#define SPI_TIMEOUT_INFINITE (0xFFFF)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-void spi_init(void);
-
-bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor);
-
-spi_status_t spi_write(uint8_t data);
-
-spi_status_t spi_read(void);
-
-spi_status_t spi_transmit(const uint8_t *data, uint16_t length);
-
-spi_status_t spi_receive(uint8_t *data, uint16_t length);
-
-void spi_stop(void);
-#ifdef __cplusplus
-}
-#endif
diff --git a/drivers/chibios/uart.c b/drivers/chibios/uart.c
deleted file mode 100644
index 030335b342..0000000000
--- a/drivers/chibios/uart.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Copyright 2021
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "uart.h"
-
-#include "quantum.h"
-
-static SerialConfig serialConfig = {SERIAL_DEFAULT_BITRATE, SD1_CR1, SD1_CR2, SD1_CR3};
-
-void uart_init(uint32_t baud) {
- static bool is_initialised = false;
-
- if (!is_initialised) {
- is_initialised = true;
-
- serialConfig.speed = baud;
-
-#if defined(USE_GPIOV1)
- palSetLineMode(SD1_TX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
- palSetLineMode(SD1_RX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
-#else
- palSetLineMode(SD1_TX_PIN, PAL_MODE_ALTERNATE(SD1_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
- palSetLineMode(SD1_RX_PIN, PAL_MODE_ALTERNATE(SD1_RX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
-#endif
- sdStart(&SERIAL_DRIVER, &serialConfig);
- }
-}
-
-void uart_putchar(uint8_t c) { sdPut(&SERIAL_DRIVER, c); }
-
-uint8_t uart_getchar(void) {
- msg_t res = sdGet(&SERIAL_DRIVER);
-
- return (uint8_t)res;
-}
-
-bool uart_available(void) { return !sdGetWouldBlock(&SERIAL_DRIVER); }
diff --git a/drivers/chibios/uart.h b/drivers/chibios/uart.h
deleted file mode 100644
index b4e20e9fd3..0000000000
--- a/drivers/chibios/uart.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* Copyright 2021
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-
-#include
-
-#ifndef SERIAL_DRIVER
-# define SERIAL_DRIVER SD1
-#endif
-
-#ifndef SD1_TX_PIN
-# define SD1_TX_PIN A9
-#endif
-
-#ifndef SD1_TX_PAL_MODE
-# define SD1_TX_PAL_MODE 7
-#endif
-
-#ifndef SD1_RX_PIN
-# define SD1_RX_PIN A10
-#endif
-
-#ifndef SD1_RX_PAL_MODE
-# define SD1_RX_PAL_MODE 7
-#endif
-
-#ifndef SD1_CTS_PIN
-# define SD1_CTS_PIN A11
-#endif
-
-#ifndef SD1_CTS_PAL_MODE
-# define SD1_CTS_PAL_MODE 7
-#endif
-
-#ifndef SD1_RTS_PIN
-# define SD1_RTS_PIN A12
-#endif
-
-#ifndef SD1_RTS_PAL_MODE
-# define SD1_RTS_PAL_MODE 7
-#endif
-
-#ifndef SD1_CR1
-# define SD1_CR1 0
-#endif
-
-#ifndef SD1_CR2
-# define SD1_CR2 0
-#endif
-
-#ifndef SD1_CR3
-# define SD1_CR3 0
-#endif
-
-void uart_init(uint32_t baud);
-
-void uart_putchar(uint8_t c);
-
-uint8_t uart_getchar(void);
-
-bool uart_available(void);
diff --git a/drivers/chibios/usbpd_stm32g4.c b/drivers/chibios/usbpd_stm32g4.c
deleted file mode 100644
index f16ca8aeae..0000000000
--- a/drivers/chibios/usbpd_stm32g4.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/* Copyright 2021 Nick Brassel (@tzarc)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include
-
-#ifndef USBPD_UCPD1_CFG1
-# define USBPD_UCPD1_CFG1 (UCPD_CFG1_PSC_UCPDCLK_0 | UCPD_CFG1_TRANSWIN_3 | UCPD_CFG1_IFRGAP_4 | UCPD_CFG1_HBITCLKDIV_4)
-#endif // USBPD_UCPD1_CFG1
-
-// Initialises the USBPD subsystem
-__attribute__((weak)) void usbpd_init(void) {
- // Disable dead-battery signals
- PWR->CR3 |= PWR_CR3_UCPD_DBDIS;
- // Enable the clock for the UCPD1 peripheral
- RCC->APB1ENR2 |= RCC_APB1ENR2_UCPD1EN;
-
- // Copy the existing value
- uint32_t CFG1 = UCPD1->CFG1;
- // Force-disable UCPD1 before configuring
- CFG1 &= ~UCPD_CFG1_UCPDEN;
- // Configure UCPD1
- CFG1 = USBPD_UCPD1_CFG1;
- // Apply the changes
- UCPD1->CFG1 = CFG1;
- // Enable UCPD1
- UCPD1->CFG1 |= UCPD_CFG1_UCPDEN;
-
- // Copy the existing value
- uint32_t CR = UCPD1->CR;
- // Clear out ANASUBMODE (irrelevant as a sink device)
- CR &= ~UCPD_CR_ANASUBMODE_Msk;
- // Advertise our capabilities as a sink, with both CC lines enabled
- CR |= UCPD_CR_ANAMODE | UCPD_CR_CCENABLE_Msk;
- // Apply the changes
- UCPD1->CR = CR;
-}
-
-// Gets the current state of the USBPD allowance
-__attribute__((weak)) usbpd_allowance_t usbpd_get_allowance(void) {
- uint32_t CR = UCPD1->CR;
-
- int ucpd_enabled = (UCPD1->CFG1 & UCPD_CFG1_UCPDEN_Msk) >> UCPD_CFG1_UCPDEN_Pos;
- int anamode = (CR & UCPD_CR_ANAMODE_Msk) >> UCPD_CR_ANAMODE_Pos;
- int cc_enabled = (CR & UCPD_CR_CCENABLE_Msk) >> UCPD_CR_CCENABLE_Pos;
-
- if (ucpd_enabled && anamode && cc_enabled) {
- uint32_t SR = UCPD1->SR;
- int vstate_cc1 = (SR & UCPD_SR_TYPEC_VSTATE_CC1_Msk) >> UCPD_SR_TYPEC_VSTATE_CC1_Pos;
- int vstate_cc2 = (SR & UCPD_SR_TYPEC_VSTATE_CC2_Msk) >> UCPD_SR_TYPEC_VSTATE_CC2_Pos;
- int vstate_max = vstate_cc1 > vstate_cc2 ? vstate_cc1 : vstate_cc2;
- switch (vstate_max) {
- case 0:
- case 1:
- return USBPD_500MA; // Note that this is 500mA (i.e. max USB 2.0), not 900mA, as we're not using USB 3.1 as a sink device.
- case 2:
- return USBPD_1500MA;
- case 3:
- return USBPD_3000MA;
- }
- }
-
- return USBPD_500MA;
-}
\ No newline at end of file
diff --git a/drivers/chibios/ws2812.c b/drivers/chibios/ws2812.c
deleted file mode 100644
index 0d12e2fb79..0000000000
--- a/drivers/chibios/ws2812.c
+++ /dev/null
@@ -1,114 +0,0 @@
-#include "quantum.h"
-#include "ws2812.h"
-#include
-#include
-
-/* Adapted from https://github.com/bigjosh/SimpleNeoPixelDemo/ */
-
-#ifndef NOP_FUDGE
-# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX)
-# define NOP_FUDGE 0.4
-# else
-# error("NOP_FUDGE configuration required")
-# define NOP_FUDGE 1 // this just pleases the compile so the above error is easier to spot
-# endif
-#endif
-
-// Push Pull or Open Drain Configuration
-// Default Push Pull
-#ifndef WS2812_EXTERNAL_PULLUP
-# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_PUSHPULL
-#else
-# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_OPENDRAIN
-#endif
-
-#define NUMBER_NOPS 6
-#define CYCLES_PER_SEC (STM32_SYSCLK / NUMBER_NOPS * NOP_FUDGE)
-#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
-#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC)
-#define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE)
-
-#define wait_ns(x) \
- do { \
- for (int i = 0; i < NS_TO_CYCLES(x); i++) { \
- __asm__ volatile("nop\n\t" \
- "nop\n\t" \
- "nop\n\t" \
- "nop\n\t" \
- "nop\n\t" \
- "nop\n\t"); \
- } \
- } while (0)
-
-// These are the timing constraints taken mostly from the WS2812 datasheets
-// These are chosen to be conservative and avoid problems rather than for maximum throughput
-
-#define T1H 900 // Width of a 1 bit in ns
-#define T1L (1250 - T1H) // Width of a 1 bit in ns
-
-#define T0H 350 // Width of a 0 bit in ns
-#define T0L (1250 - T0H) // Width of a 0 bit in ns
-
-// The reset gap can be 6000 ns, but depending on the LED strip it may have to be increased
-// to values like 600000 ns. If it is too small, the pixels will show nothing most of the time.
-#define RES (1000 * WS2812_TRST_US) // Width of the low gap between bits to cause a frame to latch
-
-void sendByte(uint8_t byte) {
- // WS2812 protocol wants most significant bits first
- for (unsigned char bit = 0; bit < 8; bit++) {
- bool is_one = byte & (1 << (7 - bit));
- // using something like wait_ns(is_one ? T1L : T0L) here throws off timings
- if (is_one) {
- // 1
- writePinHigh(RGB_DI_PIN);
- wait_ns(T1H);
- writePinLow(RGB_DI_PIN);
- wait_ns(T1L);
- } else {
- // 0
- writePinHigh(RGB_DI_PIN);
- wait_ns(T0H);
- writePinLow(RGB_DI_PIN);
- wait_ns(T0L);
- }
- }
-}
-
-void ws2812_init(void) { palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); }
-
-// Setleds for standard RGB
-void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
- static bool s_init = false;
- if (!s_init) {
- ws2812_init();
- s_init = true;
- }
-
- // this code is very time dependent, so we need to disable interrupts
- chSysLock();
-
- for (uint8_t i = 0; i < leds; i++) {
- // WS2812 protocol dictates grb order
-#if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
- sendByte(ledarray[i].g);
- sendByte(ledarray[i].r);
- sendByte(ledarray[i].b);
-#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB)
- sendByte(ledarray[i].r);
- sendByte(ledarray[i].g);
- sendByte(ledarray[i].b);
-#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
- sendByte(ledarray[i].b);
- sendByte(ledarray[i].g);
- sendByte(ledarray[i].r);
-#endif
-
-#ifdef RGBW
- sendByte(ledarray[i].w);
-#endif
- }
-
- wait_ns(RES);
-
- chSysUnlock();
-}
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c
deleted file mode 100644
index e6af55b6b3..0000000000
--- a/drivers/chibios/ws2812_pwm.c
+++ /dev/null
@@ -1,311 +0,0 @@
-#include "ws2812.h"
-#include "quantum.h"
-#include
-
-/* Adapted from https://github.com/joewa/WS2812-LED-Driver_ChibiOS/ */
-
-#ifdef RGBW
-# error "RGBW not supported"
-#endif
-
-#ifndef WS2812_PWM_DRIVER
-# define WS2812_PWM_DRIVER PWMD2 // TIMx
-#endif
-#ifndef WS2812_PWM_CHANNEL
-# define WS2812_PWM_CHANNEL 2 // Channel
-#endif
-#ifndef WS2812_PWM_PAL_MODE
-# define WS2812_PWM_PAL_MODE 2 // DI Pin's alternate function value
-#endif
-#ifndef WS2812_DMA_STREAM
-# define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP
-#endif
-#ifndef WS2812_DMA_CHANNEL
-# define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP
-#endif
-#if (STM32_DMA_SUPPORTS_DMAMUX == TRUE) && !defined(WS2812_DMAMUX_ID)
-# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP"
-#endif
-
-#ifndef WS2812_PWM_COMPLEMENTARY_OUTPUT
-# define WS2812_PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH
-#else
-# if !STM32_PWM_USE_ADVANCED
-# error "WS2812_PWM_COMPLEMENTARY_OUTPUT requires STM32_PWM_USE_ADVANCED == TRUE"
-# endif
-# define WS2812_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
-#endif
-
-// Push Pull or Open Drain Configuration
-// Default Push Pull
-#ifndef WS2812_EXTERNAL_PULLUP
-# if defined(USE_GPIOV1)
-# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
-# else
-# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING
-# endif
-#else
-# if defined(USE_GPIOV1)
-# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
-# else
-# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING
-# endif
-#endif
-
-#ifndef WS2812_PWM_TARGET_PERIOD
-//# define WS2812_PWM_TARGET_PERIOD 800000 // Original code is 800k...?
-# define WS2812_PWM_TARGET_PERIOD 80000 // TODO: work out why 10x less on f303/f4x1
-#endif
-
-/* --- PRIVATE CONSTANTS ---------------------------------------------------- */
-
-#define WS2812_PWM_FREQUENCY (STM32_SYSCLK / 2) /**< Clock frequency of PWM, must be valid with respect to system clock! */
-#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY / WS2812_PWM_TARGET_PERIOD) /**< Clock period in ticks. 1 / 800kHz = 1.25 uS (as per datasheet) */
-
-/**
- * @brief Number of bit-periods to hold the data line low at the end of a frame
- *
- * The reset period for each frame is defined in WS2812_TRST_US.
- * Calculate the number of zeroes to add at the end assuming 1.25 uS/bit:
- */
-#define WS2812_RESET_BIT_N (1000 * WS2812_TRST_US / 1250)
-#define WS2812_COLOR_BIT_N (RGBLED_NUM * 24) /**< Number of data bits */
-#define WS2812_BIT_N (WS2812_COLOR_BIT_N + WS2812_RESET_BIT_N) /**< Total number of bits in a frame */
-
-/**
- * @brief High period for a zero, in ticks
- *
- * Per the datasheet:
- * WS2812:
- * - T0H: 200 nS to 500 nS, inclusive
- * - T0L: 650 nS to 950 nS, inclusive
- * WS2812B:
- * - T0H: 200 nS to 500 nS, inclusive
- * - T0L: 750 nS to 1050 nS, inclusive
- *
- * The duty cycle is calculated for a high period of 350 nS.
- */
-#define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY / (1000000000 / 350))
-
-/**
- * @brief High period for a one, in ticks
- *
- * Per the datasheet:
- * WS2812:
- * - T1H: 550 nS to 850 nS, inclusive
- * - T1L: 450 nS to 750 nS, inclusive
- * WS2812B:
- * - T1H: 750 nS to 1050 nS, inclusive
- * - T1L: 200 nS to 500 nS, inclusive
- *
- * The duty cycle is calculated for a high period of 800 nS.
- * This is in the middle of the specifications of the WS2812 and WS2812B.
- */
-#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY / (1000000000 / 800))
-
-/* --- PRIVATE MACROS ------------------------------------------------------- */
-
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given bit
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] byte: The byte number [0, 2]
- * @param[in] bit: The bit number [0, 7]
- *
- * @return The bit index
- */
-#define WS2812_BIT(led, byte, bit) (24 * (led) + 8 * (byte) + (7 - (bit)))
-
-#if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit
- *
- * @note The red byte is the middle byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit number [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 1, (bit))
-
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit
- *
- * @note The red byte is the first byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit number [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 0, (bit))
-
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit
- *
- * @note The red byte is the last byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit index [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit))
-
-#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB)
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit
- *
- * @note The red byte is the middle byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit number [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 0, (bit))
-
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit
- *
- * @note The red byte is the first byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit number [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 1, (bit))
-
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit
- *
- * @note The red byte is the last byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit index [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit))
-
-#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit
- *
- * @note The red byte is the middle byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit number [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 2, (bit))
-
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit
- *
- * @note The red byte is the first byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit number [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 1, (bit))
-
-/**
- * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit
- *
- * @note The red byte is the last byte in the color packet
- *
- * @param[in] led: The led index [0, @ref RGBLED_NUM)
- * @param[in] bit: The bit index [0, 7]
- *
- * @return The bit index
- */
-# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 0, (bit))
-#endif
-
-/* --- PRIVATE VARIABLES ---------------------------------------------------- */
-
-static uint32_t ws2812_frame_buffer[WS2812_BIT_N + 1]; /**< Buffer for a frame */
-
-/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
-/*
- * Gedanke: Double-buffer type transactions: double buffer transfers using two memory pointers for
-the memory (while the DMA is reading/writing from/to a buffer, the application can
-write/read to/from the other buffer).
- */
-
-void ws2812_init(void) {
- // Initialize led frame buffer
- uint32_t i;
- for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle
- for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero
-
- palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE);
-
- // PWM Configuration
- //#pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config
- static const PWMConfig ws2812_pwm_config = {
- .frequency = WS2812_PWM_FREQUENCY,
- .period = WS2812_PWM_PERIOD, // Mit dieser Periode wird UDE-Event erzeugt und ein neuer Wert (Länge WS2812_BIT_N) vom DMA ins CCR geschrieben
- .callback = NULL,
- .channels =
- {
- [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled
- [WS2812_PWM_CHANNEL - 1] = {.mode = WS2812_PWM_OUTPUT_MODE, .callback = NULL}, // Turn on the channel we care about
- },
- .cr2 = 0,
- .dier = TIM_DIER_UDE, // DMA on update event for next period
- };
- //#pragma GCC diagnostic pop // Restore command-line warning options
-
- // Configure DMA
- // dmaInit(); // Joe added this
- dmaStreamAlloc(WS2812_DMA_STREAM - STM32_DMA_STREAM(0), 10, NULL, NULL);
- dmaStreamSetPeripheral(WS2812_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register
- dmaStreamSetMemory0(WS2812_DMA_STREAM, ws2812_frame_buffer);
- dmaStreamSetTransactionSize(WS2812_DMA_STREAM, WS2812_BIT_N);
- dmaStreamSetMode(WS2812_DMA_STREAM, STM32_DMA_CR_CHSEL(WS2812_DMA_CHANNEL) | STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_WORD | STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3));
- // M2P: Memory 2 Periph; PL: Priority Level
-
-#if (STM32_DMA_SUPPORTS_DMAMUX == TRUE)
- // If the MCU has a DMAMUX we need to assign the correct resource
- dmaSetRequestSource(WS2812_DMA_STREAM, WS2812_DMAMUX_ID);
-#endif
-
- // Start DMA
- dmaStreamEnable(WS2812_DMA_STREAM);
-
- // Configure PWM
- // NOTE: It's required that preload be enabled on the timer channel CCR register. This is currently enabled in the
- // ChibiOS driver code, so we don't have to do anything special to the timer. If we did, we'd have to start the timer,
- // disable counting, enable the channel, and then make whatever configuration changes we need.
- pwmStart(&WS2812_PWM_DRIVER, &ws2812_pwm_config);
- pwmEnableChannel(&WS2812_PWM_DRIVER, WS2812_PWM_CHANNEL - 1, 0); // Initial period is 0; output will be low until first duty cycle is DMA'd in
-}
-
-void ws2812_write_led(uint16_t led_number, uint8_t r, uint8_t g, uint8_t b) {
- // Write color to frame buffer
- for (uint8_t bit = 0; bit < 8; bit++) {
- ws2812_frame_buffer[WS2812_RED_BIT(led_number, bit)] = ((r >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
- ws2812_frame_buffer[WS2812_GREEN_BIT(led_number, bit)] = ((g >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
- ws2812_frame_buffer[WS2812_BLUE_BIT(led_number, bit)] = ((b >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
- }
-}
-
-// Setleds for standard RGB
-void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
- static bool s_init = false;
- if (!s_init) {
- ws2812_init();
- s_init = true;
- }
-
- for (uint16_t i = 0; i < leds; i++) {
- ws2812_write_led(i, ledarray[i].r, ledarray[i].g, ledarray[i].b);
- }
-}
diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c
deleted file mode 100644
index 377a929b94..0000000000
--- a/drivers/chibios/ws2812_spi.c
+++ /dev/null
@@ -1,159 +0,0 @@
-#include "quantum.h"
-#include "ws2812.h"
-
-/* Adapted from https://github.com/gamazeps/ws2812b-chibios-SPIDMA/ */
-
-#ifdef RGBW
-# error "RGBW not supported"
-#endif
-
-// Define the spi your LEDs are plugged to here
-#ifndef WS2812_SPI
-# define WS2812_SPI SPID1
-#endif
-
-#ifndef WS2812_SPI_MOSI_PAL_MODE
-# define WS2812_SPI_MOSI_PAL_MODE 5
-#endif
-
-#ifndef WS2812_SPI_SCK_PAL_MODE
-# define WS2812_SPI_SCK_PAL_MODE 5
-#endif
-
-// Push Pull or Open Drain Configuration
-// Default Push Pull
-#ifndef WS2812_EXTERNAL_PULLUP
-# if defined(USE_GPIOV1)
-# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
-# else
-# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL
-# endif
-#else
-# if defined(USE_GPIOV1)
-# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
-# else
-# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN
-# endif
-#endif
-
-// Define SPI config speed
-// baudrate should target 3.2MHz
-// F072 fpclk = 48MHz
-// 48/16 = 3Mhz
-#if WS2812_SPI_DIVISOR == 2
-# define WS2812_SPI_DIVISOR (0)
-#elif WS2812_SPI_DIVISOR == 4
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_0)
-#elif WS2812_SPI_DIVISOR == 8
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1)
-#elif WS2812_SPI_DIVISOR == 16 // same as default
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0)
-#elif WS2812_SPI_DIVISOR == 32
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2)
-#elif WS2812_SPI_DIVISOR == 64
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_0)
-#elif WS2812_SPI_DIVISOR == 128
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1)
-#elif WS2812_SPI_DIVISOR == 256
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0)
-#else
-# define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) // default
-#endif
-
-// Use SPI circular buffer
-#ifdef WS2812_SPI_USE_CIRCULAR_BUFFER
-# define WS2812_SPI_BUFFER_MODE 1 // circular buffer
-#else
-# define WS2812_SPI_BUFFER_MODE 0 // normal buffer
-#endif
-
-#if defined(USE_GPIOV1)
-# define WS2812_SCK_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
-#else
-# define WS2812_SCK_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL
-#endif
-
-#define BYTES_FOR_LED_BYTE 4
-#define NB_COLORS 3
-#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS)
-#define DATA_SIZE (BYTES_FOR_LED * RGBLED_NUM)
-#define RESET_SIZE (1000 * WS2812_TRST_US / (2 * 1250))
-#define PREAMBLE_SIZE 4
-
-static uint8_t txbuf[PREAMBLE_SIZE + DATA_SIZE + RESET_SIZE] = {0};
-
-/*
- * As the trick here is to use the SPI to send a huge pattern of 0 and 1 to
- * the ws2812b protocol, we use this helper function to translate bytes into
- * 0s and 1s for the LED (with the appropriate timing).
- */
-static uint8_t get_protocol_eq(uint8_t data, int pos) {
- uint8_t eq = 0;
- if (data & (1 << (2 * (3 - pos))))
- eq = 0b1110;
- else
- eq = 0b1000;
- if (data & (2 << (2 * (3 - pos))))
- eq += 0b11100000;
- else
- eq += 0b10000000;
- return eq;
-}
-
-static void set_led_color_rgb(LED_TYPE color, int pos) {
- uint8_t* tx_start = &txbuf[PREAMBLE_SIZE];
-
-#if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
- for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.g, j);
- for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.r, j);
- for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.b, j);
-#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB)
- for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.r, j);
- for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.g, j);
- for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.b, j);
-#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
- for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.b, j);
- for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.g, j);
- 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);
-#endif
-}
-
-void ws2812_init(void) {
- palSetLineMode(RGB_DI_PIN, WS2812_MOSI_OUTPUT_MODE);
-
-#ifdef WS2812_SPI_SCK_PIN
- palSetLineMode(WS2812_SPI_SCK_PIN, WS2812_SCK_OUTPUT_MODE);
-#endif // WS2812_SPI_SCK_PIN
-
- // TODO: more dynamic baudrate
- static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR};
-
- spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */
- spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */
- spiSelect(&WS2812_SPI); /* Slave Select assertion. */
-#ifdef WS2812_SPI_USE_CIRCULAR_BUFFER
- spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
-#endif
-}
-
-void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
- static bool s_init = false;
- if (!s_init) {
- ws2812_init();
- s_init = true;
- }
-
- for (uint8_t i = 0; i < leds; i++) {
- set_led_color_rgb(ledarray[i], i);
- }
-
- // Send async - each led takes ~0.03ms, 50 leds ~1.5ms, animations flushing faster than send will cause issues.
- // 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, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
-# else
- spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
-# endif
-#endif
-}
diff --git a/drivers/eeprom/eeprom_stm32_L0_L1.c b/drivers/eeprom/eeprom_stm32_L0_L1.c
deleted file mode 100644
index ed26cc7145..0000000000
--- a/drivers/eeprom/eeprom_stm32_L0_L1.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Copyright 2020 Nick Brassel (tzarc)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include
-#include
-
-#include
-#include "eeprom_driver.h"
-#include "eeprom_stm32_L0_L1.h"
-
-#define EEPROM_BASE_ADDR 0x08080000
-#define EEPROM_ADDR(offset) (EEPROM_BASE_ADDR + (offset))
-#define EEPROM_PTR(offset) ((__IO uint8_t *)EEPROM_ADDR(offset))
-#define EEPROM_BYTE(location, offset) (*(EEPROM_PTR(((uint32_t)location) + ((uint32_t)offset))))
-
-#define BUFFER_BYTE(buffer, offset) (*(((uint8_t *)buffer) + offset))
-
-#define FLASH_PEKEY1 0x89ABCDEF
-#define FLASH_PEKEY2 0x02030405
-
-static inline void STM32_L0_L1_EEPROM_WaitNotBusy(void) {
- while (FLASH->SR & FLASH_SR_BSY) {
- __WFI();
- }
-}
-
-static inline void STM32_L0_L1_EEPROM_Unlock(void) {
- STM32_L0_L1_EEPROM_WaitNotBusy();
- if (FLASH->PECR & FLASH_PECR_PELOCK) {
- FLASH->PEKEYR = FLASH_PEKEY1;
- FLASH->PEKEYR = FLASH_PEKEY2;
- }
-}
-
-static inline void STM32_L0_L1_EEPROM_Lock(void) {
- STM32_L0_L1_EEPROM_WaitNotBusy();
- FLASH->PECR |= FLASH_PECR_PELOCK;
-}
-
-void eeprom_driver_init(void) {}
-
-void eeprom_driver_erase(void) {
- STM32_L0_L1_EEPROM_Unlock();
-
- for (size_t offset = 0; offset < STM32_ONBOARD_EEPROM_SIZE; offset += sizeof(uint32_t)) {
- FLASH->PECR |= FLASH_PECR_ERASE | FLASH_PECR_DATA;
-
- *(__IO uint32_t *)EEPROM_ADDR(offset) = (uint32_t)0;
-
- STM32_L0_L1_EEPROM_WaitNotBusy();
- FLASH->PECR &= ~(FLASH_PECR_ERASE | FLASH_PECR_DATA);
- }
-
- STM32_L0_L1_EEPROM_Lock();
-}
-
-void eeprom_read_block(void *buf, const void *addr, size_t len) {
- for (size_t offset = 0; offset < len; ++offset) {
- // Drop out if we've hit the limit of the EEPROM
- if ((((uint32_t)addr) + offset) >= STM32_ONBOARD_EEPROM_SIZE) {
- break;
- }
-
- STM32_L0_L1_EEPROM_WaitNotBusy();
- BUFFER_BYTE(buf, offset) = EEPROM_BYTE(addr, offset);
- }
-}
-
-void eeprom_write_block(const void *buf, void *addr, size_t len) {
- STM32_L0_L1_EEPROM_Unlock();
-
- for (size_t offset = 0; offset < len; ++offset) {
- // Drop out if we've hit the limit of the EEPROM
- if ((((uint32_t)addr) + offset) >= STM32_ONBOARD_EEPROM_SIZE) {
- break;
- }
-
- STM32_L0_L1_EEPROM_WaitNotBusy();
- EEPROM_BYTE(addr, offset) = BUFFER_BYTE(buf, offset);
- }
-
- STM32_L0_L1_EEPROM_Lock();
-}
diff --git a/drivers/eeprom/eeprom_stm32_L0_L1.h b/drivers/eeprom/eeprom_stm32_L0_L1.h
deleted file mode 100644
index a35defca8b..0000000000
--- a/drivers/eeprom/eeprom_stm32_L0_L1.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Copyright 2020 Nick Brassel (tzarc)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-/*
- The size used by the STM32 L0/L1 EEPROM driver.
-*/
-#ifndef STM32_ONBOARD_EEPROM_SIZE
-# ifdef VIA_ENABLE
-# define STM32_ONBOARD_EEPROM_SIZE 1024
-# else
-# include "eeconfig.h"
-# define STM32_ONBOARD_EEPROM_SIZE (((EECONFIG_SIZE + 3) / 4) * 4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO and EEPROM page sizing
-# endif
-#endif
-
-#if STM32_ONBOARD_EEPROM_SIZE > 128
-# pragma message("Please note: resetting EEPROM using an STM32L0/L1 device takes up to 1 second for every 1kB of internal EEPROM used.")
-#endif
diff --git a/platforms/avr/drivers/analog.c b/platforms/avr/drivers/analog.c
new file mode 100644
index 0000000000..8d299ffdb9
--- /dev/null
+++ b/platforms/avr/drivers/analog.c
@@ -0,0 +1,138 @@
+/* Copyright 2015 Jack Humbert
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+#include
+#include "analog.h"
+
+static uint8_t aref = ADC_REF_POWER;
+
+void analogReference(uint8_t mode) { aref = mode & (_BV(REFS1) | _BV(REFS0)); }
+
+// Arduino compatible pin input
+int16_t analogRead(uint8_t pin) {
+#if defined(__AVR_ATmega32U4__)
+ // clang-format off
+ static const uint8_t PROGMEM pin_to_mux[] = {
+ //A0 A1 A2 A3 A4 A5
+ //F7 F6 F5 F4 F1 F0
+ 0x07, 0x06, 0x05, 0x04, 0x01, 0x00,
+ //A6 A7 A8 A9 A10 A11
+ //D4 D7 B4 B5 B6 D6
+ 0x20, 0x22, 0x23, 0x24, 0x25, 0x21
+ };
+ // clang-format on
+ if (pin >= 12) return 0;
+ return adc_read(pgm_read_byte(pin_to_mux + pin));
+#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
+ if (pin >= 8) return 0;
+ return adc_read(pin);
+#else
+ return 0;
+#endif
+}
+
+int16_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); }
+
+uint8_t pinToMux(pin_t pin) {
+ switch (pin) {
+ // clang-format off
+#if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
+ case F0: return 0; // ADC0
+ case F1: return _BV(MUX0); // ADC1
+ case F2: return _BV(MUX1); // ADC2
+ case F3: return _BV(MUX1) | _BV(MUX0); // ADC3
+ case F4: return _BV(MUX2); // ADC4
+ case F5: return _BV(MUX2) | _BV(MUX0); // ADC5
+ case F6: return _BV(MUX2) | _BV(MUX1); // ADC6
+ case F7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
+ default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
+#elif defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
+ case F0: return 0; // ADC0
+ case F1: return _BV(MUX0); // ADC1
+ case F4: return _BV(MUX2); // ADC4
+ case F5: return _BV(MUX2) | _BV(MUX0); // ADC5
+ case F6: return _BV(MUX2) | _BV(MUX1); // ADC6
+ case F7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
+ case D4: return _BV(MUX5); // ADC8
+ case D6: return _BV(MUX5) | _BV(MUX0); // ADC9
+ case D7: return _BV(MUX5) | _BV(MUX1); // ADC10
+ case B4: return _BV(MUX5) | _BV(MUX1) | _BV(MUX0); // ADC11
+ case B5: return _BV(MUX5) | _BV(MUX2); // ADC12
+ case B6: return _BV(MUX5) | _BV(MUX2) | _BV(MUX0); // ADC13
+ default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
+#elif defined(__AVR_ATmega32A__)
+ case A0: return 0; // ADC0
+ case A1: return _BV(MUX0); // ADC1
+ case A2: return _BV(MUX1); // ADC2
+ case A3: return _BV(MUX1) | _BV(MUX0); // ADC3
+ case A4: return _BV(MUX2); // ADC4
+ case A5: return _BV(MUX2) | _BV(MUX0); // ADC5
+ case A6: return _BV(MUX2) | _BV(MUX1); // ADC6
+ case A7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
+ default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
+#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
+ case C0: return 0; // ADC0
+ case C1: return _BV(MUX0); // ADC1
+ case C2: return _BV(MUX1); // ADC2
+ case C3: return _BV(MUX1) | _BV(MUX0); // ADC3
+ case C4: return _BV(MUX2); // ADC4
+ case C5: return _BV(MUX2) | _BV(MUX0); // ADC5
+ // ADC7:6 not present in DIP package and not shared by GPIO pins
+ default: return _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
+#endif
+ // clang-format on
+ }
+ return 0;
+}
+
+int16_t adc_read(uint8_t mux) {
+ uint16_t low;
+
+ // Enable ADC and configure prescaler
+ ADCSRA = _BV(ADEN) | ADC_PRESCALER;
+
+#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
+ // High speed mode and ADC8-13
+ ADCSRB = _BV(ADHSM) | (mux & _BV(MUX5));
+#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
+ // High speed mode only
+ ADCSRB = _BV(ADHSM);
+#endif
+
+ // Configure mux input
+#if defined(MUX4)
+ ADMUX = aref | (mux & (_BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0)));
+#else
+ ADMUX = aref | (mux & (_BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0)));
+#endif
+
+ // Start the conversion
+ ADCSRA |= _BV(ADSC);
+ // Wait for result
+ while (ADCSRA & _BV(ADSC))
+ ;
+ // Must read LSB first
+ low = ADCL;
+ // Must read MSB only once!
+ low |= (ADCH << 8);
+
+ // turn off the ADC
+ ADCSRA &= ~(1 << ADEN);
+
+ return low;
+}
diff --git a/platforms/avr/drivers/analog.h b/platforms/avr/drivers/analog.h
new file mode 100644
index 0000000000..058882450d
--- /dev/null
+++ b/platforms/avr/drivers/analog.h
@@ -0,0 +1,53 @@
+/* Copyright 2015 Jack Humbert
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include "quantum.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+void analogReference(uint8_t mode);
+int16_t analogRead(uint8_t pin);
+
+int16_t analogReadPin(pin_t pin);
+uint8_t pinToMux(pin_t pin);
+
+int16_t adc_read(uint8_t mux);
+#ifdef __cplusplus
+}
+#endif
+
+#define ADC_REF_EXTERNAL 0 // AREF, Internal Vref turned off
+#define ADC_REF_POWER _BV(REFS0) // AVCC with external capacitor on AREF pin
+#define ADC_REF_INTERNAL (_BV(REFS1) | _BV(REFS0)) // Internal 2.56V Voltage Reference with external capacitor on AREF pin (1.1V for 328P)
+
+// These prescaler values are for high speed mode, ADHSM = 1
+#if F_CPU == 16000000L || F_CPU == 12000000L
+# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS1)) // /64
+#elif F_CPU == 8000000L
+# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS0)) // /32
+#elif F_CPU == 4000000L
+# define ADC_PRESCALER (_BV(ADPS2)) // /16
+#elif F_CPU == 2000000L
+# define ADC_PRESCALER (_BV(ADPS1) | _BV(ADPS0)) // /8
+#elif F_CPU == 1000000L
+# define ADC_PRESCALER _BV(ADPS1) // /4
+#else
+# define ADC_PRESCALER _BV(ADPS0) // /2
+#endif
diff --git a/platforms/avr/drivers/glcdfont.c b/platforms/avr/drivers/glcdfont.c
new file mode 100644
index 0000000000..5e763b054f
--- /dev/null
+++ b/platforms/avr/drivers/glcdfont.c
@@ -0,0 +1,23 @@
+// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
+// See gfxfont.h for newer custom bitmap font info.
+
+#include "progmem.h"
+
+// Standard ASCII 5x7 font
+
+static const unsigned char font[] PROGMEM = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x18, 0x3C, 0x18, 0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x18, 0x24, 0x18, 0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x26, 0x29, 0x79, 0x29, 0x26, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x60, 0x60, 0x60, 0x60, 0x60, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x10, 0x20, 0x7E, 0x20, 0x10, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
+ 0x30, 0x38, 0x3E, 0x38, 0x30, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x23, 0x13, 0x08, 0x64, 0x62, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x80, 0x70, 0x30, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x60, 0x60, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x72, 0x49, 0x49, 0x49, 0x46, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x27, 0x45, 0x45, 0x45, 0x39, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x41, 0x21, 0x11, 0x09, 0x07, 0x36, 0x49, 0x49, 0x49, 0x36, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00,
+ 0x00, 0x08, 0x14, 0x22, 0x41, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x41, 0x22, 0x14, 0x08, 0x02, 0x01, 0x59, 0x09, 0x06, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x26, 0x49, 0x49, 0x49, 0x32, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x63, 0x14, 0x08, 0x14, 0x63, 0x03, 0x04, 0x78, 0x04, 0x03,
+ 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x04, 0x02, 0x01, 0x02, 0x04, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x03, 0x07, 0x08, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x38, 0x44, 0x44, 0x44, 0x28, 0x38, 0x44, 0x44, 0x28, 0x7F, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x38, 0x44, 0x44, 0x44, 0x38, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x48, 0x54, 0x54, 0x54, 0x24, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x3C, 0x40, 0x30, 0x40, 0x3C,
+ 0x44, 0x28, 0x10, 0x28, 0x44, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x1E, 0xA1, 0xA1, 0x61, 0x12, 0x3A, 0x40, 0x40, 0x20, 0x7A, 0x38, 0x54, 0x54, 0x55, 0x59, 0x21, 0x55, 0x55, 0x79, 0x41, 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
+ 0x21, 0x55, 0x54, 0x78, 0x40, 0x20, 0x54, 0x55, 0x79, 0x40, 0x0C, 0x1E, 0x52, 0x72, 0x12, 0x39, 0x55, 0x55, 0x55, 0x59, 0x39, 0x54, 0x54, 0x54, 0x59, 0x39, 0x55, 0x54, 0x54, 0x58, 0x00, 0x00, 0x45, 0x7C, 0x41, 0x00, 0x02, 0x45, 0x7D, 0x42, 0x00, 0x01, 0x45, 0x7C, 0x40, 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
+ 0xF0, 0x28, 0x25, 0x28, 0xF0, 0x7C, 0x54, 0x55, 0x45, 0x00, 0x20, 0x54, 0x54, 0x7C, 0x54, 0x7C, 0x0A, 0x09, 0x7F, 0x49, 0x32, 0x49, 0x49, 0x49, 0x32, 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
+ 0x32, 0x4A, 0x48, 0x48, 0x30, 0x3A, 0x41, 0x41, 0x21, 0x7A, 0x3A, 0x42, 0x40, 0x20, 0x78, 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
+ 0x3D, 0x40, 0x40, 0x40, 0x3D, 0x3C, 0x24, 0xFF, 0x24, 0x24, 0x48, 0x7E, 0x49, 0x43, 0x66, 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 0xFF, 0x09, 0x29, 0xF6, 0x20, 0xC0, 0x88, 0x7E, 0x09, 0x03, 0x20, 0x54, 0x54, 0x79, 0x41, 0x00, 0x00, 0x44, 0x7D, 0x41, 0x30, 0x48, 0x48, 0x4A, 0x32, 0x38, 0x40, 0x40, 0x22, 0x7A, 0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x26, 0x29, 0x29, 0x2F, 0x28, 0x26, 0x29, 0x29, 0x29, 0x26, 0x30, 0x48, 0x4D, 0x40, 0x20, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x22, 0x14, 0x2A, 0x14, 0x08, 0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
+ 0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
+ 0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
+ 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x14, 0x14, 0x14, 0xFF, 0x00, 0x10, 0x10, 0xFF, 0x00, 0xFF, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x14, 0x14, 0x14, 0xFC, 0x00, 0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x14, 0x14, 0xF4, 0x04, 0xFC, 0x14, 0x14, 0x17, 0x10, 0x1F, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x14, 0x14, 0x14, 0x1F, 0x00, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x14, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x1F, 0x10, 0x17, 0x00, 0x00, 0xFC, 0x04, 0xF4, 0x14, 0x14, 0x17, 0x10, 0x17, 0x14, 0x14, 0xF4, 0x04, 0xF4, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0xF7, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x17, 0x14, 0x10, 0x10, 0x1F, 0x10, 0x1F,
+ 0x14, 0x14, 0x14, 0xF4, 0x14, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x1F, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x00, 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0xFF, 0x10, 0xFF, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x38, 0x44, 0x44, 0x38, 0x44, 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
+ 0x7E, 0x02, 0x02, 0x06, 0x06, 0x02, 0x7E, 0x02, 0x7E, 0x02, 0x63, 0x55, 0x49, 0x41, 0x63, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x40, 0x7E, 0x20, 0x1E, 0x20, 0x06, 0x02, 0x7E, 0x02, 0x02, 0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x4C, 0x72, 0x01, 0x72, 0x4C, 0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x30, 0x48, 0x78, 0x48, 0x30, 0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x3E, 0x49, 0x49, 0x49, 0x00, 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x44, 0x44, 0x5F, 0x44, 0x44, 0x40, 0x51, 0x4A, 0x44, 0x40, 0x40, 0x44, 0x4A, 0x51, 0x40, 0x00, 0x00, 0xFF, 0x01, 0x03, 0xE0, 0x80, 0xFF, 0x00, 0x00, 0x08, 0x08, 0x6B, 0x6B, 0x08, 0x36, 0x12, 0x36, 0x24, 0x36, 0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x30, 0x40, 0xFF, 0x01, 0x01, 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
+};
diff --git a/platforms/avr/drivers/hd44780.c b/platforms/avr/drivers/hd44780.c
new file mode 100644
index 0000000000..f71069dece
--- /dev/null
+++ b/platforms/avr/drivers/hd44780.c
@@ -0,0 +1,536 @@
+/****************************************************************************
+ Title: HD44780U LCD library
+ Author: Peter Fleury http://tinyurl.com/peterfleury
+ License: GNU General Public License Version 3
+ File: $Id: lcd.c,v 1.15.2.2 2015/01/17 12:16:05 peter Exp $
+ Software: AVR-GCC 3.3
+ Target: any AVR device, memory mapped mode only for AT90S4414/8515/Mega
+
+ DESCRIPTION
+ Basic routines for interfacing a HD44780U-based text lcd display
+
+ Originally based on Volker Oth's lcd library,
+ changed lcd_init(), added additional constants for lcd_command(),
+ added 4-bit I/O mode, improved and optimized code.
+
+ Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in
+ 4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported.
+
+ Memory mapped mode compatible with Kanda STK200, but supports also
+ generation of R/W signal through A8 address line.
+
+ USAGE
+ See the C include lcd.h file for a description of each function
+
+*****************************************************************************/
+#include
+#include
+#include
+#include
+#include "hd44780.h"
+
+/*
+** constants/macros
+*/
+#define DDR(x) (*(&x - 1)) /* address of data direction register of port x */
+#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
+/* on ATmega64/128 PINF is on port 0x00 and not 0x60 */
+# define PIN(x) (&PORTF == &(x) ? _SFR_IO8(0x00) : (*(&x - 2)))
+#else
+# define PIN(x) (*(&x - 2)) /* address of input register of port x */
+#endif
+
+#if LCD_IO_MODE
+# define lcd_e_delay() _delay_us(LCD_DELAY_ENABLE_PULSE)
+# define lcd_e_high() LCD_E_PORT |= _BV(LCD_E_PIN);
+# define lcd_e_low() LCD_E_PORT &= ~_BV(LCD_E_PIN);
+# define lcd_e_toggle() toggle_e()
+# define lcd_rw_high() LCD_RW_PORT |= _BV(LCD_RW_PIN)
+# define lcd_rw_low() LCD_RW_PORT &= ~_BV(LCD_RW_PIN)
+# define lcd_rs_high() LCD_RS_PORT |= _BV(LCD_RS_PIN)
+# define lcd_rs_low() LCD_RS_PORT &= ~_BV(LCD_RS_PIN)
+#endif
+
+#if LCD_IO_MODE
+# if LCD_LINES == 1
+# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_1LINE
+# else
+# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_2LINES
+# endif
+#else
+# if LCD_LINES == 1
+# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_1LINE
+# else
+# define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_2LINES
+# endif
+#endif
+
+#if LCD_CONTROLLER_KS0073
+# if LCD_LINES == 4
+
+# define KS0073_EXTENDED_FUNCTION_REGISTER_ON 0x2C /* |0|010|1100 4-bit mode, extension-bit RE = 1 */
+# define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x28 /* |0|010|1000 4-bit mode, extension-bit RE = 0 */
+# define KS0073_4LINES_MODE 0x09 /* |0|000|1001 4 lines mode */
+
+# endif
+#endif
+
+/*
+** function prototypes
+*/
+#if LCD_IO_MODE
+static void toggle_e(void);
+#endif
+
+/*
+** local functions
+*/
+
+/*************************************************************************
+delay for a minimum of microseconds
+the number of loops is calculated at compile-time from MCU clock frequency
+*************************************************************************/
+#define delay(us) _delay_us(us)
+
+#if LCD_IO_MODE
+/* toggle Enable Pin to initiate write */
+static void toggle_e(void) {
+ lcd_e_high();
+ lcd_e_delay();
+ lcd_e_low();
+}
+#endif
+
+/*************************************************************************
+Low-level function to write byte to LCD controller
+Input: data byte to write to LCD
+ rs 1: write data
+ 0: write instruction
+Returns: none
+*************************************************************************/
+#if LCD_IO_MODE
+static void lcd_write(uint8_t data, uint8_t rs) {
+ unsigned char dataBits;
+
+ if (rs) { /* write data (RS=1, RW=0) */
+ lcd_rs_high();
+ } else { /* write instruction (RS=0, RW=0) */
+ lcd_rs_low();
+ }
+ lcd_rw_low(); /* RW=0 write mode */
+
+ if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
+ /* configure data pins as output */
+ DDR(LCD_DATA0_PORT) |= 0x0F;
+
+ /* output high nibble first */
+ dataBits = LCD_DATA0_PORT & 0xF0;
+ LCD_DATA0_PORT = dataBits | ((data >> 4) & 0x0F);
+ lcd_e_toggle();
+
+ /* output low nibble */
+ LCD_DATA0_PORT = dataBits | (data & 0x0F);
+ lcd_e_toggle();
+
+ /* all data pins high (inactive) */
+ LCD_DATA0_PORT = dataBits | 0x0F;
+ } else {
+ /* configure data pins as output */
+ DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
+ DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
+ DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
+ DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
+
+ /* output high nibble first */
+ LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
+ LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
+ LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
+ LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
+ if (data & 0x80) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
+ if (data & 0x40) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
+ if (data & 0x20) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
+ if (data & 0x10) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
+ lcd_e_toggle();
+
+ /* output low nibble */
+ LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
+ LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
+ LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
+ LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
+ if (data & 0x08) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
+ if (data & 0x04) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
+ if (data & 0x02) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
+ if (data & 0x01) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
+ lcd_e_toggle();
+
+ /* all data pins high (inactive) */
+ LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
+ LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
+ LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
+ LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
+ }
+}
+#else
+# define lcd_write(d, rs) \
+ if (rs) \
+ *(volatile uint8_t *)(LCD_IO_DATA) = d; \
+ else \
+ *(volatile uint8_t *)(LCD_IO_FUNCTION) = d;
+/* rs==0 -> write instruction to LCD_IO_FUNCTION */
+/* rs==1 -> write data to LCD_IO_DATA */
+#endif
+
+/*************************************************************************
+Low-level function to read byte from LCD controller
+Input: rs 1: read data
+ 0: read busy flag / address counter
+Returns: byte read from LCD controller
+*************************************************************************/
+#if LCD_IO_MODE
+static uint8_t lcd_read(uint8_t rs) {
+ uint8_t data;
+
+ if (rs)
+ lcd_rs_high(); /* RS=1: read data */
+ else
+ lcd_rs_low(); /* RS=0: read busy flag */
+ lcd_rw_high(); /* RW=1 read mode */
+
+ if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
+ DDR(LCD_DATA0_PORT) &= 0xF0; /* configure data pins as input */
+
+ lcd_e_high();
+ lcd_e_delay();
+ data = PIN(LCD_DATA0_PORT) << 4; /* read high nibble first */
+ lcd_e_low();
+
+ lcd_e_delay(); /* Enable 500ns low */
+
+ lcd_e_high();
+ lcd_e_delay();
+ data |= PIN(LCD_DATA0_PORT) & 0x0F; /* read low nibble */
+ lcd_e_low();
+ } else {
+ /* configure data pins as input */
+ DDR(LCD_DATA0_PORT) &= ~_BV(LCD_DATA0_PIN);
+ DDR(LCD_DATA1_PORT) &= ~_BV(LCD_DATA1_PIN);
+ DDR(LCD_DATA2_PORT) &= ~_BV(LCD_DATA2_PIN);
+ DDR(LCD_DATA3_PORT) &= ~_BV(LCD_DATA3_PIN);
+
+ /* read high nibble first */
+ lcd_e_high();
+ lcd_e_delay();
+ data = 0;
+ if (PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN)) data |= 0x10;
+ if (PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN)) data |= 0x20;
+ if (PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN)) data |= 0x40;
+ if (PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN)) data |= 0x80;
+ lcd_e_low();
+
+ lcd_e_delay(); /* Enable 500ns low */
+
+ /* read low nibble */
+ lcd_e_high();
+ lcd_e_delay();
+ if (PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN)) data |= 0x01;
+ if (PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN)) data |= 0x02;
+ if (PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN)) data |= 0x04;
+ if (PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN)) data |= 0x08;
+ lcd_e_low();
+ }
+ return data;
+}
+#else
+# define lcd_read(rs) (rs) ? *(volatile uint8_t *)(LCD_IO_DATA + LCD_IO_READ) : *(volatile uint8_t *)(LCD_IO_FUNCTION + LCD_IO_READ)
+/* rs==0 -> read instruction from LCD_IO_FUNCTION */
+/* rs==1 -> read data from LCD_IO_DATA */
+#endif
+
+/*************************************************************************
+loops while lcd is busy, returns address counter
+*************************************************************************/
+static uint8_t lcd_waitbusy(void)
+
+{
+ register uint8_t c;
+
+ /* wait until busy flag is cleared */
+ while ((c = lcd_read(0)) & (1 << LCD_BUSY)) {
+ }
+
+ /* the address counter is updated 4us after the busy flag is cleared */
+ delay(LCD_DELAY_BUSY_FLAG);
+
+ /* now read the address counter */
+ return (lcd_read(0)); // return address counter
+
+} /* lcd_waitbusy */
+
+/*************************************************************************
+Move cursor to the start of next line or to the first line if the cursor
+is already on the last line.
+*************************************************************************/
+static inline void lcd_newline(uint8_t pos) {
+ register uint8_t addressCounter;
+
+#if LCD_LINES == 1
+ addressCounter = 0;
+#endif
+#if LCD_LINES == 2
+ if (pos < (LCD_START_LINE2))
+ addressCounter = LCD_START_LINE2;
+ else
+ addressCounter = LCD_START_LINE1;
+#endif
+#if LCD_LINES == 4
+# if KS0073_4LINES_MODE
+ if (pos < LCD_START_LINE2)
+ addressCounter = LCD_START_LINE2;
+ else if ((pos >= LCD_START_LINE2) && (pos < LCD_START_LINE3))
+ addressCounter = LCD_START_LINE3;
+ else if ((pos >= LCD_START_LINE3) && (pos < LCD_START_LINE4))
+ addressCounter = LCD_START_LINE4;
+ else
+ addressCounter = LCD_START_LINE1;
+# else
+ if (pos < LCD_START_LINE3)
+ addressCounter = LCD_START_LINE2;
+ else if ((pos >= LCD_START_LINE2) && (pos < LCD_START_LINE4))
+ addressCounter = LCD_START_LINE3;
+ else if ((pos >= LCD_START_LINE3) && (pos < LCD_START_LINE2))
+ addressCounter = LCD_START_LINE4;
+ else
+ addressCounter = LCD_START_LINE1;
+# endif
+#endif
+ lcd_command((1 << LCD_DDRAM) + addressCounter);
+
+} /* lcd_newline */
+
+/*
+** PUBLIC FUNCTIONS
+*/
+
+/*************************************************************************
+Send LCD controller instruction command
+Input: instruction to send to LCD controller, see HD44780 data sheet
+Returns: none
+*************************************************************************/
+void lcd_command(uint8_t cmd) {
+ lcd_waitbusy();
+ lcd_write(cmd, 0);
+}
+
+/*************************************************************************
+Send data byte to LCD controller
+Input: data to send to LCD controller, see HD44780 data sheet
+Returns: none
+*************************************************************************/
+void lcd_data(uint8_t data) {
+ lcd_waitbusy();
+ lcd_write(data, 1);
+}
+
+/*************************************************************************
+Set cursor to specified position
+Input: x horizontal position (0: left most position)
+ y vertical position (0: first line)
+Returns: none
+*************************************************************************/
+void lcd_gotoxy(uint8_t x, uint8_t y) {
+#if LCD_LINES == 1
+ lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
+#endif
+#if LCD_LINES == 2
+ if (y == 0)
+ lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
+ else
+ lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x);
+#endif
+#if LCD_LINES == 4
+ if (y == 0)
+ lcd_command((1 << LCD_DDRAM) + LCD_START_LINE1 + x);
+ else if (y == 1)
+ lcd_command((1 << LCD_DDRAM) + LCD_START_LINE2 + x);
+ else if (y == 2)
+ lcd_command((1 << LCD_DDRAM) + LCD_START_LINE3 + x);
+ else /* y==3 */
+ lcd_command((1 << LCD_DDRAM) + LCD_START_LINE4 + x);
+#endif
+
+} /* lcd_gotoxy */
+
+/*************************************************************************
+*************************************************************************/
+int lcd_getxy(void) { return lcd_waitbusy(); }
+
+/*************************************************************************
+Clear display and set cursor to home position
+*************************************************************************/
+void lcd_clrscr(void) { lcd_command(1 << LCD_CLR); }
+
+/*************************************************************************
+Set cursor to home position
+*************************************************************************/
+void lcd_home(void) { lcd_command(1 << LCD_HOME); }
+
+/*************************************************************************
+Display character at current cursor position
+Input: character to be displayed
+Returns: none
+*************************************************************************/
+void lcd_putc(char c) {
+ uint8_t pos;
+
+ pos = lcd_waitbusy(); // read busy-flag and address counter
+ if (c == '\n') {
+ lcd_newline(pos);
+ } else {
+#if LCD_WRAP_LINES == 1
+# if LCD_LINES == 1
+ if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
+ lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
+ }
+# elif LCD_LINES == 2
+ if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
+ lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2, 0);
+ } else if (pos == LCD_START_LINE2 + LCD_DISP_LENGTH) {
+ lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
+ }
+# elif LCD_LINES == 4
+ if (pos == LCD_START_LINE1 + LCD_DISP_LENGTH) {
+ lcd_write((1 << LCD_DDRAM) + LCD_START_LINE2, 0);
+ } else if (pos == LCD_START_LINE2 + LCD_DISP_LENGTH) {
+ lcd_write((1 << LCD_DDRAM) + LCD_START_LINE3, 0);
+ } else if (pos == LCD_START_LINE3 + LCD_DISP_LENGTH) {
+ lcd_write((1 << LCD_DDRAM) + LCD_START_LINE4, 0);
+ } else if (pos == LCD_START_LINE4 + LCD_DISP_LENGTH) {
+ lcd_write((1 << LCD_DDRAM) + LCD_START_LINE1, 0);
+ }
+# endif
+ lcd_waitbusy();
+#endif
+ lcd_write(c, 1);
+ }
+
+} /* lcd_putc */
+
+/*************************************************************************
+Display string without auto linefeed
+Input: string to be displayed
+Returns: none
+*************************************************************************/
+void lcd_puts(const char *s)
+/* print string on lcd (no auto linefeed) */
+{
+ register char c;
+
+ while ((c = *s++)) {
+ lcd_putc(c);
+ }
+
+} /* lcd_puts */
+
+/*************************************************************************
+Display string from program memory without auto linefeed
+Input: string from program memory be be displayed
+Returns: none
+*************************************************************************/
+void lcd_puts_p(const char *progmem_s)
+/* print string from program memory on lcd (no auto linefeed) */
+{
+ register char c;
+
+ while ((c = pgm_read_byte(progmem_s++))) {
+ lcd_putc(c);
+ }
+
+} /* lcd_puts_p */
+
+/*************************************************************************
+Initialize display and select type of cursor
+Input: dispAttr LCD_DISP_OFF display off
+ LCD_DISP_ON display on, cursor off
+ LCD_DISP_ON_CURSOR display on, cursor on
+ LCD_DISP_CURSOR_BLINK display on, cursor on flashing
+Returns: none
+*************************************************************************/
+void lcd_init(uint8_t dispAttr) {
+#if LCD_IO_MODE
+ /*
+ * Initialize LCD to 4 bit I/O mode
+ */
+
+ if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (&LCD_RS_PORT == &LCD_DATA0_PORT) && (&LCD_RW_PORT == &LCD_DATA0_PORT) && (&LCD_E_PORT == &LCD_DATA0_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) && (LCD_RS_PIN == 4) && (LCD_RW_PIN == 5) && (LCD_E_PIN == 6)) {
+ /* configure all port bits as output (all LCD lines on same port) */
+ DDR(LCD_DATA0_PORT) |= 0x7F;
+ } else if ((&LCD_DATA0_PORT == &LCD_DATA1_PORT) && (&LCD_DATA1_PORT == &LCD_DATA2_PORT) && (&LCD_DATA2_PORT == &LCD_DATA3_PORT) && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3)) {
+ /* configure all port bits as output (all LCD data lines on same port, but control lines on different ports) */
+ DDR(LCD_DATA0_PORT) |= 0x0F;
+ DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN);
+ DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN);
+ DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
+ } else {
+ /* configure all port bits as output (LCD data and control lines on different ports */
+ DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN);
+ DDR(LCD_RW_PORT) |= _BV(LCD_RW_PIN);
+ DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
+ DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
+ DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
+ DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
+ DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
+ }
+ delay(LCD_DELAY_BOOTUP); /* wait 16ms or more after power-on */
+
+ /* initial write to lcd is 8bit */
+ LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); // LCD_FUNCTION>>4;
+ LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); // LCD_FUNCTION_8BIT>>4;
+ lcd_e_toggle();
+ delay(LCD_DELAY_INIT); /* delay, busy flag can't be checked here */
+
+ /* repeat last command */
+ lcd_e_toggle();
+ delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */
+
+ /* repeat last command a third time */
+ lcd_e_toggle();
+ delay(LCD_DELAY_INIT_REP); /* delay, busy flag can't be checked here */
+
+ /* now configure for 4bit mode */
+ LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); // LCD_FUNCTION_4BIT_1LINE>>4
+ lcd_e_toggle();
+ delay(LCD_DELAY_INIT_4BIT); /* some displays need this additional delay */
+
+ /* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */
+#else
+ /*
+ * Initialize LCD to 8 bit memory mapped mode
+ */
+
+ /* enable external SRAM (memory mapped lcd) and one wait state */
+ MCUCR = _BV(SRE) | _BV(SRW);
+
+ /* reset LCD */
+ delay(LCD_DELAY_BOOTUP); /* wait 16ms after power-on */
+ lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
+ delay(LCD_DELAY_INIT); /* wait 5ms */
+ lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
+ delay(LCD_DELAY_INIT_REP); /* wait 64us */
+ lcd_write(LCD_FUNCTION_8BIT_1LINE, 0); /* function set: 8bit interface */
+ delay(LCD_DELAY_INIT_REP); /* wait 64us */
+#endif
+
+#if KS0073_4LINES_MODE
+ /* Display with KS0073 controller requires special commands for enabling 4 line mode */
+ lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_ON);
+ lcd_command(KS0073_4LINES_MODE);
+ lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF);
+#else
+ lcd_command(LCD_FUNCTION_DEFAULT); /* function set: display lines */
+#endif
+ lcd_command(LCD_DISP_OFF); /* display off */
+ lcd_clrscr(); /* display clear */
+ lcd_command(LCD_MODE_DEFAULT); /* set entry mode */
+ lcd_command(dispAttr); /* display/cursor control */
+
+} /* lcd_init */
diff --git a/platforms/avr/drivers/hd44780.h b/platforms/avr/drivers/hd44780.h
new file mode 100644
index 0000000000..08e60f8a44
--- /dev/null
+++ b/platforms/avr/drivers/hd44780.h
@@ -0,0 +1,348 @@
+/*************************************************************************
+ Title : C include file for the HD44780U LCD library (lcd.c)
+ Author: Peter Fleury http://tinyurl.com/peterfleury
+ License: GNU General Public License Version 3
+ File: $Id: lcd.h,v 1.14.2.4 2015/01/20 17:16:07 peter Exp $
+ Software: AVR-GCC 4.x
+ Hardware: any AVR device, memory mapped mode only for AVR with
+ memory mapped interface (AT90S8515/ATmega8515/ATmega128)
+***************************************************************************/
+
+/**
+ @mainpage
+ Collection of libraries for AVR-GCC
+ @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury
+ @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
+
+ @file
+ @defgroup pfleury_lcd LCD library
+ @code #include @endcode
+
+ @brief Basic routines for interfacing a HD44780U-based character LCD display
+
+ LCD character displays can be found in many devices, like espresso machines, laser printers.
+ The Hitachi HD44780 controller and its compatible controllers like Samsung KS0066U have become an industry standard for these types of displays.
+
+ This library allows easy interfacing with a HD44780 compatible display and can be
+ operated in memory mapped mode (LCD_IO_MODE defined as 0 in the include file lcd.h.) or in
+ 4-bit IO port mode (LCD_IO_MODE defined as 1). 8-bit IO port mode is not supported.
+
+ Memory mapped mode is compatible with old Kanda STK200 starter kit, but also supports
+ generation of R/W signal through A8 address line.
+
+ @see The chapter Interfacing a HD44780 Based LCD to an AVR
+ on my home page, which shows example circuits how to connect an LCD to an AVR controller.
+
+ @author Peter Fleury pfleury@gmx.ch http://tinyurl.com/peterfleury
+
+ @version 2.0
+
+ @copyright (C) 2015 Peter Fleury, GNU General Public License Version 3
+
+*/
+
+#pragma once
+
+#include
+#include
+
+#if (__GNUC__ * 100 + __GNUC_MINOR__) < 405
+# error "This library requires AVR-GCC 4.5 or later, update to newer AVR-GCC compiler !"
+#endif
+
+/**@{*/
+
+/*
+ * LCD and target specific definitions below can be defined in a separate include file with name lcd_definitions.h instead modifying this file
+ * by adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile
+ * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
+ */
+#ifdef _LCD_DEFINITIONS_FILE
+# include "lcd_definitions.h"
+#endif
+
+/**
+ * @name Definition for LCD controller type
+ * Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller.
+ */
+#ifndef LCD_CONTROLLER_KS0073
+# define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */
+#endif
+
+/**
+ * @name Definitions for Display Size
+ * Change these definitions to adapt setting to your display
+ *
+ * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
+ * adding -D_LCD_DEFINITIONS_FILE to the CDEFS section in the Makefile.
+ * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
+ *
+ */
+#ifndef LCD_LINES
+# define LCD_LINES 2 /**< number of visible lines of the display */
+#endif
+#ifndef LCD_DISP_LENGTH
+# define LCD_DISP_LENGTH 16 /**< visibles characters per line of the display */
+#endif
+#ifndef LCD_LINE_LENGTH
+# define LCD_LINE_LENGTH 0x40 /**< internal line length of the display */
+#endif
+#ifndef LCD_START_LINE1
+# define LCD_START_LINE1 0x00 /**< DDRAM address of first char of line 1 */
+#endif
+#ifndef LCD_START_LINE2
+# define LCD_START_LINE2 0x40 /**< DDRAM address of first char of line 2 */
+#endif
+#ifndef LCD_START_LINE3
+# define LCD_START_LINE3 0x14 /**< DDRAM address of first char of line 3 */
+#endif
+#ifndef LCD_START_LINE4
+# define LCD_START_LINE4 0x54 /**< DDRAM address of first char of line 4 */
+#endif
+#ifndef LCD_WRAP_LINES
+# define LCD_WRAP_LINES 0 /**< 0: no wrap, 1: wrap at end of visibile line */
+#endif
+
+/**
+ * @name Definitions for 4-bit IO mode
+ *
+ * The four LCD data lines and the three control lines RS, RW, E can be on the
+ * same port or on different ports.
+ * Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on
+ * different ports.
+ *
+ * Normally the four data lines should be mapped to bit 0..3 on one port, but it
+ * is possible to connect these data lines in different order or even on different
+ * ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions.
+ *
+ * Adjust these definitions to your target.\n
+ * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
+ * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile.
+ * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
+ *
+ */
+#define LCD_IO_MODE 1 /**< 0: memory mapped mode, 1: IO port mode */
+
+#if LCD_IO_MODE
+
+# ifndef LCD_PORT
+# define LCD_PORT PORTA /**< port for the LCD lines */
+# endif
+# ifndef LCD_DATA0_PORT
+# define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */
+# endif
+# ifndef LCD_DATA1_PORT
+# define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */
+# endif
+# ifndef LCD_DATA2_PORT
+# define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */
+# endif
+# ifndef LCD_DATA3_PORT
+# define LCD_DATA3_PORT LCD_PORT /**< port for 4bit data bit 3 */
+# endif
+# ifndef LCD_DATA0_PIN
+# define LCD_DATA0_PIN 4 /**< pin for 4bit data bit 0 */
+# endif
+# ifndef LCD_DATA1_PIN
+# define LCD_DATA1_PIN 5 /**< pin for 4bit data bit 1 */
+# endif
+# ifndef LCD_DATA2_PIN
+# define LCD_DATA2_PIN 6 /**< pin for 4bit data bit 2 */
+# endif
+# ifndef LCD_DATA3_PIN
+# define LCD_DATA3_PIN 7 /**< pin for 4bit data bit 3 */
+# endif
+# ifndef LCD_RS_PORT
+# define LCD_RS_PORT LCD_PORT /**< port for RS line */
+# endif
+# ifndef LCD_RS_PIN
+# define LCD_RS_PIN 3 /**< pin for RS line */
+# endif
+# ifndef LCD_RW_PORT
+# define LCD_RW_PORT LCD_PORT /**< port for RW line */
+# endif
+# ifndef LCD_RW_PIN
+# define LCD_RW_PIN 2 /**< pin for RW line */
+# endif
+# ifndef LCD_E_PORT
+# define LCD_E_PORT LCD_PORT /**< port for Enable line */
+# endif
+# ifndef LCD_E_PIN
+# define LCD_E_PIN 1 /**< pin for Enable line */
+# endif
+
+#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__)
+/*
+ * memory mapped mode is only supported when the device has an external data memory interface
+ */
+# define LCD_IO_DATA 0xC000 /* A15=E=1, A14=RS=1 */
+# define LCD_IO_FUNCTION 0x8000 /* A15=E=1, A14=RS=0 */
+# define LCD_IO_READ 0x0100 /* A8 =R/W=1 (R/W: 1=Read, 0=Write */
+
+#else
+# error "external data memory interface not available for this device, use 4-bit IO port mode"
+
+#endif
+
+/**
+ * @name Definitions of delays
+ * Used to calculate delay timers.
+ * Adapt the F_CPU define in the Makefile to the clock frequency in Hz of your target
+ *
+ * These delay times can be adjusted, if some displays require different delays.\n
+ * These definitions can be defined in a separate include file \b lcd_definitions.h instead modifying this file by
+ * adding \b -D_LCD_DEFINITIONS_FILE to the \b CDEFS section in the Makefile.
+ * All definitions added to the file lcd_definitions.h will override the default definitions from lcd.h
+ */
+#ifndef LCD_DELAY_BOOTUP
+# define LCD_DELAY_BOOTUP 16000 /**< delay in micro seconds after power-on */
+#endif
+#ifndef LCD_DELAY_INIT
+# define LCD_DELAY_INIT 5000 /**< delay in micro seconds after initialization command sent */
+#endif
+#ifndef LCD_DELAY_INIT_REP
+# define LCD_DELAY_INIT_REP 64 /**< delay in micro seconds after initialization command repeated */
+#endif
+#ifndef LCD_DELAY_INIT_4BIT
+# define LCD_DELAY_INIT_4BIT 64 /**< delay in micro seconds after setting 4-bit mode */
+#endif
+#ifndef LCD_DELAY_BUSY_FLAG
+# define LCD_DELAY_BUSY_FLAG 4 /**< time in micro seconds the address counter is updated after busy flag is cleared */
+#endif
+#ifndef LCD_DELAY_ENABLE_PULSE
+# define LCD_DELAY_ENABLE_PULSE 1 /**< enable signal pulse width in micro seconds */
+#endif
+
+/**
+ * @name Definitions for LCD command instructions
+ * The constants define the various LCD controller instructions which can be passed to the
+ * function lcd_command(), see HD44780 data sheet for a complete description.
+ */
+
+/* instruction register bit positions, see HD44780U data sheet */
+#define LCD_CLR 0 /* DB0: clear display */
+#define LCD_HOME 1 /* DB1: return to home position */
+#define LCD_ENTRY_MODE 2 /* DB2: set entry mode */
+#define LCD_ENTRY_INC 1 /* DB1: 1=increment, 0=decrement */
+#define LCD_ENTRY_SHIFT 0 /* DB2: 1=display shift on */
+#define LCD_ON 3 /* DB3: turn lcd/cursor on */
+#define LCD_ON_DISPLAY 2 /* DB2: turn display on */
+#define LCD_ON_CURSOR 1 /* DB1: turn cursor on */
+#define LCD_ON_BLINK 0 /* DB0: blinking cursor ? */
+#define LCD_MOVE 4 /* DB4: move cursor/display */
+#define LCD_MOVE_DISP 3 /* DB3: move display (0-> cursor) ? */
+#define LCD_MOVE_RIGHT 2 /* DB2: move right (0-> left) ? */
+#define LCD_FUNCTION 5 /* DB5: function set */
+#define LCD_FUNCTION_8BIT 4 /* DB4: set 8BIT mode (0->4BIT mode) */
+#define LCD_FUNCTION_2LINES 3 /* DB3: two lines (0->one line) */
+#define LCD_FUNCTION_10DOTS 2 /* DB2: 5x10 font (0->5x7 font) */
+#define LCD_CGRAM 6 /* DB6: set CG RAM address */
+#define LCD_DDRAM 7 /* DB7: set DD RAM address */
+#define LCD_BUSY 7 /* DB7: LCD is busy */
+
+/* set entry mode: display shift on/off, dec/inc cursor move direction */
+#define LCD_ENTRY_DEC 0x04 /* display shift off, dec cursor move dir */
+#define LCD_ENTRY_DEC_SHIFT 0x05 /* display shift on, dec cursor move dir */
+#define LCD_ENTRY_INC_ 0x06 /* display shift off, inc cursor move dir */
+#define LCD_ENTRY_INC_SHIFT 0x07 /* display shift on, inc cursor move dir */
+
+/* display on/off, cursor on/off, blinking char at cursor position */
+#define LCD_DISP_OFF 0x08 /* display off */
+#define LCD_DISP_ON 0x0C /* display on, cursor off */
+#define LCD_DISP_ON_BLINK 0x0D /* display on, cursor off, blink char */
+#define LCD_DISP_ON_CURSOR 0x0E /* display on, cursor on */
+#define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */
+
+/* move cursor/shift display */
+#define LCD_MOVE_CURSOR_LEFT 0x10 /* move cursor left (decrement) */
+#define LCD_MOVE_CURSOR_RIGHT 0x14 /* move cursor right (increment) */
+#define LCD_MOVE_DISP_LEFT 0x18 /* shift display left */
+#define LCD_MOVE_DISP_RIGHT 0x1C /* shift display right */
+
+/* function set: set interface data length and number of display lines */
+#define LCD_FUNCTION_4BIT_1LINE 0x20 /* 4-bit interface, single line, 5x7 dots */
+#define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line, 5x7 dots */
+#define LCD_FUNCTION_8BIT_1LINE 0x30 /* 8-bit interface, single line, 5x7 dots */
+#define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line, 5x7 dots */
+
+#define LCD_MODE_DEFAULT ((1 << LCD_ENTRY_MODE) | (1 << LCD_ENTRY_INC))
+
+/**
+ * @name Functions
+ */
+
+/**
+ @brief Initialize display and select type of cursor
+ @param dispAttr \b LCD_DISP_OFF display off\n
+ \b LCD_DISP_ON display on, cursor off\n
+ \b LCD_DISP_ON_CURSOR display on, cursor on\n
+ \b LCD_DISP_ON_CURSOR_BLINK display on, cursor on flashing
+ @return none
+*/
+extern void lcd_init(uint8_t dispAttr);
+
+/**
+ @brief Clear display and set cursor to home position
+ @return none
+*/
+extern void lcd_clrscr(void);
+
+/**
+ @brief Set cursor to home position
+ @return none
+*/
+extern void lcd_home(void);
+
+/**
+ @brief Set cursor to specified position
+
+ @param x horizontal position\n (0: left most position)
+ @param y vertical position\n (0: first line)
+ @return none
+*/
+extern void lcd_gotoxy(uint8_t x, uint8_t y);
+
+/**
+ @brief Display character at current cursor position
+ @param c character to be displayed
+ @return none
+*/
+extern void lcd_putc(char c);
+
+/**
+ @brief Display string without auto linefeed
+ @param s string to be displayed
+ @return none
+*/
+extern void lcd_puts(const char *s);
+
+/**
+ @brief Display string from program memory without auto linefeed
+ @param progmem_s string from program memory be be displayed
+ @return none
+ @see lcd_puts_P
+*/
+extern void lcd_puts_p(const char *progmem_s);
+
+/**
+ @brief Send LCD controller instruction command
+ @param cmd instruction to send to LCD controller, see HD44780 data sheet
+ @return none
+*/
+extern void lcd_command(uint8_t cmd);
+
+/**
+ @brief Send data byte to LCD controller
+
+ Similar to lcd_putc(), but without interpreting LF
+ @param data byte to send to LCD controller, see HD44780 data sheet
+ @return none
+*/
+extern void lcd_data(uint8_t data);
+
+/**
+ @brief macros for automatically storing string constant in program memory
+*/
+#define lcd_puts_P(__s) lcd_puts_p(PSTR(__s))
+
+/**@}*/
diff --git a/platforms/avr/drivers/i2c_master.c b/platforms/avr/drivers/i2c_master.c
new file mode 100644
index 0000000000..2773e00778
--- /dev/null
+++ b/platforms/avr/drivers/i2c_master.c
@@ -0,0 +1,241 @@
+/* Copyright (C) 2019 Elia Ritterbusch
+ +
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+/* Library made by: g4lvanix
+ * GitHub repository: https://github.com/g4lvanix/I2C-master-lib
+ */
+
+#include
+#include
+
+#include "i2c_master.h"
+#include "timer.h"
+#include "wait.h"
+
+#ifndef F_SCL
+# define F_SCL 400000UL // SCL frequency
+#endif
+
+#ifndef I2C_START_RETRY_COUNT
+# define I2C_START_RETRY_COUNT 20
+#endif // I2C_START_RETRY_COUNT
+
+#define TWBR_val (((F_CPU / F_SCL) - 16) / 2)
+
+#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+
+void i2c_init(void) {
+ TWSR = 0; /* no prescaler */
+ TWBR = (uint8_t)TWBR_val;
+
+#ifdef __AVR_ATmega32A__
+ // set pull-up resistors on I2C bus pins
+ PORTC |= 0b11;
+
+ // enable TWI (two-wire interface)
+ TWCR |= (1 << TWEN);
+
+ // enable TWI interrupt and slave address ACK
+ TWCR |= (1 << TWIE);
+ TWCR |= (1 << TWEA);
+#endif
+}
+
+static i2c_status_t i2c_start_impl(uint8_t address, uint16_t timeout) {
+ // reset TWI control register
+ TWCR = 0;
+ // transmit START condition
+ TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
+
+ uint16_t timeout_timer = timer_read();
+ while (!(TWCR & (1 << TWINT))) {
+ if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+ return I2C_STATUS_TIMEOUT;
+ }
+ }
+
+ // check if the start condition was successfully transmitted
+ if (((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)) {
+ return I2C_STATUS_ERROR;
+ }
+
+ // load slave address into data register
+ TWDR = address;
+ // start transmission of address
+ TWCR = (1 << TWINT) | (1 << TWEN);
+
+ timeout_timer = timer_read();
+ while (!(TWCR & (1 << TWINT))) {
+ if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+ return I2C_STATUS_TIMEOUT;
+ }
+ }
+
+ // check if the device has acknowledged the READ / WRITE mode
+ uint8_t twst = TW_STATUS & 0xF8;
+ if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
+ return I2C_STATUS_ERROR;
+ }
+
+ return I2C_STATUS_SUCCESS;
+}
+
+i2c_status_t i2c_start(uint8_t address, uint16_t timeout) {
+ // Retry i2c_start_impl a bunch times in case the remote side has interrupts disabled.
+ uint16_t timeout_timer = timer_read();
+ uint16_t time_slice = MAX(1, (timeout == (I2C_TIMEOUT_INFINITE)) ? 5 : (timeout / (I2C_START_RETRY_COUNT))); // if it's infinite, wait 1ms between attempts, otherwise split up the entire timeout into the number of retries
+ i2c_status_t status;
+ do {
+ status = i2c_start_impl(address, time_slice);
+ } while ((status < 0) && ((timeout == I2C_TIMEOUT_INFINITE) || (timer_elapsed(timeout_timer) < timeout)));
+ return status;
+}
+
+i2c_status_t i2c_write(uint8_t data, uint16_t timeout) {
+ // load data into data register
+ TWDR = data;
+ // start transmission of data
+ TWCR = (1 << TWINT) | (1 << TWEN);
+
+ uint16_t timeout_timer = timer_read();
+ while (!(TWCR & (1 << TWINT))) {
+ if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+ return I2C_STATUS_TIMEOUT;
+ }
+ }
+
+ if ((TW_STATUS & 0xF8) != TW_MT_DATA_ACK) {
+ return I2C_STATUS_ERROR;
+ }
+
+ return I2C_STATUS_SUCCESS;
+}
+
+int16_t i2c_read_ack(uint16_t timeout) {
+ // start TWI module and acknowledge data after reception
+ TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
+
+ uint16_t timeout_timer = timer_read();
+ while (!(TWCR & (1 << TWINT))) {
+ if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+ return I2C_STATUS_TIMEOUT;
+ }
+ }
+
+ // return received data from TWDR
+ return TWDR;
+}
+
+int16_t i2c_read_nack(uint16_t timeout) {
+ // start receiving without acknowledging reception
+ TWCR = (1 << TWINT) | (1 << TWEN);
+
+ uint16_t timeout_timer = timer_read();
+ while (!(TWCR & (1 << TWINT))) {
+ if ((timeout != I2C_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
+ return I2C_STATUS_TIMEOUT;
+ }
+ }
+
+ // return received data from TWDR
+ return TWDR;
+}
+
+i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout) {
+ i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
+
+ for (uint16_t i = 0; i < length && status >= 0; i++) {
+ status = i2c_write(data[i], timeout);
+ }
+
+ i2c_stop();
+
+ return status;
+}
+
+i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) {
+ i2c_status_t status = i2c_start(address | I2C_READ, timeout);
+
+ for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
+ status = i2c_read_ack(timeout);
+ if (status >= 0) {
+ data[i] = status;
+ }
+ }
+
+ if (status >= 0) {
+ status = i2c_read_nack(timeout);
+ if (status >= 0) {
+ data[(length - 1)] = status;
+ }
+ }
+
+ i2c_stop();
+
+ return (status < 0) ? status : I2C_STATUS_SUCCESS;
+}
+
+i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
+ i2c_status_t status = i2c_start(devaddr | 0x00, timeout);
+ if (status >= 0) {
+ status = i2c_write(regaddr, timeout);
+
+ for (uint16_t i = 0; i < length && status >= 0; i++) {
+ status = i2c_write(data[i], timeout);
+ }
+ }
+
+ i2c_stop();
+
+ return status;
+}
+
+i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
+ i2c_status_t status = i2c_start(devaddr, timeout);
+ if (status < 0) {
+ goto error;
+ }
+
+ status = i2c_write(regaddr, timeout);
+ if (status < 0) {
+ goto error;
+ }
+
+ status = i2c_start(devaddr | 0x01, timeout);
+
+ for (uint16_t i = 0; i < (length - 1) && status >= 0; i++) {
+ status = i2c_read_ack(timeout);
+ if (status >= 0) {
+ data[i] = status;
+ }
+ }
+
+ if (status >= 0) {
+ status = i2c_read_nack(timeout);
+ if (status >= 0) {
+ data[(length - 1)] = status;
+ }
+ }
+
+error:
+ i2c_stop();
+
+ return (status < 0) ? status : I2C_STATUS_SUCCESS;
+}
+
+void i2c_stop(void) {
+ // transmit STOP condition
+ TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
+}
diff --git a/platforms/avr/drivers/i2c_master.h b/platforms/avr/drivers/i2c_master.h
new file mode 100644
index 0000000000..e5af73364b
--- /dev/null
+++ b/platforms/avr/drivers/i2c_master.h
@@ -0,0 +1,43 @@
+/* Copyright (C) 2019 Elia Ritterbusch
+ +
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+/* Library made by: g4lvanix
+ * GitHub repository: https://github.com/g4lvanix/I2C-master-lib
+ */
+
+#pragma once
+
+#define I2C_READ 0x01
+#define I2C_WRITE 0x00
+
+typedef int16_t i2c_status_t;
+
+#define I2C_STATUS_SUCCESS (0)
+#define I2C_STATUS_ERROR (-1)
+#define I2C_STATUS_TIMEOUT (-2)
+
+#define I2C_TIMEOUT_IMMEDIATE (0)
+#define I2C_TIMEOUT_INFINITE (0xFFFF)
+
+void i2c_init(void);
+i2c_status_t i2c_start(uint8_t address, uint16_t timeout);
+i2c_status_t i2c_write(uint8_t data, uint16_t timeout);
+int16_t i2c_read_ack(uint16_t timeout);
+int16_t i2c_read_nack(uint16_t timeout);
+i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout);
+i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
+i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
+i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
+void i2c_stop(void);
diff --git a/platforms/avr/drivers/i2c_slave.c b/platforms/avr/drivers/i2c_slave.c
new file mode 100644
index 0000000000..2907f164c0
--- /dev/null
+++ b/platforms/avr/drivers/i2c_slave.c
@@ -0,0 +1,111 @@
+/* Copyright (C) 2019 Elia Ritterbusch
+ +
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+/* Library made by: g4lvanix
+ * GitHub repository: https://github.com/g4lvanix/I2C-slave-lib
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include "i2c_slave.h"
+
+#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+# include "transactions.h"
+
+static volatile bool is_callback_executor = false;
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+
+volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
+
+static volatile uint8_t buffer_address;
+static volatile bool slave_has_register_set = false;
+
+void i2c_slave_init(uint8_t address) {
+ // load address into TWI address register
+ TWAR = address;
+ // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt
+ TWCR = (1 << TWIE) | (1 << TWEA) | (1 << TWINT) | (1 << TWEN);
+}
+
+void i2c_slave_stop(void) {
+ // clear acknowledge and enable bits
+ TWCR &= ~((1 << TWEA) | (1 << TWEN));
+}
+
+ISR(TWI_vect) {
+ uint8_t ack = 1;
+
+ switch (TW_STATUS) {
+ case TW_SR_SLA_ACK:
+ // The device is now a slave receiver
+ slave_has_register_set = false;
+#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ is_callback_executor = false;
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ break;
+
+ case TW_SR_DATA_ACK:
+ // This device is a slave receiver and has received data
+ // First byte is the location then the bytes will be writen in buffer with auto-increment
+ if (!slave_has_register_set) {
+ buffer_address = TWDR;
+
+ if (buffer_address >= I2C_SLAVE_REG_COUNT) { // address out of bounds dont ack
+ ack = 0;
+ buffer_address = 0;
+ }
+ slave_has_register_set = true; // address has been received now fill in buffer
+
+#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ // Work out if we're attempting to execute a callback
+ is_callback_executor = buffer_address == split_transaction_table[I2C_EXECUTE_CALLBACK].initiator2target_offset;
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ } else {
+ i2c_slave_reg[buffer_address] = TWDR;
+ buffer_address++;
+
+#if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ // If we're intending to execute a transaction callback, do so, as we've just received the transaction ID
+ if (is_callback_executor) {
+ split_transaction_desc_t *trans = &split_transaction_table[split_shmem->transaction_id];
+ if (trans->slave_callback) {
+ trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
+ }
+ }
+#endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+ }
+ break;
+
+ case TW_ST_SLA_ACK:
+ case TW_ST_DATA_ACK:
+ // This device is a slave transmitter and master has requested data
+ TWDR = i2c_slave_reg[buffer_address];
+ buffer_address++;
+ break;
+
+ case TW_BUS_ERROR:
+ // We got an error, reset i2c
+ TWCR = 0;
+ default:
+ break;
+ }
+
+ // Reset i2c state machine to be ready for next interrupt
+ TWCR |= (1 << TWIE) | (1 << TWINT) | (ack << TWEA) | (1 << TWEN);
+}
diff --git a/platforms/avr/drivers/i2c_slave.h b/platforms/avr/drivers/i2c_slave.h
new file mode 100644
index 0000000000..a8647c9da3
--- /dev/null
+++ b/platforms/avr/drivers/i2c_slave.h
@@ -0,0 +1,41 @@
+/* Copyright (C) 2019 Elia Ritterbusch
+ +
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+/* Library made by: g4lvanix
+ * GitHub repository: https://github.com/g4lvanix/I2C-slave-lib
+
+ Info: Inititate the library by giving the required address.
+ Read or write to the necessary buffer according to the opperation.
+ */
+
+#pragma once
+
+#ifndef I2C_SLAVE_REG_COUNT
+
+# if defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+# include "transport.h"
+# define I2C_SLAVE_REG_COUNT sizeof(split_shared_memory_t)
+# else // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+# define I2C_SLAVE_REG_COUNT 30
+# endif // defined(USE_I2C) && defined(SPLIT_COMMON_TRANSACTIONS)
+
+#endif // I2C_SLAVE_REG_COUNT
+
+_Static_assert(I2C_SLAVE_REG_COUNT < 256, "I2C target registers must be single byte");
+
+extern volatile uint8_t i2c_slave_reg[I2C_SLAVE_REG_COUNT];
+
+void i2c_slave_init(uint8_t address);
+void i2c_slave_stop(void);
diff --git a/platforms/avr/drivers/serial.c b/platforms/avr/drivers/serial.c
new file mode 100644
index 0000000000..9a7345a53d
--- /dev/null
+++ b/platforms/avr/drivers/serial.c
@@ -0,0 +1,529 @@
+/*
+ * WARNING: be careful changing this code, it is very timing dependent
+ *
+ * 2018-10-28 checked
+ * avr-gcc 4.9.2
+ * avr-gcc 5.4.0
+ * avr-gcc 7.3.0
+ */
+
+#ifndef F_CPU
+# define F_CPU 16000000
+#endif
+
+#include
+#include
+#include
+#include
+#include
+#include "serial.h"
+
+#ifdef SOFT_SERIAL_PIN
+
+# if !(defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
+# error serial.c is not supported for the currently selected MCU
+# endif
+// if using ATmega32U4/2, AT90USBxxx I2C, can not use PD0 and PD1 in soft serial.
+# if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
+# if defined(USE_AVR_I2C) && (SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1)
+# error Using I2C, so can not use PD0, PD1
+# endif
+# endif
+// PD0..PD3, common config
+# if SOFT_SERIAL_PIN == D0
+# define EIMSK_BIT _BV(INT0)
+# define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01)))
+# define SERIAL_PIN_INTERRUPT INT0_vect
+# define EICRx EICRA
+# elif SOFT_SERIAL_PIN == D1
+# define EIMSK_BIT _BV(INT1)
+# define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11)))
+# define SERIAL_PIN_INTERRUPT INT1_vect
+# define EICRx EICRA
+# elif SOFT_SERIAL_PIN == D2
+# define EIMSK_BIT _BV(INT2)
+# define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21)))
+# define SERIAL_PIN_INTERRUPT INT2_vect
+# define EICRx EICRA
+# elif SOFT_SERIAL_PIN == D3
+# define EIMSK_BIT _BV(INT3)
+# define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31)))
+# define SERIAL_PIN_INTERRUPT INT3_vect
+# define EICRx EICRA
+# endif
+
+// ATmegaxxU2/AT90USB162 specific config
+# if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_AT90USB162__)
+// PD4(INT5), PD6(INT6), PD7(INT7), PC7(INT4)
+# if SOFT_SERIAL_PIN == D4
+# define EIMSK_BIT _BV(INT5)
+# define EICRx_BIT (~(_BV(ISC50) | _BV(ISC51)))
+# define SERIAL_PIN_INTERRUPT INT5_vect
+# define EICRx EICRB
+# elif SOFT_SERIAL_PIN == D6
+# define EIMSK_BIT _BV(INT6)
+# define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
+# define SERIAL_PIN_INTERRUPT INT6_vect
+# define EICRx EICRB
+# elif SOFT_SERIAL_PIN == D7
+# define EIMSK_BIT _BV(INT7)
+# define EICRx_BIT (~(_BV(ISC70) | _BV(ISC71)))
+# define SERIAL_PIN_INTERRUPT INT7_vect
+# define EICRx EICRB
+# elif SOFT_SERIAL_PIN == C7
+# define EIMSK_BIT _BV(INT4)
+# define EICRx_BIT (~(_BV(ISC40) | _BV(ISC41)))
+# define SERIAL_PIN_INTERRUPT INT4_vect
+# define EICRx EICRB
+# endif
+# endif
+
+// ATmegaxxU4 specific config
+# if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
+// PE6(INT6)
+# if SOFT_SERIAL_PIN == E6
+# define EIMSK_BIT _BV(INT6)
+# define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
+# define SERIAL_PIN_INTERRUPT INT6_vect
+# define EICRx EICRB
+# endif
+# endif
+
+// AT90USBxxx specific config
+# if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
+// PE4..PE7(INT4..INT7)
+# if SOFT_SERIAL_PIN == E4
+# define EIMSK_BIT _BV(INT4)
+# define EICRx_BIT (~(_BV(ISC40) | _BV(ISC41)))
+# define SERIAL_PIN_INTERRUPT INT4_vect
+# define EICRx EICRB
+# elif SOFT_SERIAL_PIN == E5
+# define EIMSK_BIT _BV(INT5)
+# define EICRx_BIT (~(_BV(ISC50) | _BV(ISC51)))
+# define SERIAL_PIN_INTERRUPT INT5_vect
+# define EICRx EICRB
+# elif SOFT_SERIAL_PIN == E6
+# define EIMSK_BIT _BV(INT6)
+# define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
+# define SERIAL_PIN_INTERRUPT INT6_vect
+# define EICRx EICRB
+# elif SOFT_SERIAL_PIN == E7
+# define EIMSK_BIT _BV(INT7)
+# define EICRx_BIT (~(_BV(ISC70) | _BV(ISC71)))
+# define SERIAL_PIN_INTERRUPT INT7_vect
+# define EICRx EICRB
+# endif
+# endif
+
+# ifndef SERIAL_PIN_INTERRUPT
+# error invalid SOFT_SERIAL_PIN value
+# endif
+
+# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
+# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
+# define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
+# define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
+# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
+
+# define ALWAYS_INLINE __attribute__((always_inline))
+# define NO_INLINE __attribute__((noinline))
+# define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
+
+// parity check
+# define ODD_PARITY 1
+# define EVEN_PARITY 0
+# define PARITY EVEN_PARITY
+
+# ifdef SERIAL_DELAY
+// custom setup in config.h
+// #define TID_SEND_ADJUST 2
+// #define SERIAL_DELAY 6 // micro sec
+// #define READ_WRITE_START_ADJUST 30 // cycles
+// #define READ_WRITE_WIDTH_ADJUST 8 // cycles
+# else
+// ============ Standard setups ============
+
+# ifndef SELECT_SOFT_SERIAL_SPEED
+# define SELECT_SOFT_SERIAL_SPEED 1
+// 0: about 189kbps (Experimental only)
+// 1: about 137kbps (default)
+// 2: about 75kbps
+// 3: about 39kbps
+// 4: about 26kbps
+// 5: about 20kbps
+# endif
+
+# if __GNUC__ < 6
+# define TID_SEND_ADJUST 14
+# else
+# define TID_SEND_ADJUST 2
+# endif
+
+# if SELECT_SOFT_SERIAL_SPEED == 0
+// Very High speed
+# define SERIAL_DELAY 4 // micro sec
+# if __GNUC__ < 6
+# define READ_WRITE_START_ADJUST 33 // cycles
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# else
+# define READ_WRITE_START_ADJUST 34 // cycles
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# endif
+# elif SELECT_SOFT_SERIAL_SPEED == 1
+// High speed
+# define SERIAL_DELAY 6 // micro sec
+# if __GNUC__ < 6
+# define READ_WRITE_START_ADJUST 30 // cycles
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# else
+# define READ_WRITE_START_ADJUST 33 // cycles
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# endif
+# elif SELECT_SOFT_SERIAL_SPEED == 2
+// Middle speed
+# define SERIAL_DELAY 12 // micro sec
+# define READ_WRITE_START_ADJUST 30 // cycles
+# if __GNUC__ < 6
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# else
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# endif
+# elif SELECT_SOFT_SERIAL_SPEED == 3
+// Low speed
+# define SERIAL_DELAY 24 // micro sec
+# define READ_WRITE_START_ADJUST 30 // cycles
+# if __GNUC__ < 6
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# else
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# endif
+# elif SELECT_SOFT_SERIAL_SPEED == 4
+// Very Low speed
+# define SERIAL_DELAY 36 // micro sec
+# define READ_WRITE_START_ADJUST 30 // cycles
+# if __GNUC__ < 6
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# else
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# endif
+# elif SELECT_SOFT_SERIAL_SPEED == 5
+// Ultra Low speed
+# define SERIAL_DELAY 48 // micro sec
+# define READ_WRITE_START_ADJUST 30 // cycles
+# if __GNUC__ < 6
+# define READ_WRITE_WIDTH_ADJUST 3 // cycles
+# else
+# define READ_WRITE_WIDTH_ADJUST 7 // cycles
+# endif
+# else
+# error invalid SELECT_SOFT_SERIAL_SPEED value
+# endif /* SELECT_SOFT_SERIAL_SPEED */
+# endif /* SERIAL_DELAY */
+
+# define SERIAL_DELAY_HALF1 (SERIAL_DELAY / 2)
+# define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY / 2)
+
+# define SLAVE_INT_WIDTH_US 1
+# define SLAVE_INT_ACK_WIDTH_UNIT 2
+# define SLAVE_INT_ACK_WIDTH 4
+
+inline static void serial_delay(void) ALWAYS_INLINE;
+inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
+
+inline static void serial_delay_half1(void) ALWAYS_INLINE;
+inline static void serial_delay_half1(void) { _delay_us(SERIAL_DELAY_HALF1); }
+
+inline static void serial_delay_half2(void) ALWAYS_INLINE;
+inline static void serial_delay_half2(void) { _delay_us(SERIAL_DELAY_HALF2); }
+
+inline static void serial_output(void) ALWAYS_INLINE;
+inline static void serial_output(void) { setPinOutput(SOFT_SERIAL_PIN); }
+
+// make the serial pin an input with pull-up resistor
+inline static void serial_input_with_pullup(void) ALWAYS_INLINE;
+inline static void serial_input_with_pullup(void) { setPinInputHigh(SOFT_SERIAL_PIN); }
+
+inline static uint8_t serial_read_pin(void) ALWAYS_INLINE;
+inline static uint8_t serial_read_pin(void) { return !!readPin(SOFT_SERIAL_PIN); }
+
+inline static void serial_low(void) ALWAYS_INLINE;
+inline static void serial_low(void) { writePinLow(SOFT_SERIAL_PIN); }
+
+inline static void serial_high(void) ALWAYS_INLINE;
+inline static void serial_high(void) { writePinHigh(SOFT_SERIAL_PIN); }
+
+void soft_serial_initiator_init(void) {
+ serial_output();
+ serial_high();
+}
+
+void soft_serial_target_init(void) {
+ serial_input_with_pullup();
+
+ // Enable INT0-INT7
+ EIMSK |= EIMSK_BIT;
+ EICRx &= EICRx_BIT;
+}
+
+// Used by the sender to synchronize timing with the reciver.
+static void sync_recv(void) NO_INLINE;
+static void sync_recv(void) {
+ for (uint8_t i = 0; i < SERIAL_DELAY * 5 && serial_read_pin(); i++) {
+ }
+ // This shouldn't hang if the target disconnects because the
+ // serial line will float to high if the target does disconnect.
+ while (!serial_read_pin())
+ ;
+}
+
+// Used by the reciver to send a synchronization signal to the sender.
+static void sync_send(void) NO_INLINE;
+static void sync_send(void) {
+ serial_low();
+ serial_delay();
+ serial_high();
+}
+
+// Reads a byte from the serial line
+static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) NO_INLINE;
+static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
+ uint8_t byte, i, p, pb;
+
+ _delay_sub_us(READ_WRITE_START_ADJUST);
+ for (i = 0, byte = 0, p = PARITY; i < bit; i++) {
+ serial_delay_half1(); // read the middle of pulses
+ if (serial_read_pin()) {
+ byte = (byte << 1) | 1;
+ p ^= 1;
+ } else {
+ byte = (byte << 1) | 0;
+ p ^= 0;
+ }
+ _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
+ serial_delay_half2();
+ }
+ /* recive parity bit */
+ serial_delay_half1(); // read the middle of pulses
+ pb = serial_read_pin();
+ _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
+ serial_delay_half2();
+
+ *pterrcount += (p != pb) ? 1 : 0;
+
+ return byte;
+}
+
+// Sends a byte with MSB ordering
+void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE;
+void serial_write_chunk(uint8_t data, uint8_t bit) {
+ uint8_t b, p;
+ for (p = PARITY, b = 1 << (bit - 1); b; b >>= 1) {
+ if (data & b) {
+ serial_high();
+ p ^= 1;
+ } else {
+ serial_low();
+ p ^= 0;
+ }
+ serial_delay();
+ }
+ /* send parity bit */
+ if (p & 1) {
+ serial_high();
+ } else {
+ serial_low();
+ }
+ serial_delay();
+
+ serial_low(); // sync_send() / senc_recv() need raise edge
+}
+
+static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
+static void serial_send_packet(uint8_t *buffer, uint8_t size) {
+ for (uint8_t i = 0; i < size; ++i) {
+ uint8_t data;
+ data = buffer[i];
+ sync_send();
+ serial_write_chunk(data, 8);
+ }
+}
+
+static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
+static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
+ uint8_t pecount = 0;
+ for (uint8_t i = 0; i < size; ++i) {
+ uint8_t data;
+ sync_recv();
+ data = serial_read_chunk(&pecount, 8);
+ buffer[i] = data;
+ }
+ return pecount == 0;
+}
+
+inline static void change_sender2reciver(void) {
+ sync_send(); // 0
+ serial_delay_half1(); // 1
+ serial_low(); // 2
+ serial_input_with_pullup(); // 2
+ serial_delay_half1(); // 3
+}
+
+inline static void change_reciver2sender(void) {
+ sync_recv(); // 0
+ serial_delay(); // 1
+ serial_low(); // 3
+ serial_output(); // 3
+ serial_delay_half1(); // 4
+}
+
+static inline uint8_t nibble_bits_count(uint8_t bits) {
+ bits = (bits & 0x5) + (bits >> 1 & 0x5);
+ bits = (bits & 0x3) + (bits >> 2 & 0x3);
+ return bits;
+}
+
+// interrupt handle to be used by the target device
+ISR(SERIAL_PIN_INTERRUPT) {
+ // recive transaction table index
+ uint8_t tid, bits;
+ uint8_t pecount = 0;
+ sync_recv();
+ bits = serial_read_chunk(&pecount, 8);
+ tid = bits >> 3;
+ bits = (bits & 7) != (nibble_bits_count(tid) & 7);
+ if (bits || pecount > 0 || tid > NUM_TOTAL_TRANSACTIONS) {
+ return;
+ }
+ serial_delay_half1();
+
+ serial_high(); // response step1 low->high
+ serial_output();
+ _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT * SLAVE_INT_ACK_WIDTH);
+ split_transaction_desc_t *trans = &split_transaction_table[tid];
+ serial_low(); // response step2 ack high->low
+
+ // If the transaction has a callback, we can execute it now
+ if (trans->slave_callback) {
+ trans->slave_callback(trans->initiator2target_buffer_size, split_trans_initiator2target_buffer(trans), trans->target2initiator_buffer_size, split_trans_target2initiator_buffer(trans));
+ }
+
+ // target send phase
+ if (trans->target2initiator_buffer_size > 0) serial_send_packet((uint8_t *)split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size);
+ // target switch to input
+ change_sender2reciver();
+
+ // target recive phase
+ if (trans->initiator2target_buffer_size > 0) {
+ if (serial_recive_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
+ *trans->status = TRANSACTION_ACCEPTED;
+ } else {
+ *trans->status = TRANSACTION_DATA_ERROR;
+ }
+ } else {
+ *trans->status = TRANSACTION_ACCEPTED;
+ }
+
+ sync_recv(); // weit initiator output to high
+}
+
+/////////
+// start transaction by initiator
+//
+// int soft_serial_transaction(int sstd_index)
+//
+// Returns:
+// TRANSACTION_END
+// TRANSACTION_NO_RESPONSE
+// TRANSACTION_DATA_ERROR
+// this code is very time dependent, so we need to disable interrupts
+int soft_serial_transaction(int sstd_index) {
+ if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
+ split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
+
+ if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
+
+ cli();
+
+ // signal to the target that we want to start a transaction
+ serial_output();
+ serial_low();
+ _delay_us(SLAVE_INT_WIDTH_US);
+
+ // send transaction table index
+ int tid = (sstd_index << 3) | (7 & nibble_bits_count(sstd_index));
+ sync_send();
+ _delay_sub_us(TID_SEND_ADJUST);
+ serial_write_chunk(tid, 8);
+ serial_delay_half1();
+
+ // wait for the target response (step1 low->high)
+ serial_input_with_pullup();
+ while (!serial_read_pin()) {
+ _delay_sub_us(2);
+ }
+
+ // check if the target is present (step2 high->low)
+ for (int i = 0; serial_read_pin(); i++) {
+ if (i > SLAVE_INT_ACK_WIDTH + 1) {
+ // slave failed to pull the line low, assume not present
+ serial_output();
+ serial_high();
+ *trans->status = TRANSACTION_NO_RESPONSE;
+ sei();
+ return TRANSACTION_NO_RESPONSE;
+ }
+ _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
+ }
+
+ // initiator recive phase
+ // if the target is present syncronize with it
+ if (trans->target2initiator_buffer_size > 0) {
+ if (!serial_recive_packet((uint8_t *)split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
+ serial_output();
+ serial_high();
+ *trans->status = TRANSACTION_DATA_ERROR;
+ sei();
+ return TRANSACTION_DATA_ERROR;
+ }
+ }
+
+ // initiator switch to output
+ change_reciver2sender();
+
+ // initiator send phase
+ if (trans->initiator2target_buffer_size > 0) {
+ serial_send_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size);
+ }
+
+ // always, release the line when not in use
+ sync_send();
+
+ *trans->status = TRANSACTION_END;
+ sei();
+ return TRANSACTION_END;
+}
+
+int soft_serial_get_and_clean_status(int sstd_index) {
+ split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
+ cli();
+ int retval = *trans->status;
+ *trans->status = 0;
+ ;
+ sei();
+ return retval;
+}
+#endif
+
+// Helix serial.c history
+// 2018-1-29 fork from let's split and add PD2, modify sync_recv() (#2308, bceffdefc)
+// 2018-6-28 bug fix master to slave comm and speed up (#3255, 1038bbef4)
+// (adjusted with avr-gcc 4.9.2)
+// 2018-7-13 remove USE_SERIAL_PD2 macro (#3374, f30d6dd78)
+// (adjusted with avr-gcc 4.9.2)
+// 2018-8-11 add support multi-type transaction (#3608, feb5e4aae)
+// (adjusted with avr-gcc 4.9.2)
+// 2018-10-21 fix serial and RGB animation conflict (#4191, 4665e4fff)
+// (adjusted with avr-gcc 7.3.0)
+// 2018-10-28 re-adjust compiler depend value of delay (#4269, 8517f8a66)
+// (adjusted with avr-gcc 5.4.0, 7.3.0)
+// 2018-12-17 copy to TOP/quantum/split_common/ and remove backward compatibility code (#4669)
diff --git a/platforms/avr/drivers/spi_master.c b/platforms/avr/drivers/spi_master.c
new file mode 100644
index 0000000000..4e8fd3bcdf
--- /dev/null
+++ b/platforms/avr/drivers/spi_master.c
@@ -0,0 +1,180 @@
+/* Copyright 2020
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "spi_master.h"
+
+#include "timer.h"
+
+#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
+# define SPI_SCK_PIN B1
+# define SPI_MOSI_PIN B2
+# define SPI_MISO_PIN B3
+#elif defined(__AVR_ATmega32A__)
+# define SPI_SCK_PIN B7
+# define SPI_MOSI_PIN B5
+# define SPI_MISO_PIN B6
+#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
+# define SPI_SCK_PIN B5
+# define SPI_MOSI_PIN B3
+# define SPI_MISO_PIN B4
+#endif
+
+#ifndef SPI_TIMEOUT
+# define SPI_TIMEOUT 100
+#endif
+
+static pin_t currentSlavePin = NO_PIN;
+static uint8_t currentSlaveConfig = 0;
+static bool currentSlave2X = false;
+
+void spi_init(void) {
+ writePinHigh(SPI_SS_PIN);
+ setPinOutput(SPI_SCK_PIN);
+ setPinOutput(SPI_MOSI_PIN);
+ setPinInput(SPI_MISO_PIN);
+
+ SPCR = (_BV(SPE) | _BV(MSTR));
+}
+
+bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) {
+ if (currentSlavePin != NO_PIN || slavePin == NO_PIN) {
+ return false;
+ }
+
+ currentSlaveConfig = 0;
+
+ if (lsbFirst) {
+ currentSlaveConfig |= _BV(DORD);
+ }
+
+ switch (mode) {
+ case 1:
+ currentSlaveConfig |= _BV(CPHA);
+ break;
+ case 2:
+ currentSlaveConfig |= _BV(CPOL);
+ break;
+ case 3:
+ currentSlaveConfig |= (_BV(CPOL) | _BV(CPHA));
+ break;
+ }
+
+ uint16_t roundedDivisor = 1;
+ while (roundedDivisor < divisor) {
+ roundedDivisor <<= 1;
+ }
+
+ switch (roundedDivisor) {
+ case 16:
+ currentSlaveConfig |= _BV(SPR0);
+ break;
+ case 64:
+ currentSlaveConfig |= _BV(SPR1);
+ break;
+ case 128:
+ currentSlaveConfig |= (_BV(SPR1) | _BV(SPR0));
+ break;
+ case 2:
+ currentSlave2X = true;
+ break;
+ case 8:
+ currentSlave2X = true;
+ currentSlaveConfig |= _BV(SPR0);
+ break;
+ case 32:
+ currentSlave2X = true;
+ currentSlaveConfig |= _BV(SPR1);
+ break;
+ }
+
+ SPCR |= currentSlaveConfig;
+ if (currentSlave2X) {
+ SPSR |= _BV(SPI2X);
+ }
+ currentSlavePin = slavePin;
+ setPinOutput(currentSlavePin);
+ writePinLow(currentSlavePin);
+
+ return true;
+}
+
+spi_status_t spi_write(uint8_t data) {
+ SPDR = data;
+
+ uint16_t timeout_timer = timer_read();
+ while (!(SPSR & _BV(SPIF))) {
+ if ((timer_read() - timeout_timer) >= SPI_TIMEOUT) {
+ return SPI_STATUS_TIMEOUT;
+ }
+ }
+
+ return SPDR;
+}
+
+spi_status_t spi_read() {
+ SPDR = 0x00; // Dummy
+
+ uint16_t timeout_timer = timer_read();
+ while (!(SPSR & _BV(SPIF))) {
+ if ((timer_read() - timeout_timer) >= SPI_TIMEOUT) {
+ return SPI_STATUS_TIMEOUT;
+ }
+ }
+
+ return SPDR;
+}
+
+spi_status_t spi_transmit(const uint8_t *data, uint16_t length) {
+ spi_status_t status;
+
+ for (uint16_t i = 0; i < length; i++) {
+ status = spi_write(data[i]);
+
+ if (status < 0) {
+ return status;
+ }
+ }
+
+ return SPI_STATUS_SUCCESS;
+}
+
+spi_status_t spi_receive(uint8_t *data, uint16_t length) {
+ spi_status_t status;
+
+ for (uint16_t i = 0; i < length; i++) {
+ status = spi_read();
+
+ if (status >= 0) {
+ data[i] = status;
+ } else {
+ return status;
+ }
+ }
+
+ return SPI_STATUS_SUCCESS;
+}
+
+void spi_stop(void) {
+ if (currentSlavePin != NO_PIN) {
+ setPinOutput(currentSlavePin);
+ writePinHigh(currentSlavePin);
+ currentSlavePin = NO_PIN;
+ SPSR &= ~(_BV(SPI2X));
+ SPCR &= ~(currentSlaveConfig);
+ currentSlaveConfig = 0;
+ currentSlave2X = false;
+ }
+}
diff --git a/platforms/avr/drivers/spi_master.h b/platforms/avr/drivers/spi_master.h
new file mode 100644
index 0000000000..8a30f47ae4
--- /dev/null
+++ b/platforms/avr/drivers/spi_master.h
@@ -0,0 +1,59 @@
+/* Copyright 2020
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+
+#include "gpio.h"
+
+typedef int16_t spi_status_t;
+
+// Hardware SS pin is defined in the header so that user code can refer to it
+#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
+# define SPI_SS_PIN B0
+#elif defined(__AVR_ATmega32A__)
+# define SPI_SS_PIN B4
+#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
+# define SPI_SS_PIN B2
+#endif
+
+#define SPI_STATUS_SUCCESS (0)
+#define SPI_STATUS_ERROR (-1)
+#define SPI_STATUS_TIMEOUT (-2)
+
+#define SPI_TIMEOUT_IMMEDIATE (0)
+#define SPI_TIMEOUT_INFINITE (0xFFFF)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+void spi_init(void);
+
+bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor);
+
+spi_status_t spi_write(uint8_t data);
+
+spi_status_t spi_read(void);
+
+spi_status_t spi_transmit(const uint8_t *data, uint16_t length);
+
+spi_status_t spi_receive(uint8_t *data, uint16_t length);
+
+void spi_stop(void);
+#ifdef __cplusplus
+}
+#endif
diff --git a/platforms/avr/drivers/ssd1306.c b/platforms/avr/drivers/ssd1306.c
new file mode 100644
index 0000000000..1a09a2bcb7
--- /dev/null
+++ b/platforms/avr/drivers/ssd1306.c
@@ -0,0 +1,319 @@
+#ifdef SSD1306OLED
+
+# include "ssd1306.h"
+# include "i2c.h"
+# include
+# include "print.h"
+# include "glcdfont.c"
+# ifdef PROTOCOL_LUFA
+# include "lufa.h"
+# endif
+# include "sendchar.h"
+# include "timer.h"
+
+struct CharacterMatrix display;
+
+// Set this to 1 to help diagnose early startup problems
+// when testing power-on with ble. Turn it off otherwise,
+// as the latency of printing most of the debug info messes
+// with the matrix scan, causing keys to drop.
+# define DEBUG_TO_SCREEN 0
+
+// static uint16_t last_battery_update;
+// static uint32_t vbat;
+//#define BatteryUpdateInterval 10000 /* milliseconds */
+# define ScreenOffInterval 300000 /* milliseconds */
+# if DEBUG_TO_SCREEN
+static uint8_t displaying;
+# endif
+static uint16_t last_flush;
+
+// Write command sequence.
+// Returns true on success.
+static inline bool _send_cmd1(uint8_t cmd) {
+ bool res = false;
+
+ if (i2c_start_write(SSD1306_ADDRESS)) {
+ xprintf("failed to start write to %d\n", SSD1306_ADDRESS);
+ goto done;
+ }
+
+ if (i2c_master_write(0x0 /* command byte follows */)) {
+ print("failed to write control byte\n");
+
+ goto done;
+ }
+
+ if (i2c_master_write(cmd)) {
+ xprintf("failed to write command %d\n", cmd);
+ goto done;
+ }
+ res = true;
+done:
+ i2c_master_stop();
+ return res;
+}
+
+// Write 2-byte command sequence.
+// Returns true on success
+static inline bool _send_cmd2(uint8_t cmd, uint8_t opr) {
+ if (!_send_cmd1(cmd)) {
+ return false;
+ }
+ return _send_cmd1(opr);
+}
+
+// Write 3-byte command sequence.
+// Returns true on success
+static inline bool _send_cmd3(uint8_t cmd, uint8_t opr1, uint8_t opr2) {
+ if (!_send_cmd1(cmd)) {
+ return false;
+ }
+ if (!_send_cmd1(opr1)) {
+ return false;
+ }
+ return _send_cmd1(opr2);
+}
+
+# define send_cmd1(c) \
+ if (!_send_cmd1(c)) { \
+ goto done; \
+ }
+# define send_cmd2(c, o) \
+ if (!_send_cmd2(c, o)) { \
+ goto done; \
+ }
+# define send_cmd3(c, o1, o2) \
+ if (!_send_cmd3(c, o1, o2)) { \
+ goto done; \
+ }
+
+static void clear_display(void) {
+ matrix_clear(&display);
+
+ // Clear all of the display bits (there can be random noise
+ // in the RAM on startup)
+ send_cmd3(PageAddr, 0, (DisplayHeight / 8) - 1);
+ send_cmd3(ColumnAddr, 0, DisplayWidth - 1);
+
+ if (i2c_start_write(SSD1306_ADDRESS)) {
+ goto done;
+ }
+ if (i2c_master_write(0x40)) {
+ // Data mode
+ goto done;
+ }
+ for (uint8_t row = 0; row < MatrixRows; ++row) {
+ for (uint8_t col = 0; col < DisplayWidth; ++col) {
+ i2c_master_write(0);
+ }
+ }
+
+ display.dirty = false;
+
+done:
+ i2c_master_stop();
+}
+
+# if DEBUG_TO_SCREEN
+# undef sendchar
+static int8_t capture_sendchar(uint8_t c) {
+ sendchar(c);
+ iota_gfx_write_char(c);
+
+ if (!displaying) {
+ iota_gfx_flush();
+ }
+ return 0;
+}
+# endif
+
+bool iota_gfx_init(void) {
+ bool success = false;
+
+ send_cmd1(DisplayOff);
+ send_cmd2(SetDisplayClockDiv, 0x80);
+ send_cmd2(SetMultiPlex, DisplayHeight - 1);
+
+ send_cmd2(SetDisplayOffset, 0);
+
+ send_cmd1(SetStartLine | 0x0);
+ send_cmd2(SetChargePump, 0x14 /* Enable */);
+ send_cmd2(SetMemoryMode, 0 /* horizontal addressing */);
+
+# ifdef OLED_ROTATE180
+ // the following Flip the display orientation 180 degrees
+ send_cmd1(SegRemap);
+ send_cmd1(ComScanInc);
+# endif
+# ifndef OLED_ROTATE180
+ // Flips the display orientation 0 degrees
+ send_cmd1(SegRemap | 0x1);
+ send_cmd1(ComScanDec);
+# endif
+
+ send_cmd2(SetComPins, 0x2);
+ send_cmd2(SetContrast, 0x8f);
+ send_cmd2(SetPreCharge, 0xf1);
+ send_cmd2(SetVComDetect, 0x40);
+ send_cmd1(DisplayAllOnResume);
+ send_cmd1(NormalDisplay);
+ send_cmd1(DeActivateScroll);
+ send_cmd1(DisplayOn);
+
+ send_cmd2(SetContrast, 0); // Dim
+
+ clear_display();
+
+ success = true;
+
+ iota_gfx_flush();
+
+# if DEBUG_TO_SCREEN
+ print_set_sendchar(capture_sendchar);
+# endif
+
+done:
+ return success;
+}
+
+bool iota_gfx_off(void) {
+ bool success = false;
+
+ send_cmd1(DisplayOff);
+ success = true;
+
+done:
+ return success;
+}
+
+bool iota_gfx_on(void) {
+ bool success = false;
+
+ send_cmd1(DisplayOn);
+ success = true;
+
+done:
+ return success;
+}
+
+void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c) {
+ *matrix->cursor = c;
+ ++matrix->cursor;
+
+ if (matrix->cursor - &matrix->display[0][0] == sizeof(matrix->display)) {
+ // We went off the end; scroll the display upwards by one line
+ memmove(&matrix->display[0], &matrix->display[1], MatrixCols * (MatrixRows - 1));
+ matrix->cursor = &matrix->display[MatrixRows - 1][0];
+ memset(matrix->cursor, ' ', MatrixCols);
+ }
+}
+
+void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c) {
+ matrix->dirty = true;
+
+ if (c == '\n') {
+ // Clear to end of line from the cursor and then move to the
+ // start of the next line
+ uint8_t cursor_col = (matrix->cursor - &matrix->display[0][0]) % MatrixCols;
+
+ while (cursor_col++ < MatrixCols) {
+ matrix_write_char_inner(matrix, ' ');
+ }
+ return;
+ }
+
+ matrix_write_char_inner(matrix, c);
+}
+
+void iota_gfx_write_char(uint8_t c) { matrix_write_char(&display, c); }
+
+void matrix_write(struct CharacterMatrix *matrix, const char *data) {
+ const char *end = data + strlen(data);
+ while (data < end) {
+ matrix_write_char(matrix, *data);
+ ++data;
+ }
+}
+
+void iota_gfx_write(const char *data) { matrix_write(&display, data); }
+
+void matrix_write_P(struct CharacterMatrix *matrix, const char *data) {
+ while (true) {
+ uint8_t c = pgm_read_byte(data);
+ if (c == 0) {
+ return;
+ }
+ matrix_write_char(matrix, c);
+ ++data;
+ }
+}
+
+void iota_gfx_write_P(const char *data) { matrix_write_P(&display, data); }
+
+void matrix_clear(struct CharacterMatrix *matrix) {
+ memset(matrix->display, ' ', sizeof(matrix->display));
+ matrix->cursor = &matrix->display[0][0];
+ matrix->dirty = true;
+}
+
+void iota_gfx_clear_screen(void) { matrix_clear(&display); }
+
+void matrix_render(struct CharacterMatrix *matrix) {
+ last_flush = timer_read();
+ iota_gfx_on();
+# if DEBUG_TO_SCREEN
+ ++displaying;
+# endif
+
+ // Move to the home position
+ send_cmd3(PageAddr, 0, MatrixRows - 1);
+ send_cmd3(ColumnAddr, 0, (MatrixCols * FontWidth) - 1);
+
+ if (i2c_start_write(SSD1306_ADDRESS)) {
+ goto done;
+ }
+ if (i2c_master_write(0x40)) {
+ // Data mode
+ goto done;
+ }
+
+ for (uint8_t row = 0; row < MatrixRows; ++row) {
+ for (uint8_t col = 0; col < MatrixCols; ++col) {
+ const uint8_t *glyph = font + (matrix->display[row][col] * (FontWidth - 1));
+
+ for (uint8_t glyphCol = 0; glyphCol < FontWidth - 1; ++glyphCol) {
+ uint8_t colBits = pgm_read_byte(glyph + glyphCol);
+ i2c_master_write(colBits);
+ }
+
+ // 1 column of space between chars (it's not included in the glyph)
+ i2c_master_write(0);
+ }
+ }
+
+ matrix->dirty = false;
+
+done:
+ i2c_master_stop();
+# if DEBUG_TO_SCREEN
+ --displaying;
+# endif
+}
+
+void iota_gfx_flush(void) { matrix_render(&display); }
+
+__attribute__((weak)) void iota_gfx_task_user(void) {}
+
+void iota_gfx_task(void) {
+ iota_gfx_task_user();
+
+ if (display.dirty) {
+ iota_gfx_flush();
+ }
+
+ if (timer_elapsed(last_flush) > ScreenOffInterval) {
+ iota_gfx_off();
+ }
+}
+#endif
diff --git a/platforms/avr/drivers/ssd1306.h b/platforms/avr/drivers/ssd1306.h
new file mode 100644
index 0000000000..6eecdcfaa4
--- /dev/null
+++ b/platforms/avr/drivers/ssd1306.h
@@ -0,0 +1,87 @@
+#pragma once
+
+#include
+#include
+#include "config.h"
+
+enum ssd1306_cmds {
+ DisplayOff = 0xAE,
+ DisplayOn = 0xAF,
+
+ SetContrast = 0x81,
+ DisplayAllOnResume = 0xA4,
+
+ DisplayAllOn = 0xA5,
+ NormalDisplay = 0xA6,
+ InvertDisplay = 0xA7,
+ SetDisplayOffset = 0xD3,
+ SetComPins = 0xda,
+ SetVComDetect = 0xdb,
+ SetDisplayClockDiv = 0xD5,
+ SetPreCharge = 0xd9,
+ SetMultiPlex = 0xa8,
+ SetLowColumn = 0x00,
+ SetHighColumn = 0x10,
+ SetStartLine = 0x40,
+
+ SetMemoryMode = 0x20,
+ ColumnAddr = 0x21,
+ PageAddr = 0x22,
+
+ ComScanInc = 0xc0,
+ ComScanDec = 0xc8,
+ SegRemap = 0xa0,
+ SetChargePump = 0x8d,
+ ExternalVcc = 0x01,
+ SwitchCapVcc = 0x02,
+
+ ActivateScroll = 0x2f,
+ DeActivateScroll = 0x2e,
+ SetVerticalScrollArea = 0xa3,
+ RightHorizontalScroll = 0x26,
+ LeftHorizontalScroll = 0x27,
+ VerticalAndRightHorizontalScroll = 0x29,
+ VerticalAndLeftHorizontalScroll = 0x2a,
+};
+
+// Controls the SSD1306 128x32 OLED display via i2c
+
+#ifndef SSD1306_ADDRESS
+# define SSD1306_ADDRESS 0x3C
+#endif
+
+#define DisplayHeight 32
+#define DisplayWidth 128
+
+#define FontHeight 8
+#define FontWidth 6
+
+#define MatrixRows (DisplayHeight / FontHeight)
+#define MatrixCols (DisplayWidth / FontWidth)
+
+struct CharacterMatrix {
+ uint8_t display[MatrixRows][MatrixCols];
+ uint8_t *cursor;
+ bool dirty;
+};
+
+extern struct CharacterMatrix display;
+
+bool iota_gfx_init(void);
+void iota_gfx_task(void);
+bool iota_gfx_off(void);
+bool iota_gfx_on(void);
+void iota_gfx_flush(void);
+void iota_gfx_write_char(uint8_t c);
+void iota_gfx_write(const char *data);
+void iota_gfx_write_P(const char *data);
+void iota_gfx_clear_screen(void);
+
+void iota_gfx_task_user(void);
+
+void matrix_clear(struct CharacterMatrix *matrix);
+void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c);
+void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c);
+void matrix_write(struct CharacterMatrix *matrix, const char *data);
+void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
+void matrix_render(struct CharacterMatrix *matrix);
diff --git a/platforms/avr/drivers/uart.c b/platforms/avr/drivers/uart.c
new file mode 100644
index 0000000000..c6abcb6fe0
--- /dev/null
+++ b/platforms/avr/drivers/uart.c
@@ -0,0 +1,170 @@
+/* UART Example for Teensy USB Development Board
+ * http://www.pjrc.com/teensy/
+ * Copyright (c) 2009 PJRC.COM, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+// Version 1.0: Initial Release
+// Version 1.1: Add support for Teensy 2.0, minor optimizations
+
+#include
+#include
+
+#include "uart.h"
+
+#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
+# define UDRn UDR1
+# define UBRRnL UBRR1L
+# define UCSRnA UCSR1A
+# define UCSRnB UCSR1B
+# define UCSRnC UCSR1C
+# define U2Xn U2X1
+# define RXENn RXEN1
+# define TXENn TXEN1
+# define RXCIEn RXCIE1
+# define UCSZn1 UCSZ11
+# define UCSZn0 UCSZ10
+# define UDRIEn UDRIE1
+# define USARTn_UDRE_vect USART1_UDRE_vect
+# define USARTn_RX_vect USART1_RX_vect
+#elif defined(__AVR_ATmega32A__)
+# define UDRn UDR
+# define UBRRnL UBRRL
+# define UCSRnA UCSRA
+# define UCSRnB UCSRB
+# define UCSRnC UCSRC
+# define U2Xn U2X
+# define RXENn RXEN
+# define TXENn TXEN
+# define RXCIEn RXCIE
+# define UCSZn1 UCSZ1
+# define UCSZn0 UCSZ0
+# define UDRIEn UDRIE
+# define USARTn_UDRE_vect USART_UDRE_vect
+# define USARTn_RX_vect USART_RX_vect
+#elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
+# define UDRn UDR0
+# define UBRRnL UBRR0L
+# define UCSRnA UCSR0A
+# define UCSRnB UCSR0B
+# define UCSRnC UCSR0C
+# define U2Xn U2X0
+# define RXENn RXEN0
+# define TXENn TXEN0
+# define RXCIEn RXCIE0
+# define UCSZn1 UCSZ01
+# define UCSZn0 UCSZ00
+# define UDRIEn UDRIE0
+# define USARTn_UDRE_vect USART_UDRE_vect
+# define USARTn_RX_vect USART_RX_vect
+#endif
+
+// These buffers may be any size from 2 to 256 bytes.
+#define RX_BUFFER_SIZE 64
+#define TX_BUFFER_SIZE 256
+
+static volatile uint8_t tx_buffer[TX_BUFFER_SIZE];
+static volatile uint8_t tx_buffer_head;
+static volatile uint8_t tx_buffer_tail;
+static volatile uint8_t rx_buffer[RX_BUFFER_SIZE];
+static volatile uint8_t rx_buffer_head;
+static volatile uint8_t rx_buffer_tail;
+
+// Initialize the UART
+void uart_init(uint32_t baud) {
+ cli();
+ UBRRnL = (F_CPU / 4 / baud - 1) / 2;
+ UCSRnA = (1 << U2Xn);
+ UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
+ UCSRnC = (1 << UCSZn1) | (1 << UCSZn0);
+ tx_buffer_head = tx_buffer_tail = 0;
+ rx_buffer_head = rx_buffer_tail = 0;
+ sei();
+}
+
+// Transmit a byte
+void uart_putchar(uint8_t c) {
+ uint8_t i;
+
+ i = tx_buffer_head + 1;
+ if (i >= TX_BUFFER_SIZE) i = 0;
+ // return immediately to avoid deadlock when interrupt is disabled(called from ISR)
+ if (tx_buffer_tail == i && (SREG & (1 << SREG_I)) == 0) return;
+ while (tx_buffer_tail == i)
+ ; // wait until space in buffer
+ // cli();
+ tx_buffer[i] = c;
+ tx_buffer_head = i;
+ UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn) | (1 << UDRIEn);
+ // sei();
+}
+
+// Receive a byte
+uint8_t uart_getchar(void) {
+ uint8_t c, i;
+
+ while (rx_buffer_head == rx_buffer_tail)
+ ; // wait for character
+ i = rx_buffer_tail + 1;
+ if (i >= RX_BUFFER_SIZE) i = 0;
+ c = rx_buffer[i];
+ rx_buffer_tail = i;
+ return c;
+}
+
+// Return whether the number of bytes waiting in the receive buffer is nonzero.
+// Call this before uart_getchar() to check if it will need
+// to wait for a byte to arrive.
+bool uart_available(void) {
+ uint8_t head, tail;
+
+ head = rx_buffer_head;
+ tail = rx_buffer_tail;
+ if (head >= tail) return (head - tail) > 0;
+ return (RX_BUFFER_SIZE + head - tail) > 0;
+}
+
+// Transmit Interrupt
+ISR(USARTn_UDRE_vect) {
+ uint8_t i;
+
+ if (tx_buffer_head == tx_buffer_tail) {
+ // buffer is empty, disable transmit interrupt
+ UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
+ } else {
+ i = tx_buffer_tail + 1;
+ if (i >= TX_BUFFER_SIZE) i = 0;
+ UDRn = tx_buffer[i];
+ tx_buffer_tail = i;
+ }
+}
+
+// Receive Interrupt
+ISR(USARTn_RX_vect) {
+ uint8_t c, i;
+
+ c = UDRn;
+ i = rx_buffer_head + 1;
+ if (i >= RX_BUFFER_SIZE) i = 0;
+ if (i != rx_buffer_tail) {
+ rx_buffer[i] = c;
+ rx_buffer_head = i;
+ }
+}
diff --git a/platforms/avr/drivers/uart.h b/platforms/avr/drivers/uart.h
new file mode 100644
index 0000000000..602eb3d8b0
--- /dev/null
+++ b/platforms/avr/drivers/uart.h
@@ -0,0 +1,35 @@
+/* UART Example for Teensy USB Development Board
+ * http://www.pjrc.com/teensy/
+ * Copyright (c) 2009 PJRC.COM, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include
+#include
+
+void uart_init(uint32_t baud);
+
+void uart_putchar(uint8_t c);
+
+uint8_t uart_getchar(void);
+
+bool uart_available(void);
diff --git a/platforms/avr/drivers/ws2812.c b/platforms/avr/drivers/ws2812.c
new file mode 100644
index 0000000000..77c492cd4c
--- /dev/null
+++ b/platforms/avr/drivers/ws2812.c
@@ -0,0 +1,176 @@
+/*
+ * light weight WS2812 lib V2.0b
+ *
+ * Controls WS2811/WS2812/WS2812B RGB-LEDs
+ * Author: Tim (cpldcpu@gmail.com)
+ *
+ * Jan 18th, 2014 v2.0b Initial Version
+ * Nov 29th, 2015 v2.3 Added SK6812RGBW support
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#include "ws2812.h"
+#include
+#include
+#include
+
+#define pinmask(pin) (_BV((pin)&0xF))
+
+/*
+ * Forward declare internal functions
+ *
+ * The functions take a byte-array and send to the data output as WS2812 bitstream.
+ * The length is the number of bytes to send - three per LED.
+ */
+
+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) {
+ DDRx_ADDRESS(RGB_DI_PIN) |= pinmask(RGB_DI_PIN);
+
+ uint8_t masklo = ~(pinmask(RGB_DI_PIN)) & PORTx_ADDRESS(RGB_DI_PIN);
+ uint8_t maskhi = pinmask(RGB_DI_PIN) | PORTx_ADDRESS(RGB_DI_PIN);
+
+ ws2812_sendarray_mask((uint8_t *)ledarray, number_of_leds * sizeof(LED_TYPE), masklo, maskhi);
+
+ _delay_us(WS2812_TRST_US);
+}
+
+/*
+ This routine writes an array of bytes with RGB values to the Dataout pin
+ using the fast 800kHz clockless WS2811/2812 protocol.
+*/
+
+// Timing in ns
+#define w_zeropulse 350
+#define w_onepulse 900
+#define w_totalperiod 1250
+
+// Fixed cycles used by the inner loop
+#define w_fixedlow 2
+#define w_fixedhigh 4
+#define w_fixedtotal 8
+
+// Insert NOPs to match the timing, if possible
+#define w_zerocycles (((F_CPU / 1000) * w_zeropulse) / 1000000)
+#define w_onecycles (((F_CPU / 1000) * w_onepulse + 500000) / 1000000)
+#define w_totalcycles (((F_CPU / 1000) * w_totalperiod + 500000) / 1000000)
+
+// w1_nops - nops between rising edge and falling edge - low
+#if w_zerocycles >= w_fixedlow
+# define w1_nops (w_zerocycles - w_fixedlow)
+#else
+# define w1_nops 0
+#endif
+
+// w2_nops - nops between fe low and fe high
+#if w_onecycles >= (w_fixedhigh + w1_nops)
+# define w2_nops (w_onecycles - w_fixedhigh - w1_nops)
+#else
+# define w2_nops 0
+#endif
+
+// w3_nops - nops to complete loop
+#if w_totalcycles >= (w_fixedtotal + w1_nops + w2_nops)
+# define w3_nops (w_totalcycles - w_fixedtotal - w1_nops - w2_nops)
+#else
+# define w3_nops 0
+#endif
+
+// The only critical timing parameter is the minimum pulse length of the "0"
+// Warn or throw error if this timing can not be met with current F_CPU settings.
+#define w_lowtime ((w1_nops + w_fixedlow) * 1000000) / (F_CPU / 1000)
+#if w_lowtime > 550
+# error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?"
+#elif w_lowtime > 450
+# warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)."
+# warning "Please consider a higher clockspeed, if possible"
+#endif
+
+#define w_nop1 "nop \n\t"
+#define w_nop2 "rjmp .+0 \n\t"
+#define w_nop4 w_nop2 w_nop2
+#define w_nop8 w_nop4 w_nop4
+#define w_nop16 w_nop8 w_nop8
+
+static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi) {
+ uint8_t curbyte, ctr, sreg_prev;
+
+ sreg_prev = SREG;
+ cli();
+
+ while (datlen--) {
+ curbyte = (*data++);
+
+ asm volatile(" ldi %0,8 \n\t"
+ "loop%=: \n\t"
+ " out %2,%3 \n\t" // '1' [01] '0' [01] - re
+#if (w1_nops & 1)
+ w_nop1
+#endif
+#if (w1_nops & 2)
+ w_nop2
+#endif
+#if (w1_nops & 4)
+ w_nop4
+#endif
+#if (w1_nops & 8)
+ w_nop8
+#endif
+#if (w1_nops & 16)
+ w_nop16
+#endif
+ " sbrs %1,7 \n\t" // '1' [03] '0' [02]
+ " out %2,%4 \n\t" // '1' [--] '0' [03] - fe-low
+ " lsl %1 \n\t" // '1' [04] '0' [04]
+#if (w2_nops & 1)
+ w_nop1
+#endif
+#if (w2_nops & 2)
+ w_nop2
+#endif
+#if (w2_nops & 4)
+ w_nop4
+#endif
+#if (w2_nops & 8)
+ w_nop8
+#endif
+#if (w2_nops & 16)
+ w_nop16
+#endif
+ " out %2,%4 \n\t" // '1' [+1] '0' [+1] - fe-high
+#if (w3_nops & 1)
+ w_nop1
+#endif
+#if (w3_nops & 2)
+ w_nop2
+#endif
+#if (w3_nops & 4)
+ w_nop4
+#endif
+#if (w3_nops & 8)
+ w_nop8
+#endif
+#if (w3_nops & 16)
+ w_nop16
+#endif
+
+ " dec %0 \n\t" // '1' [+2] '0' [+2]
+ " brne loop%=\n\t" // '1' [+3] '0' [+4]
+ : "=&d"(ctr)
+ : "r"(curbyte), "I"(_SFR_IO_ADDR(PORTx_ADDRESS(RGB_DI_PIN))), "r"(maskhi), "r"(masklo));
+ }
+
+ SREG = sreg_prev;
+}
diff --git a/platforms/avr/drivers/ws2812_i2c.c b/platforms/avr/drivers/ws2812_i2c.c
new file mode 100644
index 0000000000..1c332e24b6
--- /dev/null
+++ b/platforms/avr/drivers/ws2812_i2c.c
@@ -0,0 +1,27 @@
+#include "ws2812.h"
+#include "i2c_master.h"
+
+#ifdef RGBW
+# error "RGBW not supported"
+#endif
+
+#ifndef WS2812_ADDRESS
+# define WS2812_ADDRESS 0xb0
+#endif
+
+#ifndef WS2812_TIMEOUT
+# define WS2812_TIMEOUT 100
+#endif
+
+void ws2812_init(void) { i2c_init(); }
+
+// Setleds for standard RGB
+void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
+ static bool s_init = false;
+ if (!s_init) {
+ ws2812_init();
+ s_init = true;
+ }
+
+ i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT);
+}
diff --git a/platforms/chibios/drivers/analog.c b/platforms/chibios/drivers/analog.c
new file mode 100644
index 0000000000..8c476fcac2
--- /dev/null
+++ b/platforms/chibios/drivers/analog.c
@@ -0,0 +1,321 @@
+/* Copyright 2019 Drew Mills
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "quantum.h"
+#include "analog.h"
+#include
+#include
+
+#if !HAL_USE_ADC
+# error "You need to set HAL_USE_ADC to TRUE in your halconf.h to use the ADC."
+#endif
+
+#if !STM32_ADC_USE_ADC1 && !STM32_ADC_USE_ADC2 && !STM32_ADC_USE_ADC3 && !STM32_ADC_USE_ADC4
+# error "You need to set one of the 'STM32_ADC_USE_ADCx' settings to TRUE in your mcuconf.h to use the ADC."
+#endif
+
+#if STM32_ADC_DUAL_MODE
+# error "STM32 ADC Dual Mode is not supported at this time."
+#endif
+
+#if STM32_ADCV3_OVERSAMPLING
+# error "STM32 ADCV3 Oversampling is not supported at this time."
+#endif
+
+// Otherwise assume V3
+#if defined(STM32F0XX) || defined(STM32L0XX)
+# define USE_ADCV1
+#elif defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX)
+# define USE_ADCV2
+#endif
+
+// BODGE to make v2 look like v1,3 and 4
+#ifdef USE_ADCV2
+# if !defined(ADC_SMPR_SMP_1P5) && defined(ADC_SAMPLE_3)
+# define ADC_SMPR_SMP_1P5 ADC_SAMPLE_3
+# define ADC_SMPR_SMP_7P5 ADC_SAMPLE_15
+# define ADC_SMPR_SMP_13P5 ADC_SAMPLE_28
+# define ADC_SMPR_SMP_28P5 ADC_SAMPLE_56
+# define ADC_SMPR_SMP_41P5 ADC_SAMPLE_84
+# define ADC_SMPR_SMP_55P5 ADC_SAMPLE_112
+# define ADC_SMPR_SMP_71P5 ADC_SAMPLE_144
+# define ADC_SMPR_SMP_239P5 ADC_SAMPLE_480
+# endif
+
+# if !defined(ADC_SMPR_SMP_1P5) && defined(ADC_SAMPLE_1P5)
+# define ADC_SMPR_SMP_1P5 ADC_SAMPLE_1P5
+# define ADC_SMPR_SMP_7P5 ADC_SAMPLE_7P5
+# define ADC_SMPR_SMP_13P5 ADC_SAMPLE_13P5
+# define ADC_SMPR_SMP_28P5 ADC_SAMPLE_28P5
+# define ADC_SMPR_SMP_41P5 ADC_SAMPLE_41P5
+# define ADC_SMPR_SMP_55P5 ADC_SAMPLE_55P5
+# define ADC_SMPR_SMP_71P5 ADC_SAMPLE_71P5
+# define ADC_SMPR_SMP_239P5 ADC_SAMPLE_239P5
+# endif
+
+// we still sample at 12bit, but scale down to the requested bit range
+# define ADC_CFGR1_RES_12BIT 12
+# define ADC_CFGR1_RES_10BIT 10
+# define ADC_CFGR1_RES_8BIT 8
+# define ADC_CFGR1_RES_6BIT 6
+#endif
+
+/* User configurable ADC options */
+#ifndef ADC_COUNT
+# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F4XX)
+# define ADC_COUNT 1
+# elif defined(STM32F3XX)
+# define ADC_COUNT 4
+# else
+# error "ADC_COUNT has not been set for this ARM microcontroller."
+# endif
+#endif
+
+#ifndef ADC_NUM_CHANNELS
+# define ADC_NUM_CHANNELS 1
+#elif ADC_NUM_CHANNELS != 1
+# error "The ARM ADC implementation currently only supports reading one channel at a time."
+#endif
+
+#ifndef ADC_BUFFER_DEPTH
+# define ADC_BUFFER_DEPTH 1
+#endif
+
+// For more sampling rate options, look at hal_adc_lld.h in ChibiOS
+#ifndef ADC_SAMPLING_RATE
+# define ADC_SAMPLING_RATE ADC_SMPR_SMP_1P5
+#endif
+
+// Options are 12, 10, 8, and 6 bit.
+#ifndef ADC_RESOLUTION
+# ifdef ADC_CFGR_RES_10BITS // ADCv3, ADCv4
+# define ADC_RESOLUTION ADC_CFGR_RES_10BITS
+# else // ADCv1, ADCv5, or the bodge for ADCv2 above
+# define ADC_RESOLUTION ADC_CFGR1_RES_10BIT
+# endif
+#endif
+
+static ADCConfig adcCfg = {};
+static adcsample_t sampleBuffer[ADC_NUM_CHANNELS * ADC_BUFFER_DEPTH];
+
+// Initialize to max number of ADCs, set to empty object to initialize all to false.
+static bool adcInitialized[ADC_COUNT] = {};
+
+// TODO: add back TR handling???
+static ADCConversionGroup adcConversionGroup = {
+ .circular = FALSE,
+ .num_channels = (uint16_t)(ADC_NUM_CHANNELS),
+#if defined(USE_ADCV1)
+ .cfgr1 = ADC_CFGR1_CONT | ADC_RESOLUTION,
+ .smpr = ADC_SAMPLING_RATE,
+#elif defined(USE_ADCV2)
+# if !defined(STM32F1XX)
+ .cr2 = ADC_CR2_SWSTART, // F103 seem very unhappy with, F401 seems very unhappy without...
+# endif
+ .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),
+ .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),
+#else
+ .cfgr = ADC_CFGR_CONT | ADC_RESOLUTION,
+ .smpr = {ADC_SMPR1_SMP_AN0(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN1(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN2(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN3(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN4(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN5(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN6(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN7(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN8(ADC_SAMPLING_RATE) | ADC_SMPR1_SMP_AN9(ADC_SAMPLING_RATE), ADC_SMPR2_SMP_AN10(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN11(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN12(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN13(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN14(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN15(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN16(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN17(ADC_SAMPLING_RATE) | ADC_SMPR2_SMP_AN18(ADC_SAMPLING_RATE)},
+#endif
+};
+
+// clang-format off
+__attribute__((weak)) adc_mux pinToMux(pin_t pin) {
+ switch (pin) {
+#if defined(STM32F0XX)
+ case A0: return TO_MUX( ADC_CHSELR_CHSEL0, 0 );
+ case A1: return TO_MUX( ADC_CHSELR_CHSEL1, 0 );
+ case A2: return TO_MUX( ADC_CHSELR_CHSEL2, 0 );
+ case A3: return TO_MUX( ADC_CHSELR_CHSEL3, 0 );
+ case A4: return TO_MUX( ADC_CHSELR_CHSEL4, 0 );
+ case A5: return TO_MUX( ADC_CHSELR_CHSEL5, 0 );
+ case A6: return TO_MUX( ADC_CHSELR_CHSEL6, 0 );
+ case A7: return TO_MUX( ADC_CHSELR_CHSEL7, 0 );
+ case B0: return TO_MUX( ADC_CHSELR_CHSEL8, 0 );
+ case B1: return TO_MUX( ADC_CHSELR_CHSEL9, 0 );
+ case C0: return TO_MUX( ADC_CHSELR_CHSEL10, 0 );
+ case C1: return TO_MUX( ADC_CHSELR_CHSEL11, 0 );
+ case C2: return TO_MUX( ADC_CHSELR_CHSEL12, 0 );
+ case C3: return TO_MUX( ADC_CHSELR_CHSEL13, 0 );
+ case C4: return TO_MUX( ADC_CHSELR_CHSEL14, 0 );
+ case C5: return TO_MUX( ADC_CHSELR_CHSEL15, 0 );
+#elif defined(STM32F3XX)
+ case A0: return TO_MUX( ADC_CHANNEL_IN1, 0 );
+ case A1: return TO_MUX( ADC_CHANNEL_IN2, 0 );
+ case A2: return TO_MUX( ADC_CHANNEL_IN3, 0 );
+ case A3: return TO_MUX( ADC_CHANNEL_IN4, 0 );
+ case A4: return TO_MUX( ADC_CHANNEL_IN1, 1 );
+ case A5: return TO_MUX( ADC_CHANNEL_IN2, 1 );
+ case A6: return TO_MUX( ADC_CHANNEL_IN3, 1 );
+ case A7: return TO_MUX( ADC_CHANNEL_IN4, 1 );
+ case B0: return TO_MUX( ADC_CHANNEL_IN12, 2 );
+ case B1: return TO_MUX( ADC_CHANNEL_IN1, 2 );
+ case B2: return TO_MUX( ADC_CHANNEL_IN12, 1 );
+ case B12: return TO_MUX( ADC_CHANNEL_IN3, 3 );
+ case B13: return TO_MUX( ADC_CHANNEL_IN5, 2 );
+ case B14: return TO_MUX( ADC_CHANNEL_IN4, 3 );
+ case B15: return TO_MUX( ADC_CHANNEL_IN5, 3 );
+ case C0: return TO_MUX( ADC_CHANNEL_IN6, 0 ); // Can also be ADC2
+ case C1: return TO_MUX( ADC_CHANNEL_IN7, 0 ); // Can also be ADC2
+ case C2: return TO_MUX( ADC_CHANNEL_IN8, 0 ); // Can also be ADC2
+ case C3: return TO_MUX( ADC_CHANNEL_IN9, 0 ); // Can also be ADC2
+ case C4: return TO_MUX( ADC_CHANNEL_IN5, 1 );
+ case C5: return TO_MUX( ADC_CHANNEL_IN11, 1 );
+ case D8: return TO_MUX( ADC_CHANNEL_IN12, 3 );
+ case D9: return TO_MUX( ADC_CHANNEL_IN13, 3 );
+ case D10: return TO_MUX( ADC_CHANNEL_IN7, 2 ); // Can also be ADC4
+ case D11: return TO_MUX( ADC_CHANNEL_IN8, 2 ); // Can also be ADC4
+ case D12: return TO_MUX( ADC_CHANNEL_IN9, 2 ); // Can also be ADC4
+ case D13: return TO_MUX( ADC_CHANNEL_IN10, 2 ); // Can also be ADC4
+ case D14: return TO_MUX( ADC_CHANNEL_IN11, 2 ); // Can also be ADC4
+ case E7: return TO_MUX( ADC_CHANNEL_IN13, 2 );
+ case E8: return TO_MUX( ADC_CHANNEL_IN6, 2 ); // Can also be ADC4
+ case E9: return TO_MUX( ADC_CHANNEL_IN2, 2 );
+ case E10: return TO_MUX( ADC_CHANNEL_IN14, 2 );
+ case E11: return TO_MUX( ADC_CHANNEL_IN15, 2 );
+ case E12: return TO_MUX( ADC_CHANNEL_IN16, 2 );
+ case E13: return TO_MUX( ADC_CHANNEL_IN3, 2 );
+ case E14: return TO_MUX( ADC_CHANNEL_IN1, 3 );
+ case E15: return TO_MUX( ADC_CHANNEL_IN2, 3 );
+ case F2: return TO_MUX( ADC_CHANNEL_IN10, 0 ); // Can also be ADC2
+ case F4: return TO_MUX( ADC_CHANNEL_IN5, 0 );
+#elif defined(STM32F4XX)
+ case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
+ case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
+ case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
+ case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 );
+ case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 );
+ case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 );
+ case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 );
+ case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 );
+ case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 );
+ case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 );
+ case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 );
+ case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 );
+ case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 );
+ case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 );
+ case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 );
+ case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 );
+# if STM32_ADC_USE_ADC3
+ case F3: return TO_MUX( ADC_CHANNEL_IN9, 2 );
+ case F4: return TO_MUX( ADC_CHANNEL_IN14, 2 );
+ case F5: return TO_MUX( ADC_CHANNEL_IN15, 2 );
+ case F6: return TO_MUX( ADC_CHANNEL_IN4, 2 );
+ case F7: return TO_MUX( ADC_CHANNEL_IN5, 2 );
+ case F8: return TO_MUX( ADC_CHANNEL_IN6, 2 );
+ case F9: return TO_MUX( ADC_CHANNEL_IN7, 2 );
+ case F10: return TO_MUX( ADC_CHANNEL_IN8, 2 );
+# endif
+#elif defined(STM32F1XX)
+ case A0: return TO_MUX( ADC_CHANNEL_IN0, 0 );
+ case A1: return TO_MUX( ADC_CHANNEL_IN1, 0 );
+ case A2: return TO_MUX( ADC_CHANNEL_IN2, 0 );
+ case A3: return TO_MUX( ADC_CHANNEL_IN3, 0 );
+ case A4: return TO_MUX( ADC_CHANNEL_IN4, 0 );
+ case A5: return TO_MUX( ADC_CHANNEL_IN5, 0 );
+ case A6: return TO_MUX( ADC_CHANNEL_IN6, 0 );
+ case A7: return TO_MUX( ADC_CHANNEL_IN7, 0 );
+ case B0: return TO_MUX( ADC_CHANNEL_IN8, 0 );
+ case B1: return TO_MUX( ADC_CHANNEL_IN9, 0 );
+ case C0: return TO_MUX( ADC_CHANNEL_IN10, 0 );
+ case C1: return TO_MUX( ADC_CHANNEL_IN11, 0 );
+ case C2: return TO_MUX( ADC_CHANNEL_IN12, 0 );
+ case C3: return TO_MUX( ADC_CHANNEL_IN13, 0 );
+ case C4: return TO_MUX( ADC_CHANNEL_IN14, 0 );
+ case C5: return TO_MUX( ADC_CHANNEL_IN15, 0 );
+ // STM32F103x[C-G] in 144-pin packages also have analog inputs on F6...F10, but they are on ADC3, and the
+ // ChibiOS ADC driver for STM32F1xx currently supports only ADC1, therefore these pins are not usable.
+#endif
+ }
+
+ // return an adc that would never be used so intToADCDriver will bail out
+ return TO_MUX(0, 0xFF);
+}
+// clang-format on
+
+static inline ADCDriver* intToADCDriver(uint8_t adcInt) {
+ switch (adcInt) {
+#if STM32_ADC_USE_ADC1
+ case 0:
+ return &ADCD1;
+#endif
+#if STM32_ADC_USE_ADC2
+ case 1:
+ return &ADCD2;
+#endif
+#if STM32_ADC_USE_ADC3
+ case 2:
+ return &ADCD3;
+#endif
+#if STM32_ADC_USE_ADC4
+ case 3:
+ return &ADCD4;
+#endif
+ }
+
+ return NULL;
+}
+
+static inline void manageAdcInitializationDriver(uint8_t adc, ADCDriver* adcDriver) {
+ if (!adcInitialized[adc]) {
+ adcStart(adcDriver, &adcCfg);
+ adcInitialized[adc] = true;
+ }
+}
+
+int16_t analogReadPin(pin_t pin) {
+ palSetLineMode(pin, PAL_MODE_INPUT_ANALOG);
+
+ return adc_read(pinToMux(pin));
+}
+
+int16_t analogReadPinAdc(pin_t pin, uint8_t adc) {
+ palSetLineMode(pin, PAL_MODE_INPUT_ANALOG);
+
+ adc_mux target = pinToMux(pin);
+ target.adc = adc;
+ return adc_read(target);
+}
+
+int16_t adc_read(adc_mux mux) {
+#if defined(USE_ADCV1)
+ // TODO: fix previous assumption of only 1 input...
+ adcConversionGroup.chselr = 1 << mux.input; /*no macro to convert N to ADC_CHSELR_CHSEL1*/
+#elif defined(USE_ADCV2)
+ adcConversionGroup.sqr3 = ADC_SQR3_SQ1_N(mux.input);
+#else
+ adcConversionGroup.sqr[0] = ADC_SQR1_SQ1_N(mux.input);
+#endif
+
+ ADCDriver* targetDriver = intToADCDriver(mux.adc);
+ if (!targetDriver) {
+ return 0;
+ }
+
+ manageAdcInitializationDriver(mux.adc, targetDriver);
+ if (adcConvert(targetDriver, &adcConversionGroup, &sampleBuffer[0], ADC_BUFFER_DEPTH) != MSG_OK) {
+ return 0;
+ }
+
+#ifdef USE_ADCV2
+ // fake 12-bit -> N-bit scale
+ return (*sampleBuffer) >> (12 - ADC_RESOLUTION);
+#else
+ // already handled as part of adcConvert
+ return *sampleBuffer;
+#endif
+}
diff --git a/platforms/chibios/drivers/analog.h b/platforms/chibios/drivers/analog.h
new file mode 100644
index 0000000000..e61c394265
--- /dev/null
+++ b/platforms/chibios/drivers/analog.h
@@ -0,0 +1,41 @@
+/* Copyright 2019 Drew Mills
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include "quantum.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ uint16_t input;
+ uint8_t adc;
+} adc_mux;
+#define TO_MUX(i, a) \
+ (adc_mux) { i, a }
+
+int16_t analogReadPin(pin_t pin);
+int16_t analogReadPinAdc(pin_t pin, uint8_t adc);
+adc_mux pinToMux(pin_t pin);
+
+int16_t adc_read(adc_mux mux);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c b/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c
new file mode 100644
index 0000000000..ed26cc7145
--- /dev/null
+++ b/platforms/chibios/drivers/eeprom/eeprom_stm32_L0_L1.c
@@ -0,0 +1,96 @@
+/* Copyright 2020 Nick Brassel (tzarc)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see