2x2 matrix scan works
This commit is contained in:
parent
94435a48ed
commit
17852c1866
15
keyboards/cheapino/cheapino.c
Normal file
15
keyboards/cheapino/cheapino.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "quantum.h"
|
||||
#include QMK_KEYBOARD_H
|
||||
#include "i2c_master.h"
|
||||
|
||||
|
||||
void keyboard_post_init_user(void) {
|
||||
// Customise these values to desired behaviour
|
||||
debug_enable=true;
|
||||
//debug_matrix=true;
|
||||
debug_keyboard=true;
|
||||
//debug_mouse=true;
|
||||
}
|
||||
|
27
keyboards/cheapino/config.h
Normal file
27
keyboards/cheapino/config.h
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Thomas Haukland (@Thomas Haukland)
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config_common.h"
|
||||
|
||||
/*
|
||||
* 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 I2C_DRIVER I2CD2
|
||||
#define I2C1_SCL_PIN GP3
|
||||
#define I2C1_SDA_PIN GP2
|
||||
|
8
keyboards/cheapino/halconf.h
Normal file
8
keyboards/cheapino/halconf.h
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define HAL_USE_PWM TRUE
|
||||
#define HAL_USE_PAL TRUE
|
||||
#define HAL_USE_I2C TRUE
|
||||
|
||||
#include_next <halconf.h>
|
36
keyboards/cheapino/info.json
Normal file
36
keyboards/cheapino/info.json
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"manufacturer": "Thomas Haukland",
|
||||
"keyboard_name": "cheapino",
|
||||
"maintainer": "Thomas Haukland",
|
||||
"bootloader": "rp2040",
|
||||
"diode_direction": "COL2ROW",
|
||||
"features": {
|
||||
"bootmagic": true,
|
||||
"command": false,
|
||||
"console": true,
|
||||
"extrakey": true,
|
||||
"mousekey": true,
|
||||
"nkro": true
|
||||
},
|
||||
"matrix_pins": {
|
||||
"cols": ["GP2", "GP2"],
|
||||
"rows": ["GP1", "GP1"]
|
||||
},
|
||||
"processor": "RP2040",
|
||||
"url": "",
|
||||
"usb": {
|
||||
"device_version": "1.0.0",
|
||||
"pid": "0x0000",
|
||||
"vid": "0xFEED"
|
||||
},
|
||||
"layouts": {
|
||||
"LAYOUT_ortho_2x2": {
|
||||
"layout": [
|
||||
{ "matrix": [0, 0], "x": 0, "y": 0 },
|
||||
{ "matrix": [0, 1], "x": 1, "y": 0 },
|
||||
{ "matrix": [1, 0], "x": 0, "y": 1 },
|
||||
{ "matrix": [1, 1], "x": 1, "y": 1 }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
15
keyboards/cheapino/keymaps/default/keymap.c
Normal file
15
keyboards/cheapino/keymaps/default/keymap.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include QMK_KEYBOARD_H
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
/*
|
||||
* ┌───┬───┬───┐
|
||||
* │ A │ B │ C │
|
||||
* ├───┼───┼───┤
|
||||
* │ D │ E │ F │
|
||||
* └───┴───┴───┘
|
||||
*/
|
||||
[0] = LAYOUT_ortho_2x2(
|
||||
KC_A, KC_B,
|
||||
KC_C, KC_D
|
||||
)
|
||||
};
|
103
keyboards/cheapino/matrix.c
Normal file
103
keyboards/cheapino/matrix.c
Normal file
@ -0,0 +1,103 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "quantum.h"
|
||||
#include QMK_KEYBOARD_H
|
||||
#include "i2c_master.h"
|
||||
#include <print.h>
|
||||
|
||||
|
||||
bool i2c_initialized = 0;
|
||||
i2c_status_t i2c_status;
|
||||
#define LED_COUNT 4
|
||||
const uint8_t leds[LED_COUNT] = {GP7,GP8,GP15,GP14};
|
||||
bool led_status[LED_COUNT] = {true,true,true,true};
|
||||
uint8_t _buf;
|
||||
|
||||
/* matrix state(1:on, 0:off) */
|
||||
//static matrix_row_t matrix[MATRIX_ROWS]; // debounced values
|
||||
|
||||
// The PCF857 addresses are explained on page 9 here:
|
||||
// https://www.ti.com/lit/ds/symlink/pcf8574.pdf
|
||||
// On the Cheapino, A0-A2 are grounded for a 0 value
|
||||
// In arduino, PCF857 address is 0x20, but thats without
|
||||
// the read/write bit at the end, so including that(unset)
|
||||
// the address is here 0x20 << 1 = 0b01000000
|
||||
//uint16_t i2c_timeout = 1250;
|
||||
#define I2C_ADDR 0b01000000
|
||||
#define I2C_ADDR_WRITE 0b01000000
|
||||
#define I2C_ADDR_READ 0b01000001
|
||||
//#define I2C_TIMEOUT 1000
|
||||
|
||||
void toggle_leds(void) {
|
||||
for (int i = 0; i < LED_COUNT; i++)
|
||||
{
|
||||
writePin(leds[i], led_status[i] ? 1 : 0);
|
||||
}
|
||||
}
|
||||
void matrix_init_custom(void) {
|
||||
//setPinOutput(GP6);
|
||||
//writePinHigh(GP6);
|
||||
printf("Init Cheapino!\n");
|
||||
|
||||
if (i2c_initialized == 0) {
|
||||
i2c_init();
|
||||
i2c_initialized = true;
|
||||
wait_ms(I2C_TIMEOUT);
|
||||
}
|
||||
for (int i=0; i<LED_COUNT; i++)
|
||||
{
|
||||
setPinOutput(leds[i]);
|
||||
}
|
||||
toggle_leds();
|
||||
wait_ms(500);
|
||||
for (int i=0; i<LED_COUNT; i++)
|
||||
{
|
||||
led_status[i] = false;
|
||||
toggle_leds();
|
||||
wait_ms(400);
|
||||
}
|
||||
matrix_init_user();
|
||||
}
|
||||
|
||||
|
||||
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
|
||||
bool changed = false;
|
||||
printf("Scan Cheapino!");
|
||||
|
||||
//i2c_status = i2c_start(I2C_ADDR_WRITE);
|
||||
//led_status[0] = i2c_status == I2C_STATUS_SUCCESS;
|
||||
// Set col0 pin high
|
||||
_buf = 0b11111110;
|
||||
uint8_t buf[] = {0b11111110};
|
||||
i2c_status = i2c_transmit(I2C_ADDR_WRITE, buf, sizeof(buf), 200);
|
||||
//led_status[0] = i2c_status == I2C_STATUS_SUCCESS;
|
||||
//i2c_stop();
|
||||
toggle_leds();
|
||||
// Read if row 0 or row 1 are high
|
||||
//i2c_status = i2c_start(I2C_ADDR_READ, I2C_TIMEOUT);
|
||||
i2c_status = i2c_receive(I2C_ADDR_READ, &_buf, 1, I2C_TIMEOUT);
|
||||
//toggle_leds();
|
||||
//led_status[1] = i2c_status == I2C_STATUS_SUCCESS;
|
||||
led_status[0] = ! (_buf & 0b00000010);
|
||||
led_status[1] = ! (_buf & 0b00001000);
|
||||
|
||||
// Set col1 pin high
|
||||
_buf = 0b11111011;
|
||||
i2c_status = i2c_transmit(I2C_ADDR_WRITE, &_buf, 1, I2C_TIMEOUT);
|
||||
//led_status[2] = i2c_status == I2C_STATUS_SUCCESS;
|
||||
//toggle_leds();
|
||||
// Read if row 0 or row 1 are high
|
||||
i2c_status = i2c_receive(I2C_ADDR_READ, &_buf, 1, I2C_TIMEOUT);
|
||||
//led_status[3] = i2c_status == I2C_STATUS_SUCCESS;
|
||||
//i2c_stop();
|
||||
led_status[2] = ! (_buf & 0b00000010);
|
||||
led_status[3] = ! (_buf & 0b00001000);
|
||||
|
||||
// update leds
|
||||
toggle_leds();
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
|
6
keyboards/cheapino/mcuconf.h
Normal file
6
keyboards/cheapino/mcuconf.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include_next <mcuconf.h>
|
||||
|
||||
#undef RP_I2C_USE_I2C1
|
||||
#define RP_I2C_USE_I2C1 TRUE
|
27
keyboards/cheapino/readme.md
Normal file
27
keyboards/cheapino/readme.md
Normal file
@ -0,0 +1,27 @@
|
||||
# cheapino
|
||||
|
||||

|
||||
|
||||
*A short description of the keyboard/project*
|
||||
|
||||
* Keyboard Maintainer: [Thomas Haukland](https://github.com/Thomas Haukland)
|
||||
* Hardware Supported: *The PCBs, controllers supported*
|
||||
* Hardware Availability: *Links to where you can find this hardware*
|
||||
|
||||
Make example for this keyboard (after setting up your build environment):
|
||||
|
||||
make cheapino:default
|
||||
|
||||
Flashing example for this keyboard:
|
||||
|
||||
make cheapino:default:flash
|
||||
|
||||
See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
|
||||
|
||||
## Bootloader
|
||||
|
||||
Enter the bootloader in 3 ways:
|
||||
|
||||
* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard
|
||||
* **Physical reset button**: Briefly press the button on the back of the PCB - some may have pads you must short instead
|
||||
* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available
|
4
keyboards/cheapino/rules.mk
Normal file
4
keyboards/cheapino/rules.mk
Normal file
@ -0,0 +1,4 @@
|
||||
# This file intentionally left blank
|
||||
CUSTOM_MATRIX = lite
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
SRC += matrix.c
|
Loading…
x
Reference in New Issue
Block a user