Skip to content

Commit

Permalink
Add Anne Pro 2 keyboard (qmk#14385)
Browse files Browse the repository at this point in the history
* [keyboard] Initial support for Anne Pro 2

* [keyboard][AnnePro2] Keymap:update to a reasonable keymap with caps+hjkl => arrow

* :(

* changed to use HSI

* support for annepro2 c18

* keyboard/annepro2: Very stupid matrix scan bug fix.

* typo

* swap COL14/13

* keyboard/annepro2: startup secondary LED MCU

* keyboard/annepro2: typo fix

* Add IO Values

* Disable Combo feature

* Update default keymap to Anne Pro 2 Official Keymap

* keyboard/annepro2: keymap layer name changes

* keyboard/annepro2 BLE Support

* Fix keymap comment

FN1 ESC was listed as ~ instead of `

* keyboard/annepro2: Bluetooth path

* Keyboard annepro2 bidir led comms (#5)

* Added bidirectional shine comms and moved led functionality to new file

* Added bidirectional shine comms and moved led functionality to new file

* Restore original functionality to existing keymaps using new shine commands

* Fix dangling bracketless if statements

* PR cleanup

* add custom keycodes to switch led profiles

* Optimize code

* switch to prev profile before turning leds off

* Add persistent led support with eeprom (#9)

* adding HT32 support to chibios SPI master driver

* add support for W25X20CL SPI eeprom

* add makefile flag for eeprom feature

* add spi support to keyboard startup and config

* example keymap using eeprom profile loading

* Cleanup to fix C15 eeprom/spi build errors (#11)

* Cleanup to fix C15 eeprom/spi build errors

* add newline at eof

* LED Masking support for Shine

Introduce companion update to ledSetMask and ledClearMask.
In keymap `codetector` there is example of how to map caps_lock
to the caps_lock key light on the keyboard.

* [AnnePro2]: update bluetooth connection

* Merge the custom keys enums on annepro2.h (#13)

* Keyboard annepro2 ble caps lock (#12)

* Move matrix_scan_kb out of board.c to annepro2.c

* add buffer clear after init and caplock polling

* Add support for LED intensity (#15)

* Improve logic for switching off and on of LEDs (#16)

* Implement animation speed (#17)

* Include logic to send solid colors as foreground to shine and add sample profiles (#14)

Include the logic to send a solid color from qmk to shine. That solid color will act as a foreground (will override the current profile) until reset (witch will reactivate the current profile).
This functionality depends on changes made for shine as well.

Include 3 new profiles:

    default-full-caps -> same as default, but with the logic of using the red foreground color on caps lock.
    default-layer-indicators -> same as default, but with the logic of red foreground on caps lock, green foreground on FN1 and blue foreground on FN2.
    thomazmoura -> my own profile as a sample of an over-engineered advanced case scenario.

* Implement reactive lighting effects (#18)

* Added multiarrow keymap (#19)

* Add LED documentation (#26)

* add LED documentation

* add LED documentation to other default profiles

* Implement QMK's IAP default keybind (#29)

* Add keymap for going into IAP

* switch to default QMK keybind for IAP mode

* implement bluetooth IAP mode

* Make default config more like Obins stock default (#30)

* Add new message type for resetting foreground color (#31)

* annepro2(bluetooth): add media keys support (#41)

* Asynchronous, robust serial protocol. (#39)

* bla personal ap2-c18 keymap.

* Bidirectional, asynchronous message-based communication with Shine.

- Requires a matching Shine version.
- Protocol is resiliant to loosing bytes during communication, chips won't lock
  waiting for bytes that aren't coming.
- Chips resynchronize in event of loosing a byte using a AA0D header.

Regressions:
- Key masking/locking doesn't work right now. (did it work before?)
- Not all user keymaps build against it.

* Clang-format + code to ease reducing speed of LED UART.

- Did clang-format --style=file -i on multiple files according to
  coding_conventions_c.md

- Added separate serial speed for IAP boot and Led communication, it's possible
  that reducing this to 9600 helped someone with faulty HW. With this code they
  can do it with simple replacing of a value.

* Main chip can set/clear foreground using a mask mechanism.

- Some preparations for selective colouring.

* Selective mask works - tested on capslock.

- Migrated personal keymaps to new status API.

* Clear the foreground colors to show profile when it's modified.

- Show example of achieving selective caps-lock painting + foreground painting
  for layers.
- annepro2LedMaskSetRow is implemented, but still requires testing.

* Implement the QMK side of led blinking to indicate the command was received.

- This stupidly blinks the key when user presses one of the bluetooth commands
to let the user know that the command was received and forwarded to the BT chip.

- TODO: Row/col key positions are hardcoded and not taken from the keymap.

* Reduce memory footprint.

Applying code review suggestions. Moved msgId to globals - preparing for
transmission without copying payload when no retries are necessary.

Added empty readme.md files - required by QMK lint.

Co-authored-by: Tomasz bla Fortuna <[email protected]>

* Let the LED chip settle a bit before waking it from the bootloader. (#42)

At least for one person that helps to reliably get the LEDs working without
disconnecting/reconnecting the power to the board multiple times.

Co-authored-by: Tomasz bla Fortuna <[email protected]>

* annepro2: rename KEYMAP to LAYOUT, as required by new version of QMK

* annepro2: update ChibiOS configuration files

* annepro2: fix undefined reference to dprint and timer_read32

* annepro2: update ChibiOS MCU name

* update spi driver, fix bad merging with master

* annepro2: add readme and info.json

* annepro2: make code compatible with QMK coding conventions

* tmk_core: temporary fix to allow HT32 based keyboards to work without patched ChibiOS-contrib (AnnePro2)

* AnnePro2: removed core changes

* AnnePro2: Leave only default keymaps

Missing keymaps will be restored in another PR

* annepro2: add licence information

* annepro2: satisfy qmk lint

* annepro2: fix drashna's suggestions

* annepro2: fix matrix

* annepro2: apply code review suggestions

* annepro2: apply remaining code review suggestions

* annepro2: update info.json

* annepro2: remove include

* annepro2: rename keymap to layout

* annepro2: fix typing

* annepro2: apply suggestions from tzarc's code review

Co-authored-by: Nick Brassel <[email protected]>

* annepro2: more fixes

* annepro2: apply suggestions from code review

Co-authored-by: Joel Challis <[email protected]>

* annepro2: rename file

* more fixes

* Apply suggestions from @tzarc code review

Co-authored-by: Nick Brassel <[email protected]>

* Update keyboards/annepro2/protocol.h

Co-authored-by: Nick Brassel <[email protected]>

* Update keyboards/annepro2/chconf.h

Co-authored-by: Nick Brassel <[email protected]>

* apply CR suggestions

* upgrade readme

* IAP

* update IAP comments, defines

* led fix

* init fix

* annepro2: GPIO cleanup

* annepro2: ioline

* change waiting time

* Start develop for 2022q2

* [Core] Squeeze AVR some more with `-mrelax` and `-mcall-prologues` (qmk#16269)

* Rework generate-api CLI command to use .build directory (qmk#16441)

* Remove `send_unicode_hex_string()` (qmk#16518)

* Change data driven "str" type to represent a quoted string literal (qmk#16516)

* Change data driven "str" type to represent a quoted string literal

* Update docs

* Map data driven `DESCRIPTION` as string literal (qmk#16523)

* update bootloader

* Revert "Merge pull request #2 from qmk/develop"

This reverts commit 9c76065, reversing
changes made to 240745d.

* Revert "update bootloader"

This reverts commit 240745d.

* fix rules.mk

* change PROGRAM_CMD

Co-authored-by: codetector <[email protected]>
Co-authored-by: Fagl4 <[email protected]>
Co-authored-by: Jakob Gillich <[email protected]>
Co-authored-by: tech2077 <[email protected]>
Co-authored-by: jcdeA <[email protected]>
Co-authored-by: Thomaz Moura <[email protected]>
Co-authored-by: Darkhan <[email protected]>
Co-authored-by: Paco <[email protected]>
Co-authored-by: jmarmstrong1207 <[email protected]>
Co-authored-by: 1Conan <[email protected]>
Co-authored-by: Tomasz bla Fortuna <[email protected]>
Co-authored-by: Tomasz bla Fortuna <[email protected]>
Co-authored-by: Nick Brassel <[email protected]>
Co-authored-by: Joel Challis <[email protected]>
Co-authored-by: QMK Bot <[email protected]>
Co-authored-by: Stefan Kerkmann <[email protected]>
Co-authored-by: Ryan <[email protected]>
  • Loading branch information
18 people authored and zykrah committed Jul 2, 2022
1 parent d9eba6f commit 3796d17
Show file tree
Hide file tree
Showing 33 changed files with 2,459 additions and 0 deletions.
202 changes: 202 additions & 0 deletions keyboards/annepro2/annepro2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/* Copyright 2021 OpenAnnePro community
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "hal.h"
#include "annepro2.h"
#include "annepro2_ble.h"
#include "spi_master.h"
#include "ap2_led.h"
#include "protocol.h"

#define RAM_MAGIC_LOCATION 0x20001ffc
#define IAP_MAGIC_VALUE 0x0000fab2

static const SerialConfig ledUartInitConfig = {
.speed = 115200,
};

#ifndef LED_UART_BAUD_RATE
# define LED_UART_BAUD_RATE 115200
#endif // LED_UART_BAUD_RATE

static const SerialConfig ledUartRuntimeConfig = {
.speed = LED_UART_BAUD_RATE,
};

static const SerialConfig bleUartConfig = {
.speed = 115200,
};

static uint8_t ledMcuWakeup[11] = {0x7b, 0x10, 0x43, 0x10, 0x03, 0x00, 0x00, 0x7d, 0x02, 0x01, 0x02};

ble_capslock_t BLECapsLock = {._dummy = {0}, .caps_lock = false};

void bootloader_jump(void) {
// Send msg to shine to boot into IAP
annepro2SetIAP();

// wait for shine to boot into IAP
wait_ms(15);

// Load ble into IAP
annepro2_ble_bootload();
wait_ms(15);

// Magic key to set keyboard to IAP
// It’s from reversing original boot loader
// If value is that it stays in boot loader aka IAP
*((uint32_t *)RAM_MAGIC_LOCATION) = IAP_MAGIC_VALUE;

// Load the main MCU into IAP
__disable_irq();
NVIC_SystemReset();
}

void keyboard_pre_init_kb(void) {
// Start LED UART
sdStart(&SD0, &ledUartInitConfig);
/* Let the LED chip settle a bit before switching the mode.
* That helped at least one person. */
wait_ms(15);
sdWrite(&SD0, ledMcuWakeup, sizeof(ledMcuWakeup));

// wait to receive response from wakeup
wait_ms(15);

protoInit(&proto, ledCommandCallback);

// loop to clear out receive buffer from shine wakeup
while (!sdGetWouldBlock(&SD0)) sdGet(&SD0);

sdStart(&SD0, &ledUartRuntimeConfig);
keyboard_pre_init_user();
}

void keyboard_post_init_kb(void) {
// Start BLE UART
sdStart(&SD1, &bleUartConfig);
annepro2_ble_startup();

// Give the send uart thread some time to
// send out the queue before we read back
wait_ms(100);

// loop to clear out receive buffer from ble wakeup
while (!sdGetWouldBlock(&SD1)) sdGet(&SD1);

annepro2LedGetStatus();

keyboard_post_init_user();
}

void matrix_scan_kb() {
// if there's stuff on the ble serial buffer
// read it into the capslock struct
while (!sdGetWouldBlock(&SD1)) {
sdReadTimeout(&SD1, (uint8_t *)&BLECapsLock, sizeof(ble_capslock_t), 10);
}

/* While there's data from LED keyboard sent - read it. */
while (!sdGetWouldBlock(&SD0)) {
uint8_t byte = sdGet(&SD0);
protoConsume(&proto, byte);
}

matrix_scan_user();
}

bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
if (annepro2LedStatus.matrixEnabled && annepro2LedStatus.isReactive) {
annepro2LedForwardKeypress(record->event.key.row, record->event.key.col);
}

const annepro2Led_t blue = {
.p.blue = 0xff,
.p.red = 0x00,
.p.green = 0x00,
.p.alpha = 0xff,
};

switch (keycode) {
case KC_AP2_BT1:
annepro2_ble_broadcast(0);
/* FIXME: This hardcodes col/row position */
annepro2LedBlink(0, 1, blue, 8, 50);
return false;

case KC_AP2_BT2:
annepro2_ble_broadcast(1);
annepro2LedBlink(0, 2, blue, 8, 50);
return false;

case KC_AP2_BT3:
annepro2_ble_broadcast(2);
annepro2LedBlink(0, 3, blue, 8, 50);
return false;

case KC_AP2_BT4:
annepro2_ble_broadcast(3);
annepro2LedBlink(0, 4, blue, 8, 50);
return false;

case KC_AP2_USB:
annepro2_ble_disconnect();
return false;

case KC_AP2_BT_UNPAIR:
annepro2_ble_unpair();
return false;

case KC_AP_LED_OFF:
annepro2LedDisable();
break;

case KC_AP_LED_ON:
if (annepro2LedStatus.matrixEnabled) {
annepro2LedNextProfile();
} else {
annepro2LedEnable();
}
annepro2LedResetForegroundColor();
break;

case KC_AP_LED_NEXT_PROFILE:
annepro2LedNextProfile();
annepro2LedResetForegroundColor();
break;

case KC_AP_LED_PREV_PROFILE:
annepro2LedPrevProfile();
annepro2LedResetForegroundColor();
break;

case KC_AP_LED_NEXT_INTENSITY:
annepro2LedNextIntensity();
annepro2LedResetForegroundColor();
return false;

case KC_AP_LED_SPEED:
annepro2LedNextAnimationSpeed();
annepro2LedResetForegroundColor();
return false;

default:
break;
}
}
return process_record_user(keycode, record);
}
65 changes: 65 additions & 0 deletions keyboards/annepro2/annepro2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2018 Yaotian Feng
*
* 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 <http://www.gnu.org/licenses/>.
*/

#pragma once
#include "quantum.h"
#include <stdint.h>
#include "ap2_led.h"

typedef struct __attribute__((__packed__)) {
uint8_t _dummy[10];
bool caps_lock;
} ble_capslock_t;
extern ble_capslock_t BLECapsLock;

// Matrix keymap
// clang-format off
#define LAYOUT( \
K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, \
K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, \
K40, K42, K43, K46, K49, K4A, K4B, K4C \
) { \
/* COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10 COL11 COL12 COL13 COL14*/ \
/* ROW1 */ { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D }, \
/* ROW2 */ { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D }, \
/* ROW3 */ { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, KC_NO}, \
/* ROW4 */ { K30, KC_NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, KC_NO}, \
/* ROW5 */ { K40, KC_NO, K42, K43, KC_NO, KC_NO, K46, KC_NO, KC_NO, K49, K4A, K4B, K4C, KC_NO}, \
}
// clang-format on

enum AP2KeyCodes {
KC_AP2_BT1 = SAFE_RANGE,
KC_AP2_BT2,
KC_AP2_BT3,
KC_AP2_BT4,
KC_AP2_BT_UNPAIR,
KC_AP2_USB,
KC_AP_LED_ON,
KC_AP_LED_OFF,
KC_AP_LED_NEXT_PROFILE,
KC_AP_LED_PREV_PROFILE,
KC_AP_LED_NEXT_INTENSITY,
KC_AP_LED_SPEED,
AP2_SAFE_RANGE,
};

#undef SAFE_RANGE
#define SAFE_RANGE AP2_SAFE_RANGE

Loading

0 comments on commit 3796d17

Please sign in to comment.