Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev branch #3

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5cb9777
Initial commit of my custom hardware and keymap configuration of a \h…
philliphall Apr 10, 2023
fac9bdf
Added keymap visual jpg.
philliphall Apr 10, 2023
0134b8e
Merge branch 'qmk:master' into master
philliphall Apr 10, 2023
255704f
Create keymap.c
philliphall Apr 11, 2023
dd08ba5
Merge branch 'master' of https://github.com/philliphall/qmk_firmware
philliphall Apr 11, 2023
7ac330a
Got OLED working as intended in latest keymap.
philliphall Apr 12, 2023
5c299bf
Merge branch 'qmk:master' into master
philliphall May 2, 2023
c341903
Removed unused keyboards
philliphall May 19, 2023
b45a14d
Keymap Updates
philliphall May 19, 2023
196cccd
Added update feature to json2c
philliphall May 19, 2023
aaf2c3a
Merge branch 'qmk:master' into master
philliphall May 19, 2023
3372dc4
Merge branch 'master' of https://github.com/philliphall/qmk_firmware
philliphall May 19, 2023
e23af3d
Revert "Removed unused keyboards"
philliphall May 19, 2023
36a1723
Added comments to json2c
philliphall May 19, 2023
93afc17
Initial (broken) phil-rev2 firmware
philliphall Sep 21, 2023
4373cf7
Merge branch 'master' into dev_branch
philliphall Sep 25, 2023
4a28969
Merge branch 'qmk:master' into dev_branch
philliphall Sep 25, 2023
f24639e
Testing, not yet working updates to dynamic macros and OLED
philliphall Sep 25, 2023
d53d2c5
Finished updates to dynamic macros and OLED - working product :-)
philliphall Sep 25, 2023
626b52b
Merge branch 'qmk:master' into dev_branch
philliphall Oct 14, 2023
fb0efc9
Left encoder now functions as backspace and alt-tab
philliphall Oct 14, 2023
72c2c9d
Merge branch 'dev_branch' of https://github.com/philliphall/qmk_firmw…
philliphall Oct 14, 2023
500b529
Relocated home for my custom boards
philliphall Oct 15, 2023
2a4e8c3
Minor keymap tweak
philliphall Oct 15, 2023
55aa10d
Blackpill version - not yet working
philliphall Oct 19, 2023
5589563
modified: keyboards/handwired/dactyl_manuform/phil_rev2_blackpill/…
philliphall Oct 22, 2023
4a6ddd9
just getting current through my debugging
philliphall Oct 22, 2023
3b1d6b3
just an incremental update through my troubleshooting.
philliphall Oct 23, 2023
f4b053e
Split pmw3389 drivers from 3360 and updated init
philliphall Oct 24, 2023
5184935
quick sync of enviornments
philliphall Oct 29, 2023
a419f20
Merge branch 'qmk:master' into dev_branch
philliphall Nov 19, 2023
5a08e5e
3389 testing (#2)
philliphall Nov 19, 2023
cbaaadb
Merge branch 'dev_branch' of https://github.com/philliphall/qmk_firmw…
philliphall Nov 17, 2023
1b6fc07
Mom Lighting Enabled
philliphall Nov 24, 2023
553e07a
minor tweaks
philliphall Nov 24, 2023
02d10b9
VIrtualized EEPROM storage of custom settings!
philliphall Nov 27, 2023
8cbd0ce
Minor update
philliphall Nov 27, 2023
5fd253a
Turned off AutoMouse
philliphall May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"xstddef": "c",
"type_traits": "c",
"utility": "c",
"ranges": "c"
"ranges": "c",
"chrono": "c",
"cmath": "c"
},
"[markdown]": {
"editor.trimAutoWhitespace": false,
Expand Down
8 changes: 6 additions & 2 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ ifeq ($(strip $(POINTING_DEVICE_ENABLE)), yes)
else ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pimoroni_trackball)
OPT_DEFS += -DSTM32_SPI -DHAL_USE_I2C=TRUE
QUANTUM_LIB_SRC += i2c_master.c
else ifneq ($(filter $(strip $(POINTING_DEVICE_DRIVER)),pmw3360 pmw3389),)
else ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pmw3360)
OPT_DEFS += -DSTM32_SPI -DHAL_USE_SPI=TRUE
SRC += drivers/sensors/pmw33xx_common.c
SRC += drivers/sensors/pmw3360_common.c
QUANTUM_LIB_SRC += spi_master.c
else ifeq ($(strip $(POINTING_DEVICE_DRIVER)), pmw3389)
OPT_DEFS += -DSTM32_SPI -DHAL_USE_SPI=TRUE
SRC += drivers/sensors/pmw3389.c
QUANTUM_LIB_SRC += spi_master.c
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion drivers/sensors/pmw3360.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright 2020 Ploopy Corporation
// SPDX-License-Identifier: GPL-2.0-or-later

#include "pmw33xx_common.h"
#include "pmw3360_common.h"
#include "progmem.h"

uint16_t pmw33xx_get_cpi(uint8_t sensor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include "pointing_device_internal.h"
#include "pmw33xx_common.h"
#include "pmw3360_common.h"
#include "string.h"
#include "wait.h"
#include "spi_master.h"
Expand Down
File renamed without changes.
233 changes: 232 additions & 1 deletion drivers/sensors/pmw3389.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,249 @@
// Copyright 2022 Pablo Martinez (@elpekenin)
// Copyright 2022 Daniel Kao (dkao)
// Copyright 2022 Stefan Kerkmann (KarlK90)
// Copyright 2022 Ulrich Spörlein (@uqs)
// Copyright 2021 Alabastard (@Alabastard-64)
// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <[email protected]>
// Copyright 2019 Sunjun Kim
// Copyright 2020 Ploopy Corporation
// SPDX-License-Identifier: GPL-2.0-or-later

#include "pmw33xx_common.h"
#include "pmw3389.h"
#include "progmem.h"
#include "pointing_device_internal.h"
#include "string.h"
#include "wait.h"
#include "spi_master.h"

extern const uint8_t pmw33xx_firmware_data[PMW33XX_FIRMWARE_LENGTH] PROGMEM;
extern const uint8_t pmw33xx_firmware_signature[3] PROGMEM;

static const pin_t cs_pins_left[] = PMW33XX_CS_PINS;
static const pin_t cs_pins_right[] = PMW33XX_CS_PINS_RIGHT;

static bool in_burst_left[ARRAY_SIZE(cs_pins_left)] = {0};
static bool in_burst_right[ARRAY_SIZE(cs_pins_right)] = {0};

bool __attribute__((cold)) pmw33xx_upload_firmware(uint8_t sensor);
bool __attribute__((cold)) pmw33xx_check_signature(uint8_t sensor);

void pmw33xx_set_cpi_all_sensors(uint16_t cpi) {
for (uint8_t sensor = 0; sensor < pmw33xx_number_of_sensors; sensor++) {
pmw33xx_set_cpi(sensor, cpi);
}
}

bool pmw33xx_spi_start(uint8_t sensor) {
if (!spi_start(cs_pins[sensor], false, 3, PMW33XX_SPI_DIVISOR)) {
spi_stop();
return false;
}
// tNCS-SCLK, 10ns
wait_us(1);
return true;
}

bool pmw33xx_write(uint8_t sensor, uint8_t reg_addr, uint8_t data) {
if (!pmw33xx_spi_start(sensor)) {
pd_dprintf("Failed to start SPI for pmw33xx_write function - register %2x.\n", reg_addr);
return false;
}

if (reg_addr != REG_Motion_Burst) {
in_burst[sensor] = false;
}

// send address of the register, with MSBit = 1 to indicate it's a write
uint8_t command[2] = {reg_addr | 0x80, data};
if (spi_transmit(command, sizeof(command)) != SPI_STATUS_SUCCESS) {
return false;
}

// tSCLK-NCS for write operation is 35us
wait_us(35);
spi_stop();

// tSWW/tSWR (=18us) minus tSCLK-NCS. Could be shortened, but it looks like
// a safe lower bound
wait_us(145);
return true;
}

uint8_t pmw33xx_read(uint8_t sensor, uint8_t reg_addr) {
if (!pmw33xx_spi_start(sensor)) {
pd_dprintf("Failed to start SPI for pmw33xx_read function - register %2x.\n", reg_addr);
return 0;
}

// send adress of the register, with MSBit = 0 to indicate it's a read
spi_write(reg_addr & 0x7f);
// tSRAD (=160us)
wait_us(160);
uint8_t data = spi_read();
//pd_dprintf("Read from register %2x the following data: %2x\n", reg_addr, data);

// tSCLK-NCS, 120ns
wait_us(1);
spi_stop();

// tSRW/tSRR (=20us) mins tSCLK-NCS
wait_us(19);
return data;
}

bool pmw33xx_check_signature(uint8_t sensor) {
uint8_t signature_dump[3] = {
pmw33xx_read(sensor, REG_Product_ID),
pmw33xx_read(sensor, REG_Inverse_Product_ID),
pmw33xx_read(sensor, REG_SROM_ID),
};

pd_dprintf("Signature: Product_ID %x, Inverse_Product_ID %x, SROM_ID %x\n", signature_dump[0], signature_dump[1], signature_dump[2]);

return memcmp(pmw33xx_firmware_signature, signature_dump, sizeof(signature_dump)) == 0;
}

bool pmw33xx_upload_firmware(uint8_t sensor) {
// Datasheet claims we need to disable REST mode first, but during startup
// it's already disabled and we're not turning it on ...
// pmw33xx_write(REG_Config2, 0x00); // disable REST mode
pd_dprintf("In the pmw33xx_upload_firmware Function.\n");
pmw33xx_write(sensor, REG_Config2, 0x00); // Added here specific to the 3389 datasheet.
if (!pmw33xx_write(sensor, REG_SROM_Enable, 0x1d)) {
return false;
}
wait_ms(10);
pmw33xx_write(sensor, REG_SROM_Enable, 0x18);

if (!pmw33xx_spi_start(sensor)) {
return false;
}

spi_write(REG_SROM_Load_Burst | 0x80);
wait_us(15);

for (size_t i = 0; i < PMW33XX_FIRMWARE_LENGTH; i++) {
spi_write(pgm_read_byte(pmw33xx_firmware_data + i));
wait_us(15);
}
wait_us(200);

//pd_dprintf("Sensor SROM_ID: %x\n", pmw33xx_read(sensor, REG_SROM_ID));
//pmw33xx_write(sensor, REG_Config2, 0x00); // Appears to be out of order for the 3389 datasheet.

return true;
}

bool pmw33xx_init(uint8_t sensor) {
pd_dprintf("In the pmw33xx_init function.\n");
if (sensor >= pmw33xx_number_of_sensors) {
return false;
}
spi_init();

// power up, need to first drive NCS high then low. the datasheet does not
// say for how long, 40us works well in practice.
if (!pmw33xx_spi_start(sensor)) {
return false;
}
wait_us(40);
spi_stop();
wait_us(40);

if (!pmw33xx_write(sensor, REG_Power_Up_Reset, 0x5a)) {
return false;
}
wait_ms(50);

// read registers and discard
pmw33xx_read(sensor, REG_Motion);
pmw33xx_read(sensor, REG_Delta_X_L);
pmw33xx_read(sensor, REG_Delta_X_H);
pmw33xx_read(sensor, REG_Delta_Y_L);
pmw33xx_read(sensor, REG_Delta_Y_H);

if (!pmw33xx_upload_firmware(sensor)) {
pd_dprintf("PMW33XX (%d): firmware upload failed!\n", sensor);
return false;
}

// Extra steps per 3389 datasheet.
pmw33xx_write(sensor, 0x3D, 0x80);
for (int i = 0; i < 55; i++) {
wait_ms(1);
if (pmw33xx_read(sensor, 0x3D) == 0xC0) {
pd_dprintf("Register 0x3D reached value 0xC0 after %d ms.\n", i);
break;
}
}
pmw33xx_write(sensor, 0x3D, 0x00);
pmw33xx_write(sensor, REG_Config2, 0x10);

// Configure the rest of the registers
wait_ms(10);
pmw33xx_set_cpi(sensor, PMW33XX_CPI);

wait_ms(1);

pmw33xx_write(sensor, REG_Config2, 0x00);
pmw33xx_write(sensor, REG_Angle_Tune, CONSTRAIN(ROTATIONAL_TRANSFORM_ANGLE, -127, 127));
pmw33xx_write(sensor, REG_Lift_Config, PMW33XX_LIFTOFF_DISTANCE);

if (!pmw33xx_check_signature(sensor)) {
pd_dprintf("PMW33XX (%d): firmware signature verification failed!\n", sensor);
return false;
}
pd_dprintf("Leaving the pmw33xx_init function.\n");
return true;
}

pmw33xx_report_t pmw33xx_read_burst(uint8_t sensor) {
pmw33xx_report_t report = {0};

if (sensor >= pmw33xx_number_of_sensors) {
return report;
}

if (!in_burst[sensor]) {
//pd_dprintf("PMW33XX (%d): burst\n", sensor);
if (!pmw33xx_write(sensor, REG_Motion_Burst, 0x00)) {
return report;
}
in_burst[sensor] = true;
}

if (!pmw33xx_spi_start(sensor)) {
return report;
}

spi_write(REG_Motion_Burst);
wait_us(35); // waits for tSRAD_MOTBR

spi_receive((uint8_t*)&report, sizeof(report));

// panic recovery, sometimes burst mode works weird.
if (report.motion.w & 0b111) {
in_burst[sensor] = false;
}

spi_stop();

//pd_dprintf("PMW33XX (%d): motion: 0x%x dx: %i dy: %i\n", sensor, report.motion.w, report.delta_x, report.delta_y);

report.delta_x *= -1;
report.delta_y *= -1;

return report;
}

uint16_t pmw33xx_get_cpi(uint8_t sensor) {
if (sensor >= pmw33xx_number_of_sensors) {
return 0;
}

// pd_dprintf("Reading CPI... 0x%02x", pmw33xx_read(sensor, REG_Resolution_H));
// wait_ms(10);
// pd_dprintf("%02x\n", pmw33xx_read(sensor, REG_Resolution_L));
uint16_t cpival = (pmw33xx_read(sensor, REG_Resolution_H) << 8) | pmw33xx_read(sensor, REG_Resolution_L);
return (uint16_t)((cpival + 1) & 0xFFFF) * PMW33XX_CPI_STEP;
}
Expand Down
Loading
Loading