Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaxin96 committed Aug 7, 2024
1 parent 3c73e5c commit 6289494
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 21 deletions.
9 changes: 9 additions & 0 deletions keyboards/yandrstudio/dev/apmhs/apmhs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "quantum.h"

#include "apmhs.h"

// globol
kb_cstm_config_t kb_cstm_config;

void eeconfig_init_kb(void) {
eeconfig_init_user();
}

void keyboard_post_init_kb(void) {
keyboard_post_init_user();
#ifdef CONSOLE_ENABLE
Expand Down
12 changes: 11 additions & 1 deletion keyboards/yandrstudio/dev/apmhs/apmhs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@
{ K200, K201, K202, K203, K204, K205, K206, K207, K208, K209, K210, K211, KC_NO, K213, K214 }, \
{ K300, KC_NO, K302, K303, K304, K305, K306, K307, K308, K309, K310, K311, K312, K313, KC_NO}, \
{ K400, K401, K402, KC_NO, KC_NO, KC_NO, K406, KC_NO, KC_NO, K409, K410, K411, K412, K413, K414 } \
}
}


typedef union {
uint8_t raw[EECONFIG_YR_DATA_SIZE];
struct {
uint8_t t2[EECONFIG_YR_DATA_SIZE];
};
} __attribute__((packed)) kb_cstm_config_t;

extern kb_cstm_config_t kb_cstm_config;
14 changes: 13 additions & 1 deletion keyboards/yandrstudio/dev/apmhs/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define MATRIX_COLS 15

#define ADC_RESOLUTION ADC_CFGR1_RES_12BIT

#define ADC_SAMPLING_RATE ADC_SMPR_SMP_13P5

#define NUM_OF_MUX 10
#define MUX_ADD_PIN0 C8
Expand All @@ -38,3 +38,15 @@
{{4,0}, {3,4}, {4,2}, {3,6}, {3,2}, {2,9}, {4, 4}, {4, 7}, {4, 5}, {4, 9}} \
}

// 405XE
#define FEE_MCU_FLASH_SIZE 512
#define BACKING_STORE_WRITE_SIZE 2
#define WEAR_LEVELING_LEGACY_EMULATION_PAGE_SIZE 16384
#define WEAR_LEVELING_BACKING_SIZE (16384)
#define WEAR_LEVELING_LOGICAL_SIZE ((WEAR_LEVELING_BACKING_SIZE) / 2)
#define WEAR_LEVELING_LEGACY_EMULATION_PAGE_COUNT 1
#define WEAR_LEVELING_LEGACY_EMULATION_BASE_PAGE_ADDRESS (WEAR_LEVELING_LEGACY_EMULATION_FLASH_BASE + (2 * (WEAR_LEVELING_LEGACY_EMULATION_PAGE_SIZE))) // +32k


#define EECONFIG_YR_FLASH_BASE 0x0800C000 // +48K
#define EECONFIG_YR_DATA_SIZE (16384)
86 changes: 86 additions & 0 deletions keyboards/yandrstudio/dev/apmhs/f4xx/ld/M32F4xE_YR.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
* STM32F405xG memory setup.
* Note: Use of ram1 and ram2 is mutually exclusive with use of ram0.
*/
MEMORY
{
flash0 (rx) : org = 0x08000000, len = 32k /* Sector 0,1 - BOOTLOADER */
flash1 (rx) : org = 0x08000000+32k, len = 16k /* Sector 2 - Emulated eeprom */
flash2 (rx) : org = 0x08000000+48k, len = 16k /* Sector 3 - USER DATA */
flash3 (rx) : org = 0x00000000+64k, len = 512k - 64k /* Sector 4..6 - Rest of firmware */
flash4 (rx) : org = 0x00000000, len = 0
flash5 (rx) : org = 0x00000000, len = 0
flash6 (rx) : org = 0x00000000, len = 0
flash7 (rx) : org = 0x00000000, len = 0
ram0 (wx) : org = 0x20000000, len = 128k /* SRAM1 + SRAM2 */
ram1 (wx) : org = 0x20000000, len = 112k /* SRAM1 */
ram2 (wx) : org = 0x2001C000, len = 16k /* SRAM2 */
ram3 (wx) : org = 0x00000000, len = 0
ram4 (wx) : org = 0x10000000, len = 64k /* CCM SRAM */
ram5 (wx) : org = 0x40024000, len = 4k /* BCKP SRAM */
ram6 (wx) : org = 0x00000000, len = 0
ram7 (wx) : org = 0x00000000, len = 0
}

/* For each data/text section two region are defined, a virtual region
and a load region (_LMA suffix).*/

/* Flash region to be used for exception vectors.*/
REGION_ALIAS("VECTORS_FLASH", flash0);
REGION_ALIAS("VECTORS_FLASH_LMA", flash0);

/* Flash region to be used for constructors and destructors.*/
REGION_ALIAS("XTORS_FLASH", flash3);
REGION_ALIAS("XTORS_FLASH_LMA", flash3);

/* Flash region to be used for code text.*/
REGION_ALIAS("TEXT_FLASH", flash3);
REGION_ALIAS("TEXT_FLASH_LMA", flash3);

/* Flash region to be used for read only data.*/
REGION_ALIAS("RODATA_FLASH", flash3);
REGION_ALIAS("RODATA_FLASH_LMA", flash3);

/* Flash region to be used for various.*/
REGION_ALIAS("VARIOUS_FLASH", flash3);
REGION_ALIAS("VARIOUS_FLASH_LMA", flash3);

/* Flash region to be used for RAM(n) initialization data.*/
REGION_ALIAS("RAM_INIT_FLASH_LMA", flash3);

/* RAM region to be used for Main stack. This stack accommodates the processing
of all exceptions and interrupts.*/
REGION_ALIAS("MAIN_STACK_RAM", ram0);

/* RAM region to be used for the process stack. This is the stack used by
the main() function.*/
REGION_ALIAS("PROCESS_STACK_RAM", ram0);

/* RAM region to be used for data segment.*/
REGION_ALIAS("DATA_RAM", ram0);
REGION_ALIAS("DATA_RAM_LMA", flash3);

/* RAM region to be used for BSS segment.*/
REGION_ALIAS("BSS_RAM", ram0);

/* RAM region to be used for the default heap.*/
REGION_ALIAS("HEAP_RAM", ram0);

/* Generic rules inclusion.*/
INCLUDE rules.ld
5 changes: 5 additions & 0 deletions keyboards/yandrstudio/dev/apmhs/f4xx/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# MCU name
MCU = STM32F405
BOOTLOADER = stm32-dfu

MCU_LDSCRIPT = M32F4xE_YR
6 changes: 4 additions & 2 deletions keyboards/yandrstudio/dev/apmhs/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"mousekey": true,
"extrakey": true
},
"keyboard_name": "ATEST",
"rgblight": {
"led_count": 69,
"animations": {
Expand All @@ -27,7 +28,8 @@
"driver": "pwm"
},
"usb": {
"vid": "0x1209",
"pid": "0x4920"
"vid": "0xAA96",
"pid": "0xFF00",
"device_version": "1.0.0"
}
}
9 changes: 7 additions & 2 deletions keyboards/yandrstudio/dev/apmhs/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include QMK_KEYBOARD_H
#include "debug.h"
#include "analog.h"
#include "apmhs.h"

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LAYOUT(
Expand All @@ -15,7 +16,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {


void keyboard_post_init_user(void) {

}
// static void dummy_vt_callback(virtual_timer_t *vtp, void *p) {}

Expand All @@ -24,7 +25,7 @@ static uint32_t adc_debug_timer = 0;
void housekeeping_task_user(void) {
uint32_t timer_now = timer_read32();
if (TIMER_DIFF_32(timer_now, adc_debug_timer) >= 1000) {
dprintf("==========MATRIX ADC VAL, VUSB:%d, VHC:%d=============\n", analogReadPin(B1), analogReadPin(B0));
dprintf("==========MATRIX ADC VAL, VUSB:%d, VHC:%d, VREF:%d, %d=============\n", analogReadPin(B1), analogReadPin(B0), adc_read(TO_MUX(ADC_CHANNEL_VREFINT, 0)), kb_cstm_config.raw[1]);
dprintf(" ");
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
dprintf("C%2d ", current_col+1);
Expand All @@ -46,3 +47,7 @@ void housekeeping_task_user(void) {
// chVTSetContinuous(&vt, TIME_MS2I(10), dummy_vt_callback, NULL);
}

void dummy_cb(USBDriver *usbp) {
(void)usbp;
rgblight_setrgb_at(0,0,100,0);
}
4 changes: 3 additions & 1 deletion keyboards/yandrstudio/dev/apmhs/keymaps/default/rules.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
NO_USB_STARTUP_CHECK = yes
# USB_WAIT_FOR_ENUMERATION = yes
EEPROM_DRIVER = transient
# EEPROM_DRIVER = transient
WEAR_LEVELING_DRIVER = legacy
VIA_ENABLE = yes
12 changes: 11 additions & 1 deletion keyboards/yandrstudio/dev/apmhs/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static bool read_matrix(matrix_row_t current_matrix[], uint8_t current_row, uint

// 多次采样取平均值
mag_keys[current_row][current_col].last_adc = get_curr_adc_val(current_mux, current_addr);

// wait_ms(1);
debug_for_adc();
return matrix_changed;
}
Expand Down Expand Up @@ -102,6 +102,13 @@ void matrix_init_custom(void) {

analogReadPin(B0);
analogReadPin(B1);

gpio_set_pin_output(MUX_ADD_PIN0);
gpio_set_pin_output(MUX_ADD_PIN1);
gpio_set_pin_output(MUX_ADD_PIN2);
writePin(MUX_ADD_PIN0, 1);
writePin(MUX_ADD_PIN1, 1);
writePin(MUX_ADD_PIN2, 0);
}


Expand All @@ -116,6 +123,9 @@ uint8_t matrix_scan_custom(matrix_row_t current_matrix[]) {
// Set addr, scan key
uint8_t current_col = 0;
uint8_t current_row = 0;
adc_read(TO_MUX(ADC_CHANNEL_VREFINT, 0));
adc_read(TO_MUX(ADC_CHANNEL_VREFINT, 0));
adc_read(TO_MUX(ADC_CHANNEL_VREFINT, 0));
for (uint8_t current_addr = 0; current_addr < 8; ++current_addr) {
set_mux_addr(current_addr);
for (uint8_t current_mux = 0; current_mux < NUM_OF_MUX; ++current_mux) {
Expand Down
2 changes: 1 addition & 1 deletion keyboards/yandrstudio/dev/apmhs/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
make yandrstudio/dev/apmhs/rev1/stm32:default
make yandrstudio/dev/apmhs/f4xx:default
5 changes: 0 additions & 5 deletions keyboards/yandrstudio/dev/apmhs/rev1/info.json

This file was deleted.

6 changes: 0 additions & 6 deletions keyboards/yandrstudio/dev/apmhs/rev1/stm32/info.json

This file was deleted.

Empty file.
2 changes: 2 additions & 0 deletions keyboards/yandrstudio/dev/apmhs/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ SRC += analog.c

CUSTOM_MATRIX = lite # for using the A9 pin as matrix io
QUANTUM_SRC += matrix.c

KEYBOARD_SHARED_EP = yes # Free up some extra endpoints - needed if console+mouse+extra
8 changes: 7 additions & 1 deletion tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,16 @@ static bool usb_requests_hook_cb(USBDriver *usbp) {
return false;
}

static __attribute__((unused)) void dummy_cb(USBDriver *usbp) {
// static __attribute__((unused)) void dummy_cb(USBDriver *usbp) {
// (void)usbp;
// rgblight_setrgb_at(0,0,100,0);
// }
__attribute__((weak)) void dummy_cb(USBDriver *usbp) {
(void)usbp;
}



static const USBConfig usbcfg = {
usb_event_cb, /* USB events callback */
usb_get_descriptor_cb, /* Device GET_DESCRIPTOR request callback */
Expand Down

0 comments on commit 6289494

Please sign in to comment.