annepro2: more fixes

This commit is contained in:
bwisn 2021-10-18 23:33:02 +02:00
parent 77ada6d94b
commit 41a8091a08
15 changed files with 40 additions and 425 deletions

View File

@ -14,7 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ch.h"
#include "hal.h"
#include "annepro2.h"
#include "annepro2_ble.h"
@ -26,10 +25,6 @@ static const SerialConfig ledUartInitConfig = {
.speed = 115200,
};
/*
* Some people have serial issues between main chip and led chip.
* This code allows them to easily reduce the speed to 9600 for testing
*/
static const SerialConfig ledUartRuntimeConfig = {
.speed = 115200,
};
@ -42,7 +37,7 @@ static uint8_t ledMcuWakeup[11] = {0x7b, 0x10, 0x43, 0x10, 0x03, 0x00, 0x00, 0x7
ble_capslock_t BLECapsLock = {._dummy = {0}, .caps_lock = false};
void OVERRIDE bootloader_jump(void) {
void bootloader_jump(void) {
// Send msg to shine to boot into IAP
annepro2SetIAP();
@ -106,13 +101,6 @@ void matrix_scan_kb() {
// read it into the capslock struct
while (!sdGetWouldBlock(&SD1)) {
sdReadTimeout(&SD1, (uint8_t *)&BLECapsLock, sizeof(ble_capslock_t), 10);
// if it's capslock from ble, darken led
if (BLECapsLock.caps_lock) {
// annepro2LedClearMask(MATRIX_COLS * 2);
} else {
// annepro2LedSetMask(MATRIX_COLS * 2);
}
}
/* While there's data from LED keyboard sent - read it. */

View File

@ -29,9 +29,6 @@ extern uint16_t annepro2LedMatrix[MATRIX_ROWS * MATRIX_COLS];
extern ble_capslock_t BLECapsLock;
/* System clock - needed for custom matrix lite */
#define STM32_SYSCLK HT32_CK_SYS_FREQUENCY
// Matrix keymap
// clang-format off
#define LAYOUT( \

View File

@ -1,5 +0,0 @@
# List of all the board related files.
BOARDSRC = $(BOARD_PATH)/boards/ANNEPRO2/board.c
# Required include directories
BOARDINC = $(BOARD_PATH)/boards/ANNEPRO2

View File

@ -15,7 +15,6 @@
*/
#include <string.h>
#include "ch.h"
#include "hal.h"
#include "wait.h"
#include "led.h"
@ -176,13 +175,5 @@ void __early_init(void) {
ht32_clock_init();
}
/**
* @brief Board-specific initialization code.
* @todo Add your board-specific code, if any.
*/
void boardInit(void) {
#if HAL_USE_GPT == TRUE
gpt_init();
#endif
// spi_init();
}

View File

@ -0,0 +1,5 @@
# List of all the board related files.
BOARDSRC = $(BOARD_PATH)/boards/ANNEPRO2_C15/board.c
# Required include directories
BOARDINC = $(BOARD_PATH)/boards/ANNEPRO2_C15

View File

@ -1,5 +1,5 @@
# List of all the board related files.
BOARDSRC = $(BOARD_PATH)/boards/ANNEPRO2/board.c
BOARDSRC = $(BOARD_PATH)/boards/ANNEPRO2_C15/board.c
# Required include directories
BOARDINC = $(BOARD_PATH)/boards/ANNEPRO2_C18

View File

@ -18,8 +18,8 @@
#pragma once
/* USB Device descriptor parameter */
#define VENDOR_ID 0x04d9
#define PRODUCT_ID 0xa290
#define VENDOR_ID 0xfeed
#define PRODUCT_ID 0xac15
#define DEVICE_VER 0x1337
#define MANUFACTURER Obins
#define PRODUCT Anne Pro 2 QMK

View File

@ -18,10 +18,10 @@
#pragma once
/* USB Device descriptor parameter */
#define VENDOR_ID 0x04d9
#define PRODUCT_ID 0xa291
#define VENDOR_ID 0xfeed
#define PRODUCT_ID 0xac18
#define DEVICE_VER 0x1337
#define MANUFACTURER Holtek
#define MANUFACTURER Obins
#define PRODUCT Anne Pro 2(c18)QMK
#define ANNEPRO2_C18
@ -31,11 +31,6 @@
#define MATRIX_COLS 14
// layer size: MATRIX_ROWS * MATRIX_COLS * sizeof(uint16_t) = 144 bytes
// Max available layers
#define MAX_LAYERS 8
// keymaps size: layer size * MAX_LAYERS = 1152 bytes
#define KEYMAP_60_ANSI
// Number of supported layouts
#define NUM_LAYOUTS 4
@ -51,90 +46,4 @@
#define SPI_MOSI_PAL_MODE 5
#define SPI_MISO_PIN A2
#define SPI_MISO_PAL_MODE 5
// EEPROM Config for W25X20CL
#define EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN A3
#define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 16
#define EXTERNAL_EEPROM_BYTE_COUNT 1024 // 262144
#define EXTERNAL_EEPROM_PAGE_SIZE 256
#define EXTERNAL_EEPROM_ADDRESS_SIZE 3
#define EXTERNAL_EEPROM_SPI_LSBFIRST false
#define EXTERNAL_EEPROM_SPI_MODE 3
// HAL Config
#define HAL_USE_SPI TRUE
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
// MCU Config
#define HT32_SPI_USE_SPI1 TRUE
#define HT32_SPI1_IRQ_PRIORITY 9
#endif
/* number of backlight levels */
// #define BACKLIGHT_LEVELS 10
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
//#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
//#define LOCKING_RESYNC_ENABLE
/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
* This is userful for the Windows task manager shortcut (ctrl+shift+esc).
*/
// #define GRAVE_ESC_CTRL_OVERRIDE
/*
* Force NKRO
*
* Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
* state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
* makefile for this to work.)
*
* If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
* until the next keyboard reset.
*
* NKRO may prevent your keystrokes from being detected in the BIOS, but it is
* fully operational during normal computer usage.
*
* For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
* or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
* bootmagic, NKRO mode will always be enabled until it is toggled again during a
* power-up.
*
*/
#define FORCE_NKRO
/*
* Magic Key Options
*
* Magic keys are hotkey commands that allow control over firmware functions of
* the keyboard. They are best used in combination with the HID Listen program,
* found here: https://www.pjrc.com/teensy/hid_listen.html
*
* The options below allow the magic key functionality to be changed. This is
* useful if your keyboard/keypad is missing keys and you want magic key support.
*
*/
/* key combination for magic key command */
/*
#define IS_COMMAND() ( \
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
)
*/
/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/
/* disable debug print */
// #define NO_DEBUG
/* disable print */
// #define NO_PRINT
/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION

View File

@ -1,197 +0,0 @@
/* Copyright 2020 Nick Brassel (tzarc) and tech2077
*
* 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 <stdint.h>
#include <string.h>
/*
Note that the implementations of eeprom_XXXX_YYYY on AVR are normally
provided by avr-libc. The same functions are reimplemented below and are
rerouted to the external SPI equivalent.
Seemingly, as this is compiled from within QMK, the object file generated
during the build overrides the avr-libc implementation during the linking
stage.
On other platforms such as ARM, there are no provided implementations, so
there is nothing to override during linkage.
*/
#include "wait.h"
#include "spi_master.h"
#include "eeprom.h"
#include "eeprom_w25x20cl.h"
#include "timer.h"
#include "debug.h"
#define CMD_WREN 0x06u
#define CMD_WRDI 0x04u
#define CMD_RDSR 0x05u
#define CMD_WRSR 0x01u
#define CMD_READ 0x03u
#define CMD_WRITE 0x02u
#define CMD_SECTOR_ERASE 0x20u
#define SR_WIP 0x01u
// #define DEBUG_EEPROM_OUTPUT
#ifndef EXTERNAL_EEPROM_SPI_TIMEOUT
# define EXTERNAL_EEPROM_SPI_TIMEOUT 100
#endif
bool spi_eeprom_start(void) { return spi_start(EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN, EXTERNAL_EEPROM_SPI_LSBFIRST, EXTERNAL_EEPROM_SPI_MODE, EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR); }
static spi_status_t spi_eeprom_wait_while_busy(int timeout) {
uint32_t deadline = timer_read32() + timeout;
spi_status_t response;
spi_write(CMD_RDSR);
do {
response = spi_read();
if (timer_read32() >= deadline) {
return SPI_STATUS_TIMEOUT;
}
} while ((uint16_t)response & SR_WIP);
return SPI_STATUS_SUCCESS;
}
//----------------------------------------------------------------------------------------------------------------------
void eeprom_erase(uint32_t addr) {
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
uint32_t start = timer_read32();
#endif
spi_eeprom_start();
spi_write(CMD_WREN);
spi_stop();
spi_eeprom_start();
spi_write(CMD_SECTOR_ERASE);
spi_write((uint8_t)((addr & 0xFF0000u) >> 16u));
spi_write((uint8_t)((addr & 0x00FF00u) >> 8u));
spi_write((uint8_t)((addr & 0x0000FFu)));
spi_stop();
spi_eeprom_start();
spi_status_t response = spi_eeprom_wait_while_busy(10000);
spi_stop();
if (response == SPI_STATUS_TIMEOUT) {
dprint("SPI timeout for WIP check\n");
return;
}
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
dprintf("EEPROM erase took %ldms to complete\n", ((long)(timer_read32() - start)));
#endif
}
void eeprom_read(void *buf, uint32_t addr, size_t len) {
//-------------------------------------------------
// Wait for the write-in-progress bit to be cleared
bool res = spi_eeprom_start();
if (!res) {
dprint("failed to start SPI for WIP check\n");
spi_stop();
return;
}
spi_status_t response = spi_eeprom_wait_while_busy(EXTERNAL_EEPROM_SPI_TIMEOUT);
spi_stop();
if (response == SPI_STATUS_TIMEOUT) {
dprint("SPI timeout for WIP check\n");
spi_stop();
return;
}
//-------------------------------------------------
// Perform read
res = spi_eeprom_start();
if (!res) {
dprint("failed to start SPI for read\n");
spi_stop();
return;
}
spi_write(CMD_READ);
spi_write((uint8_t)((addr & 0xFF0000u) >> 16u));
spi_write((uint8_t)((addr & 0x00FF00u) >> 8u));
spi_write((uint8_t)((addr & 0x0000FFu)));
spi_receive(buf, len);
spi_stop();
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
dprintf("[EEPROM R] 0x%08lX: ", (addr));
for (size_t i = 0; i < len; ++i) {
dprintf(" %02X", (int)(((uint8_t *)buf)[i]));
}
dprintf("\n");
#endif // DEBUG_EEPROM_OUTPUT
}
void eeprom_write(const void *buf, uint32_t addr, size_t len) {
eeprom_erase(addr);
//-------------------------------------------------
// Enable writes
bool res = spi_eeprom_start();
if (!res) {
dprint("failed to start SPI for write-enable\n");
spi_stop();
return;
}
spi_write(CMD_WREN);
spi_stop();
wait_us(1);
//-------------------------------------------------
// Perform the write
res = spi_eeprom_start();
if (!res) {
dprint("failed to start SPI for write\n");
spi_stop();
return;
}
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
dprintf("[EEPROM W] 0x%08lX: ", ((uint32_t)(uintptr_t)addr));
for (size_t i = 0; i < len; i++) {
dprintf(" %02X", (int)(uint8_t)(buf[i]));
}
dprintf("\n");
#endif // DEBUG_EEPROM_OUTPUT
spi_write(CMD_WRITE);
spi_write((uint8_t)((addr & 0xFF0000u) >> 16u));
spi_write((uint8_t)((addr & 0x00FF00u) >> 8u));
spi_write((uint8_t)((addr & 0x0000FFu)));
spi_transmit(buf, len);
spi_stop();
res = spi_eeprom_start();
if (!res) {
dprint("failed to start SPI for status\n");
spi_stop();
return;
}
spi_status_t response = spi_eeprom_wait_while_busy(EXTERNAL_EEPROM_SPI_TIMEOUT);
spi_stop();
if (response == SPI_STATUS_TIMEOUT) {
dprint("SPI timeout for WIP check\n");
return;
}
}

View File

@ -1,84 +0,0 @@
/* Copyright 2020 Nick Brassel (tzarc) and tech2077
*
* 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
void eeprom_erase(uint32_t addr);
void eeprom_read(void *buf, uint32_t addr, size_t len);
void eeprom_write(const void *buf, uint32_t addr, size_t len);
/*
The slave select pin of the EEPROM.
This needs to be a normal GPIO pin_t value, such as A7.
*/
#ifndef EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN
# error "No chip select pin defined -- missing EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN"
#endif
/*
The clock divisor for SPI to ensure that the MCU is within the
specifications of the EEPROM chip. Generally this will be PCLK divided by
the intended divisor -- check your clock settings and the datasheet of
your EEPROM.
*/
#ifndef EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR
# ifdef __AVR__
# define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 8
# else
# define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 64
# endif
#endif
/*
The SPI mode to communicate with the EEPROM.
*/
#ifndef EXTERNAL_EEPROM_SPI_MODE
# define EXTERNAL_EEPROM_SPI_MODE 0
#endif
/*
Whether or not the SPI communication between the MCU and EEPROM should be
LSB-first.
*/
#ifndef EXTERNAL_EEPROM_SPI_LSBFIRST
# define EXTERNAL_EEPROM_SPI_LSBFIRST false
#endif
/*
The total size of the EEPROM, in bytes. The EEPROM datasheet will usually
specify this value in kbits, and will require conversion to bytes.
*/
#ifndef EXTERNAL_EEPROM_BYTE_COUNT
# define EXTERNAL_EEPROM_BYTE_COUNT 8192
#endif
/*
The page size in bytes of the EEPROM, as specified in the datasheet.
*/
#ifndef EXTERNAL_EEPROM_PAGE_SIZE
# define EXTERNAL_EEPROM_PAGE_SIZE 32
#endif
/*
The address size in bytes of the EEPROM. For EEPROMs with <=256 bytes, this
will likely be 1. For EEPROMs >256 and <=65536, this will be 2. For EEPROMs
>65536, this will likely need to be 4.
As expected, consult the datasheet for specifics of your EEPROM.
*/
#ifndef EXTERNAL_EEPROM_ADDRESS_SIZE
# define EXTERNAL_EEPROM_ADDRESS_SIZE 2
#endif

View File

@ -25,4 +25,9 @@
#define SERIAL_USB_BUFFERS_SIZE 256
#if defined(ANNEPRO2_EEPROM)
#define HAL_USE_SPI TRUE
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
#endif
#include_next <halconf.h>

View File

@ -1,4 +1,19 @@
#include "ch.h"
/* 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 <string.h>
#include "hal.h"

View File

@ -25,15 +25,10 @@
#include "matrix.h"
#include "annepro2.h"
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
static uint32_t debounce_times[MATRIX_ROWS];
extern ioline_t row_list[MATRIX_ROWS];
extern ioline_t col_list[MATRIX_COLS];
void matrix_init_custom(void) {
memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
memset(debounce_times, 0, MATRIX_ROWS * sizeof(uint32_t));
}
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
@ -62,17 +57,8 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
data |= (((port & (1 << PAL_PAD(line))) ? 0 : 1) << col);
}
// if a key event happens <5ms before the system time rolls over,
// the event will "never" debounce
// but any event on the same row will reset the debounce timer
if (matrix_debouncing[row] != data) {
// whenever row changes restart debouncing
matrix_debouncing[row] = data;
debounce_times[row] = timer_read32();
} else if (debounce_times[row] && timer_elapsed32(debounce_times[row]) >= DEBOUNCE) {
// when debouncing complete, update matrix
current_matrix[row] = matrix_debouncing[row];
debounce_times[row] = 0;
if (current_matrix[row] != data) {
current_matrix[row] = data;
matrix_has_changed = true;
}
}

View File

@ -63,4 +63,9 @@
#define HT32_USB_USE_USB0 TRUE
#define HT32_USB_USB0_IRQ_PRIORITY 5
#if defined(ANNEPRO2_EEPROM)
#define HT32_SPI_USE_SPI1 TRUE
#define HT32_SPI1_IRQ_PRIORITY 9
#endif
#endif /* _MCUCONF_H_ */