qmk_firmware/keyboards/handwired/frenchdev/frenchdev.h

96 lines
2.6 KiB
C
Raw Permalink Normal View History

#pragma once
2016-10-07 17:18:49 +02:00
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "i2c_master.h"
2016-10-07 17:18:49 +02:00
#include <util/delay.h>
2017-06-23 21:35:33 +02:00
// I2C aliases and register addresses (see "mcp23018.md" on tmk repository)
#define I2C_ADDR (0b0100000<<1)
2016-10-07 17:18:49 +02:00
#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 uint8_t mcp23018_status;
#define I2C_TIMEOUT 100
2016-10-07 17:18:49 +02:00
2017-06-23 21:35:33 +02:00
void init_frenchdev(void);
void frenchdev_blink_all_leds(void);
2016-10-07 17:18:49 +02:00
uint8_t init_mcp23018(void);
#define LED_BRIGHTNESS_LO 15
#define LED_BRIGHTNESS_HI 255
#define FRENCHDEV_BOARD_LED_PIN D6
#define FRENCHDEV_LED_1_PIN B5
#define FRENCHDEV_LED_2_PIN B6
#define FRENCHDEV_LED_3_PIN B7
2016-10-07 17:18:49 +02:00
inline void frenchdev_board_led_on(void) {
gpio_set_pin_output(FRENCHDEV_BOARD_LED_PIN);
gpio_write_pin_high(FRENCHDEV_BOARD_LED_PIN);
}
inline void frenchdev_led_1_on(void) {
gpio_set_pin_output(FRENCHDEV_LED_1_PIN);
gpio_write_pin_high(FRENCHDEV_LED_1_PIN);
}
inline void frenchdev_led_2_on(void) {
gpio_set_pin_output(FRENCHDEV_LED_2_PIN);
gpio_write_pin_high(FRENCHDEV_LED_2_PIN);
}
inline void frenchdev_led_3_on(void) {
gpio_set_pin_output(FRENCHDEV_LED_3_PIN);
gpio_write_pin_high(FRENCHDEV_LED_3_PIN);
}
2016-10-07 17:18:49 +02:00
inline void frenchdev_board_led_off(void) {
gpio_set_pin_input(FRENCHDEV_BOARD_LED_PIN);
}
inline void frenchdev_led_1_off(void) {
gpio_set_pin_input(FRENCHDEV_LED_1_PIN);
}
inline void frenchdev_led_2_off(void) {
gpio_set_pin_input(FRENCHDEV_LED_2_PIN);
}
inline void frenchdev_led_3_off(void) {
gpio_set_pin_input(FRENCHDEV_LED_3_PIN);
}
2016-10-07 17:18:49 +02:00
2017-06-23 21:35:33 +02:00
inline void frenchdev_led_all_on(void)
2016-10-07 17:18:49 +02:00
{
2017-06-23 21:35:33 +02:00
frenchdev_board_led_on();
frenchdev_led_1_on();
frenchdev_led_2_on();
frenchdev_led_3_on();
2016-10-07 17:18:49 +02:00
}
2017-06-23 21:35:33 +02:00
inline void frenchdev_led_all_off(void)
2016-10-07 17:18:49 +02:00
{
2017-06-23 21:35:33 +02:00
frenchdev_board_led_off();
frenchdev_led_1_off();
frenchdev_led_2_off();
frenchdev_led_3_off();
2016-10-07 17:18:49 +02:00
}
2017-06-23 21:35:33 +02:00
inline void frenchdev_led_1_set(uint8_t n) { OCR1A = n; }
inline void frenchdev_led_2_set(uint8_t n) { OCR1B = n; }
inline void frenchdev_led_3_set(uint8_t n) { OCR1C = n; }
inline void frenchdev_led_set(uint8_t led, uint8_t n) {
2016-10-07 17:18:49 +02:00
(led == 1) ? (OCR1A = n) :
(led == 2) ? (OCR1B = n) :
(OCR1C = n);
}
2017-06-23 21:35:33 +02:00
inline void frenchdev_led_all_set(uint8_t n)
2016-10-07 17:18:49 +02:00
{
2017-06-23 21:35:33 +02:00
frenchdev_led_1_set(n);
frenchdev_led_2_set(n);
frenchdev_led_3_set(n);
2016-10-07 17:18:49 +02:00
}