Skip to content

Commit 441240a

Browse files
committed
Merge branch 'MatrixRevC'
2 parents 7214b49 + ac676df commit 441240a

27 files changed

Lines changed: 458 additions & 485 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Applications that run on Matrix OS. All user interactions are Matrix OS applicat
2929
Compile and Upload for Matrix Pro:
3030
Set Matrix Pro into bootloader mode (Hold the FN key while powering up or going though system settings) and the following
3131
```
32-
make DEVICE=MatrixPro build uf2-upload
32+
make DEVICE=Matrix build uf2-upload
3333
```
3434
TODO
3535
### Make your own Matrix OS applications

applications/BootAnimations/MatrixBoot/MatrixBoot.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,15 @@ void MatrixBoot::BootPhase2QuadSetColor(uint8_t x_offset, uint8_t y_offset, Colo
188188
}
189189

190190
void MatrixBoot::BootPhase2() {
191-
const uint8_t hue[2] = {127, 212};
191+
uint8_t hue[2] = {127, 212};
192+
193+
#if FAMILY == MATRIX
194+
if(Device::deviceInfo.Model[3] == 'S')
195+
{ hue[1] = 43; }
196+
else if(Device::deviceInfo.Model[3] == 'P')
197+
{ hue[1] = 212; }
198+
#endif
199+
192200
const uint16_t start_offset = 150;
193201
if (timer.Tick(10))
194202
{

applications/Matrix/FactoryMenu/EFuseBurner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ void BurnEFuse(); // This is in device folder, a custom BurnEFuse will be provi
44

55
void FactoryMenu::EFuseBurner() {
66
#ifdef EFUSE_BURNER
7-
if (esp_efuse_block_is_empty(EFUSE_BLK3))
7+
if (true)
88
{
99
UI efuseConfirm("eFuse Burn Confirmation", Color(0xFFFFFF));
1010

1111
UIButtonLarge confirmBtn("Confirm", Color(0x00FF00), Dimension(2, 2), [&]() -> void {
1212
BurnEFuse();
13-
Exit();
13+
efuseConfirm.Exit();
1414
});
1515
efuseConfirm.AddUIComponent(confirmBtn, Point(1, 5));
1616

17-
UIButtonLarge cancelBtn("Cancel", Color(0xFF0000), Dimension(2, 2), [&]() -> void { Exit(); });
17+
UIButtonLarge cancelBtn("Cancel", Color(0xFF0000), Dimension(2, 2), [&]() -> void { efuseConfirm.Exit(); });
1818
efuseConfirm.AddUIComponent(cancelBtn, Point(5, 5));
1919

2020
efuseConfirm.Start();

applications/Matrix/FactoryMenu/FactoryMenu.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ void FactoryMenu::Setup() {
2727
[&]() -> void {});
2828
factoryMenu.AddUIComponent(usbConnection, Point(7, 7));
2929

30+
Color deviceColor = Color(0xFFFFFF);
31+
if(Device::deviceInfo.Model[3] == 'S')
32+
{
33+
deviceColor = Color(0x00FFFF);
34+
}
35+
else if(Device::deviceInfo.Model[3] == 'P')
36+
{
37+
deviceColor = Color(0xFF00FF);
38+
}
39+
40+
UIButtonLarge deviceVersionBtn("Device Version", deviceColor, Dimension(4, 1), [&]() -> void {});
41+
factoryMenu.AddUIComponent(deviceVersionBtn, Point(2, 7));
42+
3043
factoryMenu.Start();
3144
Exit();
3245
}

devices/MatrixBlock6_ESP32S3/Varients/MatrixPro/V100/EFuse.cpp renamed to devices/MatrixBlock6_ESP32S3/Drivers/EFuse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Device.h"
22

3-
#if FACTORY_CONFIG == V100
3+
#ifdef FACTORY_CONFIG
44
#include "esp_efuse.h"
55
#include "esp_efuse_table.h"
66
void BurnEFuse() {

devices/MatrixBlock6_ESP32S3/Drivers/Keypad.cpp

Lines changed: 44 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,20 @@
22
#include "Device.h"
33
#include "timers.h"
44

5-
#include "ulp_riscv.h"
6-
#include "ulp_keypad.h"
7-
8-
#include "esp_private/esp_sleep_internal.h"
9-
#include "esp_private/adc_share_hw_ctrl.h"
10-
11-
#define VELOCITY_SENSITIVE_KEYPAD_ADC_ATTEN ADC_ATTEN_DB_0
12-
#define VELOCITY_SENSITIVE_KEYPAD_ADC_WIDTH ADC_BITWIDTH_12
13-
14-
extern const uint8_t ulp_keypad_bin_start[] asm("_binary_ulp_keypad_bin_start");
15-
extern const uint8_t ulp_keypad_bin_end[] asm("_binary_ulp_keypad_bin_end");
16-
175
namespace Device::KeyPad
186
{
19-
adc_oneshot_unit_handle_t adc_handle;
207
StaticTimer_t keypad_timer_def;
218
TimerHandle_t keypad_timer;
229

2310
void Init() {
2411
LoadCustomSettings();
12+
InitFN();
2513
InitKeyPad();
2614
InitTouchBar();
2715
}
2816

29-
void Scan() {
30-
if (ScanFN())
31-
return;
32-
if (ScanKeyPad())
33-
return;
34-
}
35-
36-
void InitKeyPad() {
17+
// TODO Change to use interrupt
18+
void InitFN() {
3719
gpio_config_t io_conf;
3820

3921
// Config FN
@@ -51,66 +33,30 @@ namespace Device::KeyPad
5133
#endif
5234
gpio_config(&io_conf);
5335

54-
// Config Input Pins
55-
if (!keypad_config.velocity_sensitive) // Non velocity sensitive keypad
56-
{
57-
io_conf.intr_type = GPIO_INTR_DISABLE;
58-
io_conf.mode = GPIO_MODE_INPUT;
59-
io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
60-
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
61-
io_conf.pin_bit_mask = 0;
62-
for (uint8_t y = 0; y < y_size; y++)
63-
{ io_conf.pin_bit_mask |= (1ULL << keypad_read_pins[y]); }
64-
gpio_config(&io_conf);
65-
}
66-
else // Velocity sensitive keypad
67-
{
68-
adc_oneshot_unit_init_cfg_t init_config = {
69-
.unit_id = ADC_UNIT_1,
70-
.ulp_mode = ADC_ULP_MODE_RISCV,
71-
};
72-
adc_oneshot_new_unit(&init_config, &adc_handle);
73-
74-
adc_oneshot_chan_cfg_t adc_config = {
75-
.atten = VELOCITY_SENSITIVE_KEYPAD_ADC_ATTEN,
76-
.bitwidth = VELOCITY_SENSITIVE_KEYPAD_ADC_WIDTH,
77-
};
78-
79-
for (uint8_t y = 0; y < y_size; y++)
80-
{ adc_oneshot_config_channel(adc_handle, keypad_read_adc_channel[y], &adc_config); }
81-
}
82-
83-
// Config Output Pins
84-
io_conf.intr_type = GPIO_INTR_DISABLE;
85-
io_conf.mode = GPIO_MODE_OUTPUT;
86-
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
87-
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
88-
io_conf.pin_bit_mask = 0;
89-
for (uint8_t x = 0; x < x_size; x++)
90-
{ io_conf.pin_bit_mask |= (1ULL << keypad_write_pins[x]); }
91-
gpio_config(&io_conf);
92-
93-
// Calibrate the ADC
94-
adc_set_hw_calibration_code(ADC_UNIT_1, VELOCITY_SENSITIVE_KEYPAD_ADC_ATTEN);
95-
96-
// Enables the use of ADC and temperature sensor in monitor (ULP) mode
97-
esp_sleep_enable_adc_tsens_monitor(true);
98-
9936
// Set up Matrix OS key config
10037
fnState.setConfig(&fn_config);
38+
}
10139

102-
for (uint8_t x = 0; x < x_size; x++)
103-
{
104-
for (uint8_t y = 0; y < y_size; y++)
105-
{ keypadState[x][y].setConfig(&keypad_config); }
106-
}
40+
void InitKeyPad() {
41+
if (!velocity_sensitivity)
42+
{ Binary::Init(); }
43+
else
44+
{ FSR::Init(); }
10745
}
10846

10947
void StartKeyPad() {
110-
ulp_riscv_load_binary(ulp_keypad_bin_start, (ulp_keypad_bin_end - ulp_keypad_bin_start));
111-
ulp_riscv_run();
48+
if (!velocity_sensitivity)
49+
{
50+
Binary::Start();
51+
}
52+
else
53+
{
54+
FSR::Start();
55+
}
11256

11357
keypad_timer = xTimerCreateStatic(NULL, configTICK_RATE_HZ / Device::keypad_scanrate, true, NULL, reinterpret_cast<TimerCallbackFunction_t>(Scan), &keypad_timer_def);
58+
59+
11460
xTimerStart(keypad_timer, 0);
11561
}
11662

@@ -119,6 +65,31 @@ namespace Device::KeyPad
11965
StartTouchBar();
12066
}
12167

68+
void Scan() {
69+
ScanFN();
70+
ScanKeyPad();
71+
}
72+
73+
bool ScanKeyPad() {
74+
if (!velocity_sensitivity)
75+
{ return Binary::Scan(); }
76+
else
77+
{ return FSR::Scan(); }
78+
}
79+
80+
bool ScanFN() {
81+
Fract16 read = gpio_get_level(fn_pin) * UINT16_MAX;
82+
// ESP_LOGI("FN", "%d", gpio_get_level(fn_pin));
83+
if (fn_active_low)
84+
{ read = UINT16_MAX - (uint16_t)read; }
85+
if (fnState.update(read, false))
86+
{
87+
if (NotifyOS(0, &fnState))
88+
{ return true; }
89+
}
90+
return false;
91+
}
92+
12293
void Clear() {
12394
fnState.Clear();
12495

@@ -165,86 +136,6 @@ namespace Device::KeyPad
165136
}
166137
return nullptr; // Return an empty KeyInfo
167138
}
168-
169-
bool ScanFN() {
170-
Fract16 read = gpio_get_level(fn_pin) * UINT16_MAX;
171-
// ESP_LOGI("FN", "%d", gpio_get_level(fn_pin));
172-
if (fn_active_low)
173-
{ read = UINT16_MAX - (uint16_t)read; }
174-
if (fnState.update(read, false))
175-
{
176-
if (NotifyOS(0, &fnState))
177-
{ return true; }
178-
}
179-
return false;
180-
}
181-
182-
uint16_t middleOfThree(uint16_t a, uint16_t b, uint16_t c)
183-
{
184-
// Checking for a
185-
if ((b <= a && a <= c) || (c <= a && a <= b))
186-
return a;
187-
188-
// Checking for b
189-
if ((a <= b && b <= c) || (c <= b && b <= a))
190-
return b;
191-
192-
return c;
193-
}
194-
195-
uint16_t minOfThree(uint16_t a, uint16_t b, uint16_t c)
196-
{
197-
// Checking for a
198-
if (a < b && a < c)
199-
return a;
200-
201-
// Checking for b
202-
if (b < a && b < c)
203-
return b;
204-
205-
return c;
206-
}
207-
208-
bool ScanKeyPad()
209-
{
210-
// ESP_LOGI("Keypad ULP", "Scaned: %lu", ulp_count);
211-
uint16_t (*result)[8][3] = (uint16_t(*)[8][3])&ulp_result;
212-
for(uint8_t y = 0; y < Device::y_size; y ++)
213-
{
214-
for(uint8_t x = 0; x < Device::x_size; x++)
215-
{
216-
// printf("%d,", result[x][y][0]);
217-
uint16_t reading = 0;
218-
if(result[x][y][0] != 0 && result[x][y][1] != 0 && result[x][y][2] != 0)
219-
{
220-
reading = middleOfThree(result[x][y][0], result[x][y][1], result[x][y][2]);
221-
}
222-
// uint16_t reading = resxult[x][y][0] + result[x][y][1] + result[x][y][2] + result[x][y][ulp_latest];
223-
Fract16 read = (reading << 4) + (reading >> 8); // Raw Voltage mapped. Will add calibration curve later.
224-
bool updated = keypadState[x][y].update(read, true);
225-
// if(keypadState[x][y].state == DEBUNCING)
226-
// {
227-
// printf("Key %d %d Debuncing - %d - [%d, %d, %d]\n", x, y, (uint16_t)read, result[x][y][ulp_latest], result[x][y][(ulp_latest + 1) % 3], result[x][y][(ulp_latest + 2) % 3]);
228-
// }
229-
// else if(keypadState[x][y].state == PRESSED)
230-
// {
231-
// printf("Key %d %d Pressed - %d - [%d, %d, %d]\n", x, y, (uint16_t)read, result[x][y][ulp_latest], result[x][y][(ulp_latest + 1) % 3], result[x][y][(ulp_latest + 2) % 3]);
232-
// }
233-
if (updated)
234-
{
235-
uint16_t keyID = (1 << 12) + (x << 6) + y;
236-
if (NotifyOS(keyID, &keypadState[x][y]))
237-
{
238-
// printf("\n");
239-
return true;
240-
}
241-
}
242-
}
243-
}
244-
// printf("\n");
245-
return false;
246-
}
247-
248139
bool NotifyOS(uint16_t keyID, KeyInfo* keyInfo) {
249140
KeyEvent keyEvent;
250141
keyEvent.id = keyID;

0 commit comments

Comments
 (0)