-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add schematic pdfs and firmware code
- Loading branch information
Showing
35 changed files
with
24,620 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Arduino 1.8.13 | ||
|
||
http://dan.drown.org/stm32duino/package_STM32duino_index.json | ||
|
||
STM32F1xx/GD32F1xx boards | ||
by stm32duino version 2021.2.22 | ||
|
||
GENERIC STM32F103R series | ||
|
||
gd32f1_generic_boot20_pc13.bin | ||
generic_boot20_pc13.bin | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef DEVTERM_H | ||
#define DEVTERM_H | ||
|
||
|
||
#include <USBComposite.h> | ||
|
||
typedef struct keyboard_state{ | ||
|
||
uint8_t layer; | ||
uint8_t shift; | ||
uint8_t caps_lock; | ||
|
||
}KEYBOARD_STATE; | ||
|
||
class DEVTERM { | ||
public: | ||
HIDKeyboard *Keyboard; | ||
HIDMouse *Mouse; | ||
HIDJoystick *Joystick; | ||
KEYBOARD_STATE Keyboard_state; | ||
USBCompositeSerial *_Serial; | ||
//if not to use USBCompositeSerial,then use default Serial | ||
//**Serial and USBCompositeSerial can not use together, otherwise the keyboard firmware uploading will be dead** | ||
//and you will need to find a way out to flash the stm32duino bootloader once again | ||
//USBSerial *_Serial;//_Serial = &Serial; | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "keyboard.h" | ||
#include "keys.h" | ||
#include "trackball.h" | ||
#include "devterm.h" | ||
|
||
#include <USBComposite.h> | ||
|
||
#define SER_NUM_STR "20210320" | ||
|
||
USBHID HID; | ||
DEVTERM dev_term; | ||
|
||
void setup() { | ||
USBComposite.setManufacturerString("ClockworkPI"); | ||
USBComposite.setProductString("DevTerm"); | ||
USBComposite.setSerialString(SER_NUM_STR); | ||
|
||
dev_term.Keyboard = new HIDKeyboard(HID); | ||
dev_term.Joystick = new HIDJoystick(HID); | ||
dev_term.Mouse = new HIDMouse(HID); | ||
|
||
dev_term.Keyboard_state.shift = 0; | ||
dev_term.Keyboard_state.layer = 0; | ||
dev_term.Keyboard_state.caps_lock = 0; | ||
|
||
dev_term._Serial = new USBCompositeSerial; | ||
|
||
HID.begin(*dev_term._Serial,HID_KEYBOARD_MOUSE_JOYSTICK); | ||
|
||
while(!USBComposite);//wait until usb port been plugged in to PC | ||
|
||
|
||
keyboard_init(&dev_term); | ||
keys_init(&dev_term); | ||
trackball_init(&dev_term); | ||
|
||
dev_term._Serial->println("setup done"); | ||
|
||
//delay(3000); | ||
} | ||
|
||
void loop() { | ||
|
||
trackball_task(&dev_term); | ||
keys_task(&dev_term); //keys above keyboard | ||
keyboard_task(&dev_term); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* | ||
*/ | ||
#ifndef HELPER_H | ||
#define HELPER_H | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
|
||
uint8_t read_io(uint8_t io); | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "helper.h" | ||
|
||
|
||
uint8_t read_io(uint8_t io) { | ||
|
||
if(digitalRead(io) == LOW ){ | ||
return 0; | ||
}else { | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef KEYBOARD_H | ||
#define KEYBOARD_H | ||
|
||
/* | ||
* clockworkpi devterm keyboard test2 | ||
* able to correct scan the 8x8 keypads re-action | ||
*/ | ||
|
||
#include "devterm.h" | ||
|
||
#include "keys_io_map.h" | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
#define MATRIX_ROWS 8 | ||
#define MATRIX_COLS 8 | ||
|
||
#ifndef DEBOUNCE | ||
# define DEBOUNCE 5 | ||
#endif | ||
|
||
void init_rows(); | ||
void init_cols(); | ||
uint8_t read_io(uint8_t io); | ||
|
||
void matrix_init(); | ||
uint8_t matrix_scan(void); | ||
|
||
bool matrix_is_on(uint8_t row, uint8_t col); | ||
uint8_t matrix_get_row(uint8_t row) ; | ||
|
||
|
||
//void matrix_print(void); | ||
|
||
|
||
|
||
void keyboard_task(DEVTERM*); | ||
void keyboard_init(DEVTERM*); | ||
|
||
|
||
#define KEY_PRESSED 1 | ||
#define KEY_RELEASED 0 | ||
|
||
#define KEY_PRNT_SCRN 0xCE //Print screen | ||
#define KEY_PAUSE 0xd0 | ||
|
||
#define KEY_VOLUME_UP 0x108 | ||
#define KEY_VOLUME_DOWN 0x109 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
#include "keyboard.h" | ||
#include "helper.h" | ||
|
||
|
||
static bool debouncing = false; | ||
static uint16_t debouncing_time = 0; | ||
|
||
uint8_t matrix_rows[ MATRIX_ROWS ]= {ROW1,ROW2,ROW3,ROW4,ROW5,ROW6,ROW7,ROW8}; | ||
uint8_t matrix_cols[ MATRIX_COLS ] = {COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8}; | ||
|
||
/* matrix state(1:on, 0:off) */ | ||
static uint8_t matrix[MATRIX_ROWS]; | ||
static uint8_t matrix_debouncing[MATRIX_COLS]; | ||
static uint8_t matrix_prev[MATRIX_ROWS]; | ||
|
||
static int8_t jack_idx=-1; | ||
static uint16_t jack_time = 0; | ||
|
||
|
||
|
||
void init_rows(){ | ||
int i; | ||
for(i=0;i<8;i++) { | ||
pinMode(matrix_rows[i],OUTPUT); | ||
digitalWrite(matrix_rows[i],LOW); | ||
|
||
pinMode(matrix_rows[i],INPUT_PULLDOWN); | ||
} | ||
} | ||
|
||
void init_cols() { | ||
|
||
int i; | ||
for(i=0;i<8;i++){ | ||
pinMode(matrix_cols[i],OUTPUT); | ||
digitalWrite(matrix_cols[i],LOW); | ||
} | ||
} | ||
|
||
|
||
|
||
void matrix_init() { | ||
init_cols(); | ||
init_rows(); | ||
|
||
for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
matrix[i] = 0; | ||
matrix_debouncing[i] = 0; | ||
matrix_prev[i] = 0; | ||
} | ||
|
||
delay(500); | ||
} | ||
|
||
uint8_t matrix_scan(void) { | ||
|
||
uint8_t data; | ||
for(int col = 0; col < MATRIX_COLS;col++){ | ||
data = 0; | ||
digitalWrite(matrix_cols[col],HIGH); | ||
|
||
|
||
delayMicroseconds(20); | ||
|
||
data =( | ||
( read_io(matrix_rows[0]) << 0 ) | | ||
( read_io(matrix_rows[1]) << 1 ) | | ||
( read_io(matrix_rows[2]) << 2 ) | | ||
( read_io(matrix_rows[3]) << 3 ) | | ||
( read_io(matrix_rows[4]) << 4 ) | | ||
( read_io(matrix_rows[5]) << 5 ) | | ||
( read_io(matrix_rows[6]) << 6 ) | | ||
( read_io(matrix_rows[7]) << 7 ) | ||
); | ||
|
||
digitalWrite(matrix_cols[col],LOW); | ||
if (matrix_debouncing[col] != data) { | ||
matrix_debouncing[col] = data; | ||
debouncing = true; | ||
debouncing_time = millis(); | ||
} | ||
} | ||
|
||
if (debouncing == true && ( (millis() - debouncing_time) > DEBOUNCE )) { | ||
for (int row = 0; row < MATRIX_ROWS; row++) { | ||
matrix[row] = 0; | ||
for (int col = 0; col < MATRIX_COLS; col++) { | ||
matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col); | ||
|
||
} | ||
} | ||
debouncing = false; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
|
||
bool matrix_is_on(uint8_t row, uint8_t col) { | ||
return (matrix[row] & (1<<col)); | ||
} | ||
|
||
|
||
|
||
uint8_t matrix_get_row(uint8_t row) { | ||
return matrix[row]; | ||
} | ||
|
||
|
||
void matrix_press(DEVTERM*dv,uint8_t row,uint8_t col) { | ||
char buff[128]; | ||
|
||
if(matrix_is_on(row,col) == true ){ | ||
sprintf(buff,"%d %d M%d pressed\n",row,col,(row+1)*10+col+1); | ||
dv->_Serial->print(buff); | ||
keyboard_action(dv,row,col,KEY_PRESSED); | ||
} | ||
|
||
} | ||
|
||
void matrix_release(DEVTERM*dv,uint8_t row,uint8_t col) { | ||
char buff[128]; | ||
|
||
|
||
if(matrix_is_on(row,col) == false ){ | ||
sprintf(buff,"%d %d M%d released\n",row,col,(row+1)*10+col+1); | ||
dv->_Serial->print(buff); | ||
keyboard_action(dv,row,col,KEY_RELEASED); | ||
|
||
} | ||
|
||
} | ||
|
||
void keyboard_task(DEVTERM*dv) | ||
{ | ||
|
||
uint8_t matrix_row = 0; | ||
uint8_t matrix_change = 0; | ||
|
||
matrix_scan(); | ||
for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | ||
matrix_row = matrix_get_row(r); | ||
|
||
uint8_t col_mask =1; | ||
for(uint8_t c=0;c < MATRIX_COLS;c++,col_mask <<=1){ | ||
|
||
if( ( (matrix_prev[r] & col_mask) == 0) && ( (matrix_row & col_mask) > 0) ) { | ||
matrix_press(dv,r,c); | ||
} | ||
|
||
if( ( (matrix_prev[r] & col_mask) > 0) && ( (matrix_row & col_mask) == 0) ) { | ||
|
||
matrix_release(dv,r,c); | ||
} | ||
|
||
if( ( (matrix_prev[r] & col_mask) > 0) && ( (matrix_row & col_mask) > 0) ) {//same key | ||
|
||
|
||
if( jack_idx == -1){ | ||
jack_idx = r*MATRIX_ROWS+c; | ||
}else{ | ||
|
||
if(jack_idx != r*MATRIX_ROWS+c) { | ||
jack_time = 0; | ||
jack_idx = r*MATRIX_ROWS+c; | ||
}else{ | ||
jack_time +=1; | ||
if( jack_time % (DEBOUNCE*20) == 0){ | ||
if(jack_idx > 1){//skip select,start button | ||
matrix_press(dv,r,c); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
matrix_prev[r] = matrix_row; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
void keyboard_init(DEVTERM*){ | ||
matrix_init(); | ||
|
||
} |
Oops, something went wrong.