Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Keyboard annepro2 bidir led comms #5

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions keyboards/annepro2/annepro2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "hal.h"
#include "annepro2.h"
#include "annepro2_ble.h"
#include "qmk_ap2_led.h"

static const SerialConfig ledUartConfig = {
.speed = 115200,
Expand Down Expand Up @@ -36,43 +35,14 @@ void OVERRIDE keyboard_post_init_kb(void) {
// Start BLE UART
sdStart(&SD1, &bleUartConfig);
annepro2_ble_startup();

keyboard_post_init_user();
}

void OVERRIDE matrix_init_kb(void) {
matrix_init_user();
}

void annepro2LedDisable(void)
{
sdPut(&SD0, CMD_LED_OFF);
}

void annepro2LedEnable(void)
{
sdPut(&SD0, CMD_LED_ON);
}

void annepro2LedUpdate(uint8_t row, uint8_t col)
{
sdPut(&SD0, CMD_LED_SET);
sdPut(&SD0, row);
sdPut(&SD0, col);
sdWrite(&SD0, (uint8_t *)&annepro2LedMatrix[row * MATRIX_COLS + col], sizeof(uint16_t));
}

void annepro2LedUpdateRow(uint8_t row)
{
sdPut(&SD0, CMD_LED_SET_ROW);
sdPut(&SD0, row);
sdWrite(&SD0, (uint8_t *)&annepro2LedMatrix[row * MATRIX_COLS], sizeof(uint16_t) * MATRIX_COLS);
}

bool OVERRIDE led_update_kb(led_t status) {
annepro2LedMatrix[2 * MATRIX_COLS] = status.caps_lock ? 0x4FF : 0;
annepro2LedUpdate(2, 0);
return led_update_user(status);
}

/*!
* @returns false processing for this keycode has been completed.
*/
Expand Down
5 changes: 0 additions & 5 deletions keyboards/annepro2/annepro2.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,3 @@ enum AP2KeyCodes {
KC_AP2_USB,
AP2_SAFE_RANGE,
};

void annepro2LedDisable(void);
void annepro2LedEnable(void);
void annepro2LedUpdate(uint8_t row, uint8_t col);
void annepro2LedUpdateRow(uint8_t row);
3 changes: 2 additions & 1 deletion keyboards/annepro2/c15/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
SRC = \
matrix.c \
hardfault_handler.c \
annepro2_ble.c
annepro2_ble.c \
qmk_ap2_led.c

LAYOUTS +=

Expand Down
3 changes: 2 additions & 1 deletion keyboards/annepro2/c18/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
SRC = \
matrix.c \
hardfault_handler.c \
annepro2_ble.c
annepro2_ble.c \
qmk_ap2_led.c

LAYOUTS +=

Expand Down
9 changes: 7 additions & 2 deletions keyboards/annepro2/keymaps/codetector/keymap.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdint.h>
#include "annepro2.h"
#include "qmk_ap2_led.h"

enum anne_pro_layers {
_BASE_LAYER,
Expand Down Expand Up @@ -64,12 +65,16 @@ layer_state_t layer_state_set_user(layer_state_t layer) {
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_AP_LED_OFF:
if (record->event.pressed)
if (record->event.pressed) {
annepro2LedDisable();
annepro2LedPrevProfile();
}
return false;
case KC_AP_LED_ON:
if (record->event.pressed)
if (record->event.pressed) {
annepro2LedEnable();
annepro2LedNextProfile();
}
return false;
default:
break;
Expand Down
9 changes: 7 additions & 2 deletions keyboards/annepro2/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdint.h>
#include "annepro2.h"
#include "qmk_ap2_led.h"

enum anne_pro_layers {
_BASE_LAYER,
Expand Down Expand Up @@ -109,12 +110,16 @@ layer_state_t layer_state_set_user(layer_state_t layer) {
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_AP_LED_OFF:
if (record->event.pressed)
if (record->event.pressed) {
annepro2LedDisable();
annepro2LedPrevProfile();
}
return false;
case KC_AP_LED_ON:
if (record->event.pressed)
if (record->event.pressed) {
annepro2LedEnable();
annepro2LedNextProfile();
}
return false;
default:
break;
Expand Down
60 changes: 60 additions & 0 deletions keyboards/annepro2/qmk_ap2_led.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "hal.h"
#include "annepro2.h"
#include "qmk_ap2_led.h"

void annepro2LedDisable(void)
{
sdPut(&SD0, CMD_LED_OFF);
}

void annepro2LedEnable(void)
{
sdPut(&SD0, CMD_LED_ON);
}

void annepro2LedUpdate(uint8_t row, uint8_t col)
{
sdPut(&SD0, CMD_LED_SET);
sdPut(&SD0, row);
sdPut(&SD0, col);
sdWrite(&SD0, (uint8_t *)&annepro2LedMatrix[row * MATRIX_COLS + col], sizeof(uint16_t));
}

void annepro2LedUpdateRow(uint8_t row)
{
sdPut(&SD0, CMD_LED_SET_ROW);
sdPut(&SD0, row);
sdWrite(&SD0, (uint8_t *)&annepro2LedMatrix[row * MATRIX_COLS], sizeof(uint16_t) * MATRIX_COLS);
}

void annepro2LedSetProfile(uint8_t prof)
{
sdPut(&SD0, CMD_LED_SET_PROFILE);
sdPut(&SD0, prof);
}

uint8_t annepro2LedGetProfile()
{
uint8_t buf = 0;
sdPut(&SD0, CMD_LED_GET_PROFILE);
buf = sdGet(&SD0);
return buf;
}

uint8_t annepro2LedGetNumProfiles()
{
uint8_t buf = 0;
sdPut(&SD0, CMD_LED_GET_NUM_PROFILES);
buf = sdGet(&SD0);
return buf;
}

void annepro2LedNextProfile()
{
sdPut(&SD0, CMD_LED_NEXT_PROFILE);
}

void annepro2LedPrevProfile()
{
sdPut(&SD0, CMD_LED_PREV_PROFILE);
}
15 changes: 15 additions & 0 deletions keyboards/annepro2/qmk_ap2_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,18 @@
#define CMD_LED_OFF 0x2
#define CMD_LED_SET 0x3
#define CMD_LED_SET_ROW 0x4
#define CMD_LED_SET_PROFILE 0x5
#define CMD_LED_NEXT_PROFILE 0x6
#define CMD_LED_PREV_PROFILE 0x7
#define CMD_LED_GET_PROFILE 0x8
#define CMD_LED_GET_NUM_PROFILES 0x9

void annepro2LedDisable(void);
void annepro2LedEnable(void);
void annepro2LedUpdate(uint8_t row, uint8_t col);
void annepro2LedUpdateRow(uint8_t row);
void annepro2LedSetProfile(uint8_t prof);
uint8_t annepro2LedGetProfile(void);
uint8_t annepro2LedGetNumProfiles(void);
void annepro2LedNextProfile(void);
void annepro2LedPrevProfile(void);