Skip to content

Commit

Permalink
添加新键盘
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaxin96 committed Jun 26, 2021
1 parent 42b0038 commit 574b709
Show file tree
Hide file tree
Showing 49 changed files with 3,076 additions and 29 deletions.
53 changes: 53 additions & 0 deletions keyboards/yandrstudio/m60ble/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright 2021 JasonRen(biu)
*
* 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 "config_common.h"

/* USB Device descriptor parameter */
#define VENDOR_ID 0xAA96
#define PRODUCT_ID 0xAA05
#define DEVICE_VER 0x0001
#define MANUFACTURER JasonRen biu
#define PRODUCT m60ble

/* key matrix size */
#define MATRIX_ROWS 5
#define MATRIX_COLS 14

// 0 1 2 3 4 5 6 7 8 9 10 11 12 13
#define MATRIX_COL_PINS { B12, B13, B14, B15,A8, B5, B4, B3, A15,B6, B7, B8, B9, A2}
#define MATRIX_ROW_PINS { C14, C15, C13, A5, A4}

/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW


// enable the nkro when using the VIA.
#define FORCE_NKRO

// fix VIA RGB_light
#define VIA_HAS_BROKEN_KEYCODES

/* define if matrix has ghost */
//#define MATRIX_HAS_GHOST

/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5




25 changes: 25 additions & 0 deletions keyboards/yandrstudio/m60ble/f401/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright 2020 Nick Brassel (tzarc)
*
* 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 3 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 <https://www.gnu.org/licenses/>.
*/
#pragma once

#include_next "board.h"


#undef STM32_HSECLK
#define STM32_HSECLK 8000000


#define BOARD_YANDR_BIU_F401
34 changes: 34 additions & 0 deletions keyboards/yandrstudio/m60ble/f401/chconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Copyright 2020 QMK
*
* 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

#define CH_CFG_ST_FREQUENCY 10000

#define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE

#define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE

#define CH_CFG_FACTORY_SEMAPHORES TRUE

#define CH_CFG_FACTORY_MAILBOXES TRUE

#define CH_CFG_FACTORY_OBJ_FIFOS TRUE

#define CH_CFG_FACTORY_PIPES TRUE

#include_next <chconf.h>

61 changes: 61 additions & 0 deletions keyboards/yandrstudio/m60ble/f401/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Copyright 2021 JasonRen(biu)
*
* 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 "config_common.h"


/* RGN Matrix */
#ifdef RGB_MATRIX_ENABLE

# define RGB_DI_PIN A7
# define RGBLED_NUM 79
# define DRIVER_LED_TOTAL RGBLED_NUM

#define WS2812_PWM_DRIVER PWMD3 // default: PWMD2
#define WS2812_PWM_CHANNEL 2 // default: 2
#define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2
#define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.
#define WS2812_DMA_CHANNEL 5 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.


# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 180
# define RGBLIGHT_VAL_STEP 18
# define RGB_DISABLE_WHEN_USB_SUSPENDED true
# define RGB_MATRIX_CENTER { 32, 96 }
# define RGB_MATRIX_KEYPRESSES
# define RGB_MATRIX_FRAMEBUFFER_EFFECTS

#endif


#ifdef RGBLIGHT_ENABLE

# define RGB_DI_PIN A7
# define RGBLED_NUM 79
# define DRIVER_LED_TOTAL RGBLED_NUM


#define WS2812_PWM_DRIVER PWMD3 // default: PWMD2
#define WS2812_PWM_CHANNEL 2 // default: 2
#define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2
#define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.
#define WS2812_DMA_CHANNEL 5 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.

#endif



217 changes: 217 additions & 0 deletions keyboards/yandrstudio/m60ble/f401/eep/eeprom_stm32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/*
* This software is experimental and a work in progress.
* Under no circumstances should these files be used in relation to any critical system(s).
* Use of these files is at your own risk.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* This files are free to use from http://engsta.com/stm32-flash-memory-eeprom-emulator/ by
* Artur F.
*
* Modifications for QMK and STM32F303 by Yiancar
* update for STM32F4 support and the the flashing algorithm by yulei
* Adjust the file structure to custom EEPROM_DRIVER by jiaxin96 for support stm32f401cc
*/

#include <stdio.h>
#include <string.h>
#include "eeprom_stm32_custom.h"
#include "eeprom_driver.h"
/*****************************************************************************
* Allows to use the internal flash to store non volatile data. To initialize
* the functionality use the EEPROM_Init() function. Be sure that by reprogramming
* of the controller just affected pages will be deleted. In other case the non
* volatile data will be lost.
******************************************************************************/

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Functions -----------------------------------------------------------------*/

#define IS_VALID_ADDRESS(x) ((x) < FEE_MAX_BYTES)

uint8_t DataBuf[FEE_MAX_BYTES];
static void EEPROM_Backup(void);
static FLASH_Status EEPROM_Restore(void);
static uint32_t EEPROM_FindValidAddress(void);
static void EEPROM_Clear(void);

/*****************************************************************************
* Unlock the FLASH programming and initialized the DataBuf
******************************************************************************/
uint16_t EEPROM_Init(void) {
// unlock flash
FLASH_Unlock();

// initialize DataBuf
EEPROM_Backup();

// Clear Flags
// FLASH_ClearFlag(FLASH_SR_EOP|FLASH_SR_PGERR|FLASH_SR_WRPERR);

return FEE_DENSITY_BYTES;
}
void eeprom_driver_init(void) {
EEPROM_Init();
}

/*****************************************************************************
* Erase the whole reserved Flash Space used for user Data
******************************************************************************/
void EEPROM_Erase(void) {
// erase all flash pages
EEPROM_Clear();

// reset the content of the buffer
memset(&DataBuf[0], FEE_EMPTY_BYTE, sizeof(DataBuf));
}
void eeprom_driver_erase(void) {
EEPROM_Erase();
}
/*****************************************************************************
* Write data with its eeprom address to flash if there has empty words,
* otherwise backup the current valid data, erase all flash pages,
* and finally restore the valid data.
*******************************************************************************/
uint16_t EEPROM_WriteDataByte(uint16_t Address, uint8_t DataByte) {
FLASH_Status FlashStatus = FLASH_COMPLETE;

uint32_t addr;
// exit if not a valid address
if (!IS_VALID_ADDRESS(Address)) {
return 0;
}

// we are sure the address will not be out of bound
#pragma GCC diagnostic ignored "-Warray-bounds"
// same value, do not need program
if (DataBuf[Address] == DataByte) {
return FlashStatus;
}

// find the address can be written
addr = EEPROM_FindValidAddress();
DataBuf[Address] = DataByte;
#pragma GCC diagnostic pop
if (addr == FEE_EMPTY_VALUE) {
// EEPROM is full, need to erase and reprogramming
EEPROM_Clear();
EEPROM_Restore();
} else {
FLASH_ProgramHalfWord(FEE_ADDR_ADDRESS(addr), Address);
FLASH_ProgramHalfWord(FEE_DATA_ADDRESS(addr), DataByte);
}

return FlashStatus;
}
/*****************************************************************************
* Read once data byte from a specified address.
*******************************************************************************/
uint8_t EEPROM_ReadDataByte(uint16_t Address) {
if (!IS_VALID_ADDRESS(Address)) {
return FEE_EMPTY_BYTE;
}

// Get Byte from caches
return DataBuf[Address];
}

/*****************************************************************************
* helper functions
*******************************************************************************/
// backup the current data
void EEPROM_Backup(void)
{
uint32_t begin = FEE_PAGE_BASE_ADDRESS;
uint32_t end = FEE_PAGE_END_ADDRESS;
memset(&DataBuf[0], FEE_EMPTY_BYTE, sizeof(DataBuf));
while( begin < end) {
uint16_t addr = *(__IO uint16_t*)(FEE_ADDR_ADDRESS(begin));
if (IS_VALID_ADDRESS(addr)) {
DataBuf[addr] = *(__IO uint16_t*)(FEE_DATA_ADDRESS(begin));
} else if( addr == FEE_EMPTY_WORD) {
uint16_t data = *(__IO uint16_t*)(FEE_DATA_ADDRESS(begin));
if (data == FEE_EMPTY_WORD) {
// we reached the end of valid data
break;
}
}
begin += 4;
}
}
// restore data from DataBuf
FLASH_Status EEPROM_Restore(void) {
uint32_t cur = FEE_PAGE_BASE_ADDRESS;
for (uint8_t i = 0; i < FEE_MAX_BYTES; i++) {
if (DataBuf[i] != FEE_EMPTY_BYTE) {
FLASH_ProgramHalfWord(FEE_ADDR_ADDRESS(cur), i);
FLASH_ProgramHalfWord(FEE_DATA_ADDRESS(cur), DataBuf[i]);
cur += 4;
}
}
return FLASH_COMPLETE;
}
// find an empty place for programming
uint32_t EEPROM_FindValidAddress(void) {
uint32_t begin = FEE_PAGE_BASE_ADDRESS;
uint32_t end = FEE_PAGE_END_ADDRESS;
while( begin < end) {
uint32_t data = *(__IO uint32_t*)(begin);
if (data == FEE_EMPTY_VALUE) {
return begin;
}
begin += 4;
}
return FEE_EMPTY_VALUE;
}

void EEPROM_Clear(void)
{
#if defined(EEPROM_EMU_STM32F401xC)
FLASH_ErasePage(FEE_SECTOR_ID);
#else
int page_num = 0;

// delete all pages from specified start page to the last page
do {
FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + (page_num * FEE_PAGE_SIZE));
page_num++;
} while (page_num < FEE_DENSITY_PAGES);
#endif
}
/*****************************************************************************
* Wrap library in AVR style functions.
*******************************************************************************/
uint8_t eeprom_read_byte_f4(const uint8_t *Address) {
const uint16_t p = (const uint32_t)Address;
return EEPROM_ReadDataByte(p);
}

void eeprom_write_byte_f4(uint8_t *Address, uint8_t Value) {
uint16_t p = (uint32_t)Address;
EEPROM_WriteDataByte(p, Value);
}


void eeprom_read_block(void *buf, const void *addr, size_t len) {
const uint8_t *p = (const uint8_t *)addr;
uint8_t * dest = (uint8_t *)buf;
while (len--) {
*dest++ = eeprom_read_byte_f4(p++);
}
}

void eeprom_write_block(const void *buf, void *addr, size_t len) {
uint8_t * p = (uint8_t *)addr;
const uint8_t *src = (const uint8_t *)buf;
while (len--) {
eeprom_write_byte_f4(p++, *src++);
}
}


Loading

0 comments on commit 574b709

Please sign in to comment.