diff options
Diffstat (limited to 'keyboards/matrix/m20add/m20add.c')
| -rw-r--r-- | keyboards/matrix/m20add/m20add.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/keyboards/matrix/m20add/m20add.c b/keyboards/matrix/m20add/m20add.c new file mode 100644 index 000000000..b38dad27c --- /dev/null +++ b/keyboards/matrix/m20add/m20add.c | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | /** | ||
| 2 | * m20add.c | ||
| 3 | */ | ||
| 4 | |||
| 5 | #include "m20add.h" | ||
| 6 | #include "tca6424.h" | ||
| 7 | #include "rgb_ring.h" | ||
| 8 | #include "i2c_master.h" | ||
| 9 | |||
| 10 | void set_pin(uint16_t pin) | ||
| 11 | { | ||
| 12 | uint8_t data = tca6424_read_port(GET_PORT(pin)); | ||
| 13 | data |= ( 1 << GET_PIN(pin)); | ||
| 14 | tca6424_write_port(GET_PORT(pin), data); | ||
| 15 | } | ||
| 16 | |||
| 17 | void clear_pin(uint16_t pin) | ||
| 18 | { | ||
| 19 | uint8_t data = tca6424_read_port(GET_PORT(pin)); | ||
| 20 | data &= ~( 1 << GET_PIN(pin)); | ||
| 21 | tca6424_write_port(GET_PORT(pin), data); | ||
| 22 | } | ||
| 23 | |||
| 24 | uint8_t read_pin(uint16_t pin) | ||
| 25 | { | ||
| 26 | uint8_t data = tca6424_read_port(GET_PORT(pin)); | ||
| 27 | return (data & (1<<GET_PIN(pin))) ? 1 : 0; | ||
| 28 | } | ||
| 29 | |||
| 30 | void matrix_init_kb(void) { | ||
| 31 | #ifdef RGBLIGHT_ENABLE | ||
| 32 | rgb_ring_init(); | ||
| 33 | #endif | ||
| 34 | matrix_init_user(); | ||
| 35 | } | ||
| 36 | |||
| 37 | void matrix_scan_kb(void) { | ||
| 38 | #ifdef RGBLIGHT_ENABLE | ||
| 39 | rgb_ring_task(); | ||
| 40 | #endif | ||
| 41 | matrix_scan_user(); | ||
| 42 | } | ||
| 43 | |||
| 44 | static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3); | ||
| 45 | static uint16_t scroll_lock_pin = DEF_PIN(TCA6424_PORT0, 1); | ||
| 46 | |||
| 47 | bool led_update_kb(led_t led_state) { | ||
| 48 | bool res = led_update_user(led_state); | ||
| 49 | if (res) { | ||
| 50 | led_state.caps_lock ? set_pin(caps_lock_pin) : clear_pin(caps_lock_pin); | ||
| 51 | led_state.scroll_lock ? set_pin(scroll_lock_pin) : clear_pin(scroll_lock_pin); | ||
| 52 | } | ||
| 53 | return res; | ||
| 54 | } | ||
| 55 | |||
| 56 | // override the default implementation to avoid re-initialization | ||
| 57 | void i2c_init(void) | ||
| 58 | { | ||
| 59 | static bool initialized = false; | ||
| 60 | if (initialized) { | ||
| 61 | return; | ||
| 62 | } else { | ||
| 63 | initialized = true; | ||
| 64 | } | ||
| 65 | |||
| 66 | // Try releasing special pins for a short time | ||
| 67 | palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT); | ||
| 68 | palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT); | ||
| 69 | |||
| 70 | chThdSleepMilliseconds(10); | ||
| 71 | palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | ||
| 72 | palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | ||
| 73 | } | ||
| 74 | |||
| 75 | #define REBOOT_MAGIC 0x41544B42 | ||
| 76 | void shutdown_user(void) | ||
| 77 | { | ||
| 78 | // set the magic number for resetting to the bootloader | ||
| 79 | *(uint32_t *)(&(RTCD1.rtc->BKP0R)) = REBOOT_MAGIC; | ||
| 80 | } | ||
