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

get latest upstream #2

Merged
merged 50 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8ba537f
Keyboard: Planck THK (#12597)
Erovia May 26, 2021
0399271
[Keymap] update gunp layout for Planck (#12926)
gunpinyo May 27, 2021
7cd9eda
[Keyboard] SKErgo (#12923)
kevinzhao-tech May 27, 2021
3a6188f
[Keyboard] Adjustments to Gust Rev1.2 (#12716)
eithanshavit May 27, 2021
5962f05
[Keyboard] Add RGB Matrix support for Bear65 PCB (#12961)
stanrc85 May 27, 2021
e7d68c5
[Keymap] Add mercutio keymap and update readme.md for layouts (#12973)
Jonavin May 27, 2021
722b1d6
[Keymap] Add new keymap for ut472 (#12974)
stefanopace May 27, 2021
2ca7a86
[Keyboard] Removed LAYOUTS = ortho_6x16 (#12983)
noroadsleft May 27, 2021
712d53c
Document RGB_MATRIX_FRAMEBUFFER_EFFECTS (#12984)
peepeetee May 27, 2021
975e42e
[Keyboard] Fix Clawsome/Sedan matrix and default keymap (#13007)
beansrowning May 27, 2021
6750733
Add keymap with scrolling mode for the Ploopy Nano trackball (#13013)
hexadecatrienoic May 27, 2021
1f86c3a
[Keyboard] Fix Delilah VIA Keymap (#13008)
rainkeebs May 27, 2021
446ef4a
[Keyboard] Add F.Me Macropad (#12658)
thompson-ele May 27, 2021
0e53917
[Keyboard] Add VIA to Aves65 (#12990)
evyd13 May 27, 2021
7e14f85
[Keyboard] Add Jabberwocky Keyboard (#12500)
nopunin10did May 27, 2021
088c71b
[Keyboard] Corgi keyboard (#12311)
May 27, 2021
9da95bc
[Keymap] add personal keymap files, and sofle_rgb default maps, (#12267)
DaneEvans May 27, 2021
147cf8a
Sofle rev1 Keymap - featuring keyboard pets (#12499)
HellSingCoder May 27, 2021
84883d3
CLI/c2json: Print 'cpp' error when executed in verbose mode (#12869)
Erovia May 27, 2021
f55e39e
World domination (#13021)
Erovia May 29, 2021
1646c0f
2021 May 29 Breaking Changes Update (#13034)
noroadsleft May 29, 2021
305cca9
CLI: Fix automagic (#13046)
Erovia May 30, 2021
3aca3d3
merge/um70:via: Avoid sprintf() to make the code fit into flash (#12919)
sigprof May 30, 2021
fc9a216
[Keyboard] jabberwocky via support (#13029)
lukeski14 May 30, 2021
7b055dc
[Keyboard] Added BOP support (#12991)
blewis308 May 30, 2021
2b8f1fc
[Keyboard] Unicomp Mini M (#12892)
stevendlander May 30, 2021
1a3064a
[Keyboard] Add Rubi Numpad (#12283)
ohchiko May 31, 2021
6bafefa
[Keymap] lja83's Planck keymap (#12809)
lja83 May 31, 2021
5a06813
VIA compile fixes (#13054)
Xelus22 Jun 1, 2021
93496c8
fix missing arg (#13068)
Xelus22 Jun 1, 2021
35dbe8b
[Keymap] merge jdelkins userspace and associated keymaps (#11276)
jdelkins Jun 2, 2021
597d2e0
Fix up WS2812 SPI driver on F072. (#13022)
tzarc Jun 2, 2021
a0cc2dc
Update noroadsleft userspace and keymaps (2021-06-02) (#13086)
noroadsleft Jun 3, 2021
261d94c
Tidy up spi_master includes (#13053)
fauxpark Jun 3, 2021
af91221
`qmk multibuild`: Fix bug with Path objects (#13093)
fauxpark Jun 3, 2021
6eb18a6
[Keymap] Update bcat's split_3x6_3 for Crkbd legacy removal (#13097)
bcat Jun 3, 2021
e660dcf
Fix caps lock indicator on Bear65 PCB (#12966)
stanrc85 Jun 4, 2021
c7c9f3e
kbdfans/kbd67/rev2: add LAYOUT_65_ansi_split_space layout data (#13102)
noroadsleft Jun 4, 2021
770a334
Fix includes for pmw3360 driver (#13108)
drashna Jun 5, 2021
8128c5f
update feature_layers.md translation (#12752)
umi-umi Jun 5, 2021
ab6128e
Update Japanese document (#10670)
shelaf Jun 5, 2021
7aab06f
JETVAN: Add initial support (#12790)
TerryMathews Jun 5, 2021
add1052
Corrected Number-pad numbers (#13057)
NathanBlais Jun 6, 2021
0374e4c
[Keymap] add id80/ansi/keymaps/msf (#11957)
msf Jun 7, 2021
23631de
Fixed ISO keyboard layout for the Mysterium rev1.1 board (#12531)
HalfHeuslerAlloy Jun 7, 2021
7b66624
[Keyboard] add molecule (#12601)
bbrfkr Jun 7, 2021
94e8091
[Keyboard] Add program yoink via keymap (#12645)
matthewdias Jun 7, 2021
b10728e
[Docs] added basic midi documention of common features (#13113)
wxyangf Jun 7, 2021
9dffd35
Add default `ortho_1x1` layout (#13118)
fauxpark Jun 7, 2021
671a626
Merge branch 'qmk:master' into master
spRite75 Jun 7, 2021
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
Prev Previous commit
Next Next commit
[Keyboard] add molecule (qmk#12601)
Co-authored-by: Ryan <fauxpark@gmail.com>
Co-authored-by: Drashna Jaelre <drashna@live.com>
  • Loading branch information
3 people authored Jun 7, 2021
commit 7b666245d6e6baea939e0088fbbf9104d8efaca1
254 changes: 254 additions & 0 deletions keyboards/molecule/adns.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
/* Copyright 2020 Richard Sutherland <rich@brickbots.com>
*
* 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/>.
*/
#include "spi_master.h"
#include "adns.h"
#include "debug.h"
#include "quantum.h"
#include "pointing_device.h"
#include "adns9800_srom_A6.h"

// registers
#define REG_Product_ID 0x00
#define REG_Revision_ID 0x01
#define REG_Motion 0x02
#define REG_Delta_X_L 0x03
#define REG_Delta_X_H 0x04
#define REG_Delta_Y_L 0x05
#define REG_Delta_Y_H 0x06
#define REG_SQUAL 0x07
#define REG_Pixel_Sum 0x08
#define REG_Maximum_Pixel 0x09
#define REG_Minimum_Pixel 0x0a
#define REG_Shutter_Lower 0x0b
#define REG_Shutter_Upper 0x0c
#define REG_Frame_Period_Lower 0x0d
#define REG_Frame_Period_Upper 0x0e
#define REG_Configuration_I 0x0f
#define REG_Configuration_II 0x10
#define REG_Frame_Capture 0x12
#define REG_SROM_Enable 0x13
#define REG_Run_Downshift 0x14
#define REG_Rest1_Rate 0x15
#define REG_Rest1_Downshift 0x16
#define REG_Rest2_Rate 0x17
#define REG_Rest2_Downshift 0x18
#define REG_Rest3_Rate 0x19
#define REG_Frame_Period_Max_Bound_Lower 0x1a
#define REG_Frame_Period_Max_Bound_Upper 0x1b
#define REG_Frame_Period_Min_Bound_Lower 0x1c
#define REG_Frame_Period_Min_Bound_Upper 0x1d
#define REG_Shutter_Max_Bound_Lower 0x1e
#define REG_Shutter_Max_Bound_Upper 0x1f
#define REG_LASER_CTRL0 0x20
#define REG_Observation 0x24
#define REG_Data_Out_Lower 0x25
#define REG_Data_Out_Upper 0x26
#define REG_SROM_ID 0x2a
#define REG_Lift_Detection_Thr 0x2e
#define REG_Configuration_V 0x2f
#define REG_Configuration_IV 0x39
#define REG_Power_Up_Reset 0x3a
#define REG_Shutdown 0x3b
#define REG_Inverse_Product_ID 0x3f
#define REG_Motion_Burst 0x50
#define REG_SROM_Load_Burst 0x62
#define REG_Pixel_Burst 0x64

// pins
#define NCS F7

extern const uint16_t firmware_length;
extern const uint8_t firmware_data[];

enum motion_burst_propertr{
motion = 0,
observation,
delta_x_l,
delta_x_h,
delta_y_l,
delta_y_h,
squal,
pixel_sum,
maximum_pixel,
minimum_pixel,
shutter_upper,
shutter_lower,
frame_period_upper,
frame_period_lower,
end_data
};

void adns_begin(void){
spi_start(NCS, false, 3, 8);
}

void adns_end(void){
spi_stop();
}

void adns_write(uint8_t reg_addr, uint8_t data){

adns_begin();
//send address of the register, with MSBit = 1 to indicate it's a write
spi_write(reg_addr | 0x80 );
spi_write(data);

// tSCLK-NCS for write operation
wait_us(20);


// tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
wait_us(100);
adns_end();
}

uint8_t adns_read(uint8_t reg_addr){


adns_begin();
// send adress of the register, with MSBit = 0 to indicate it's a read
spi_write(reg_addr & 0x7f );
uint8_t data = spi_read();

// tSCLK-NCS for read operation is 120ns
wait_us(1);


// tSRW/tSRR (=20us) minus tSCLK-NCS
wait_us(19);

adns_end();
return data;
}

void pointing_device_init(void) {
dprint("STARTING INTI\n");

spi_init();
// reset serial port
adns_begin();
adns_end();

// reboot
adns_write(REG_Power_Up_Reset, 0x5a);
wait_ms(50);
// read registers and discard
adns_read(REG_Motion);
adns_read(REG_Delta_X_L);
adns_read(REG_Delta_X_H);
adns_read(REG_Delta_Y_L);
adns_read(REG_Delta_Y_H);

// upload firmware

// set the configuration_IV register in 3k firmware mode
// bit 1 = 1 for 3k mode, other bits are reserved
adns_write(REG_Configuration_IV, 0x02);

// write 0x1d in SROM_enable reg for initializing
adns_write(REG_SROM_Enable, 0x1d);

// wait for more than one frame period
// assume that the frame rate is as low as 100fps... even if it should never be that low
wait_ms(10);

// write 0x18 to SROM_enable to start SROM download
adns_write(REG_SROM_Enable, 0x18);

// write the SROM file (=firmware data)

// write burst destination adress
adns_begin();
spi_write(REG_SROM_Load_Burst | 0x80);
wait_us(15);
// send all bytes of the firmware
unsigned char c;
for(int i = 0; i < firmware_length; i++){
c = (unsigned char)pgm_read_byte(firmware_data + i);
spi_write(c);
wait_us(15);
}

adns_end();
wait_ms(10);

// enable laser(bit 0 = 0b), in normal mode (bits 3,2,1 = 000b)
// reading the actual value of the register is important because the real
// default value is different from what is said in the datasheet, and if you
// change the reserved bytes (like by writing 0x00...) it would not work.
uint8_t laser_ctrl0 = adns_read(REG_LASER_CTRL0);
adns_write(REG_LASER_CTRL0, laser_ctrl0 & 0xf0);

wait_ms(1);

// set the configuration_I register to set the CPI
// 0x01 = 50, minimum
// 0x44 = 3400, default
// 0x8e = 7100
// 0xA4 = 8200, maximum
adns_write(REG_Configuration_I, 0x10);

wait_ms(100);
dprint("INIT ENDED\n");
}

int16_t convertDeltaToInt(uint8_t high, uint8_t low){

// join bytes into twos compliment
//int16_t twos_comp = (high << 8) | low;
//return twos_comp;
return (high << 8) | low;
}

motion_delta_t readSensor(void) {
adns_begin();

// read from Motion_Burst to enable burt mode
spi_write(REG_Motion_Burst & 0x7f);

// Wait one frame per docs, thanks u/kbjunky
wait_us(100);
uint8_t burst_data[pixel_sum];

for (int i = 0; i < pixel_sum; ++i) {
burst_data[i] = spi_read();
}

uint16_t delta_x = convertDeltaToInt(burst_data[delta_x_h], burst_data[delta_x_l]);
uint16_t delta_y = convertDeltaToInt(burst_data[delta_y_h], burst_data[delta_y_l]);
// Only consider the MSB for motion as this byte has other status bits
uint8_t motion_ind = burst_data[motion] & 0b10000000;
adns_end();

motion_delta_t delta = {delta_x, delta_y, motion_ind};
return delta;
}

void pointing_device_task(void) {
motion_delta_t delta = readSensor();

report_mouse_t report = pointing_device_get_report();

if(delta.motion_ind) {
// clamp deltas from -127 to 127
report.x = delta.delta_x < -127 ? -127 : delta.delta_x > 127 ? 127 : delta.delta_x;
report.x = -report.x;
report.y = delta.delta_y < -127 ? -127 : delta.delta_y > 127 ? 127 : delta.delta_y;
}

pointing_device_set_report(report);
pointing_device_send();
}
36 changes: 36 additions & 0 deletions keyboards/molecule/adns.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright 2020 Richard Sutherland <rich@brickbots.com>
*
* 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

void adns_begin(void);

void adns_end(void);

void adns_write(uint8_t reg_addr, uint8_t data);

uint8_t adns_read(uint8_t reg_addr);


int16_t convertDeltaToInt(uint8_t high, uint8_t low);

struct _motion_delta {
int16_t delta_x;
int16_t delta_y;
int8_t motion_ind;
};
typedef struct _motion_delta motion_delta_t;

motion_delta_t readSensor(void);
Loading