2022-02-06 12:00:50 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "quantum.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "i2c_master.h"
|
2023-12-19 09:03:31 -08:00
|
|
|
#include "hardware/macros.h"
|
2022-02-06 12:00:50 -08:00
|
|
|
|
|
|
|
// I2C aliases and register addresses (see "mcp23018.md")
|
|
|
|
#define I2C_ADDR 0b0100000
|
|
|
|
#define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE )
|
|
|
|
#define I2C_ADDR_READ ( (I2C_ADDR<<1) | I2C_READ )
|
|
|
|
#define IODIRA 0x00 // i/o direction register
|
|
|
|
#define IODIRB 0x01
|
|
|
|
#define GPPUA 0x0C // GPIO pull-up resistor register
|
|
|
|
#define GPPUB 0x0D
|
|
|
|
#define GPIOA 0x12 // general purpose i/o port register (write modifies OLAT)
|
|
|
|
#define GPIOB 0x13
|
|
|
|
#define OLATA 0x14 // output latch register
|
|
|
|
#define OLATB 0x15
|
|
|
|
|
|
|
|
extern i2c_status_t mcp23018_status;
|
|
|
|
#define ERGODOX_EZ_I2C_TIMEOUT 100
|
|
|
|
|
|
|
|
void init_ergodox(void);
|
|
|
|
void ergodox_blink_all_leds(void);
|
|
|
|
uint8_t init_mcp23018(void);
|
|
|
|
|
|
|
|
#ifndef LED_BRIGHTNESS_LO
|
|
|
|
#define LED_BRIGHTNESS_LO 15
|
|
|
|
#endif
|
|
|
|
#ifndef LED_BRIGHTNESS_HI
|
|
|
|
#define LED_BRIGHTNESS_HI 255
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
inline void ergodox_board_led_on(void) { DDRD |= (1<<6); PORTD |= (1<<6); }
|
|
|
|
inline void ergodox_right_led_1_on(void) { DDRB |= (1<<5); PORTB |= (1<<5); }
|
|
|
|
inline void ergodox_right_led_2_on(void) { DDRB |= (1<<6); PORTB |= (1<<6); }
|
|
|
|
inline void ergodox_right_led_3_on(void) { DDRB |= (1<<7); PORTB |= (1<<7); }
|
|
|
|
inline void ergodox_right_led_on(uint8_t led) { DDRB |= (1<<(led+4)); PORTB |= (1<<(led+4)); }
|
|
|
|
|
|
|
|
inline void ergodox_board_led_off(void) { DDRD &= ~(1<<6); PORTD &= ~(1<<6); }
|
|
|
|
inline void ergodox_right_led_1_off(void) { DDRB &= ~(1<<5); PORTB &= ~(1<<5); }
|
|
|
|
inline void ergodox_right_led_2_off(void) { DDRB &= ~(1<<6); PORTB &= ~(1<<6); }
|
|
|
|
inline void ergodox_right_led_3_off(void) { DDRB &= ~(1<<7); PORTB &= ~(1<<7); }
|
|
|
|
inline void ergodox_right_led_off(uint8_t led) { DDRB &= ~(1<<(led+4)); PORTB &= ~(1<<(led+4)); }
|
|
|
|
|
|
|
|
|
2022-02-06 13:27:09 -08:00
|
|
|
inline void ergodox_led_all_on(void) {
|
|
|
|
ergodox_board_led_on();
|
|
|
|
ergodox_right_led_1_on();
|
|
|
|
ergodox_right_led_2_on();
|
|
|
|
ergodox_right_led_3_on();
|
2022-02-06 12:00:50 -08:00
|
|
|
}
|
|
|
|
|
2022-02-06 13:27:09 -08:00
|
|
|
inline void ergodox_led_all_off(void) {
|
|
|
|
ergodox_board_led_off();
|
|
|
|
ergodox_right_led_1_off();
|
|
|
|
ergodox_right_led_2_off();
|
|
|
|
ergodox_right_led_3_off();
|
2022-02-06 12:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void ergodox_right_led_1_set(uint8_t n) { OCR1A = n; }
|
|
|
|
inline void ergodox_right_led_2_set(uint8_t n) { OCR1B = n; }
|
|
|
|
inline void ergodox_right_led_3_set(uint8_t n) { OCR1C = n; }
|
|
|
|
inline void ergodox_right_led_set(uint8_t led, uint8_t n) {
|
2022-02-06 13:27:09 -08:00
|
|
|
(led == 1) ? (OCR1A = n) :
|
|
|
|
(led == 2) ? (OCR1B = n) :
|
|
|
|
(OCR1C = n);
|
2022-02-06 12:00:50 -08:00
|
|
|
}
|
|
|
|
|
2022-02-06 13:27:09 -08:00
|
|
|
inline void ergodox_led_all_set(uint8_t n) {
|
|
|
|
ergodox_right_led_1_set(n);
|
|
|
|
ergodox_right_led_2_set(n);
|
|
|
|
ergodox_right_led_3_set(n);
|
2022-02-06 12:00:50 -08:00
|
|
|
}
|
|
|
|
|
2022-07-21 18:16:23 -07:00
|
|
|
enum betalupi_keycodes {
|
2022-02-06 13:27:09 -08:00
|
|
|
LED_LEVEL = SAFE_RANGE,
|
|
|
|
TOGGLE_LAYER_COLOR,
|
2022-06-17 12:06:53 -07:00
|
|
|
// Custom RGBLIGHT macros
|
|
|
|
LIGHT_TOG, // Toggle backlight
|
|
|
|
LIGHT_HUI, // Increase backlight hue
|
|
|
|
LIGHT_HUD, // Decrease backlight hue
|
|
|
|
LIGHT_SAI, // Increase backlight sat
|
|
|
|
LIGHT_SAD, // Decrease backlight sat
|
|
|
|
LIGHT_VAI, // Increase backlight val
|
|
|
|
LIGHT_VAD, // Decrease backlight val
|
|
|
|
LIGHT_SPI, // Increase backlight speed
|
|
|
|
LIGHT_SPD, // Decrease backlight speed
|
|
|
|
LIGHT_MOD, // Change backlight animation mode
|
|
|
|
BETA_SAFE_RANGE
|
2022-02-06 12:00:50 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef union {
|
|
|
|
uint32_t raw;
|
|
|
|
struct {
|
2022-02-06 13:27:09 -08:00
|
|
|
uint8_t led_level :3;
|
|
|
|
bool disable_layer_led :1;
|
|
|
|
bool rgb_matrix_enable :1;
|
2022-02-06 12:00:50 -08:00
|
|
|
};
|
|
|
|
} keyboard_config_t;
|
|
|
|
|
2023-12-19 09:03:31 -08:00
|
|
|
extern keyboard_config_t keyboard_config;
|