Skip to content

Commit

Permalink
Merge branch 'develop' into bk_dilemma_3x5_3
Browse files Browse the repository at this point in the history
  • Loading branch information
casuanoob authored Dec 2, 2023
2 parents a6d0807 + 07e2b64 commit 8533d74
Show file tree
Hide file tree
Showing 61 changed files with 809 additions and 358 deletions.
19 changes: 19 additions & 0 deletions docs/feature_pointing_device.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,29 @@ The Analog Joystick is an analog (ADC) driven sensor. There are a variety of jo
| `ANALOG_JOYSTICK_Y_AXIS_PIN` | (Required) The pin used for the horizontal/Y axis. | _not defined_ |
| `ANALOG_JOYSTICK_AXIS_MIN` | (Optional) Sets the lower range to be considered movement. | `0` |
| `ANALOG_JOYSTICK_AXIS_MAX` | (Optional) Sets the upper range to be considered movement. | `1023` |
| `ANALOG_JOYSTICK_AUTO_AXIS` | (Optional) Sets ranges to be considered movement automatically. | _not defined_ |
| `ANALOG_JOYSTICK_SPEED_REGULATOR` | (Optional) The divisor used to slow down movement. (lower makes it faster) | `20` |
| `ANALOG_JOYSTICK_READ_INTERVAL` | (Optional) The interval in milliseconds between reads. | `10` |
| `ANALOG_JOYSTICK_SPEED_MAX` | (Optional) The maximum value used for motion. | `2` |
| `ANALOG_JOYSTICK_CLICK_PIN` | (Optional) The pin wired up to the press switch of the analog stick. | _not defined_ |
| `ANALOG_JOYSTICK_WEIGHTS` | (Optional) Use custom weights for lever positions. | _not defined_ |
| `ANALOG_JOYSTICK_CUTOFF` | (Optional) Cut off movement when joystick returns to start position. | _not defined_ |

If `ANALOG_JOYSTICK_AUTO_AXIS` is used, then `ANALOG_JOYSTICK_AXIS_MIN` and `ANALOG_JOYSTICK_AXIS_MAX` are ignored.

By default analog joystick implementation uses `x^2` weighting for lever positions. `ANALOG_JOYSTICK_WEIGHTS` allows to experiment with different configurations that might feel better.

E.g. This is weights for `((x-0.4)^3+0.064)/0.282`:

```c
#define ANALOG_JOYSTICK_WEIGHTS {0,2,4,5,7,8,9,10,12,13,14,15,15,16,17,18,18,19,19,20,20,21,21,21,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,25,25,25,26,26,26,27,28,28,29,29,30,31,32,33,34,35,36,37,38,40,41,43,44,46,48,49,51,53,56,58,60,62,65,68,70,73,76,79,82,85,89,92,96,100}
```
You can use following JS code to generate weights for different formulas:
```js
JSON.stringify(Array.from(Array(101).keys()).map(x => Math.ceil((((x/100-0.4)**3+0.064)/0.282*100))))
```

### Azoteq IQS5XX Trackpad

Expand Down
68 changes: 58 additions & 10 deletions drivers/sensors/analog_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,28 @@
#include <stdlib.h>

// Set Parameters
#ifndef ANALOG_JOYSTICK_AUTO_AXIS
uint16_t minAxisValue = ANALOG_JOYSTICK_AXIS_MIN;
uint16_t maxAxisValue = ANALOG_JOYSTICK_AXIS_MAX;
#else
int16_t minAxisValues[2];
int16_t maxAxisValues[2];
#endif

uint8_t maxCursorSpeed = ANALOG_JOYSTICK_SPEED_MAX;
uint8_t speedRegulator = ANALOG_JOYSTICK_SPEED_REGULATOR; // Lower Values Create Faster Movement

#ifdef ANALOG_JOYSTICK_WEIGHTS
int8_t weights[101] = ANALOG_JOYSTICK_WEIGHTS;
#endif

int16_t xOrigin, yOrigin;

uint16_t lastCursor = 0;

int16_t axisCoordinate(pin_t pin, uint16_t origin) {
uint8_t prevValues[2] = {0, 0};

int16_t axisCoordinate(pin_t pin, uint16_t origin, uint8_t axis) {
int8_t direction;
int16_t distanceFromOrigin;
int16_t range;
Expand All @@ -43,12 +54,27 @@ int16_t axisCoordinate(pin_t pin, uint16_t origin) {
return 0;
} else if (origin > position) {
distanceFromOrigin = origin - position;
range = origin - minAxisValue;
direction = -1;
#ifdef ANALOG_JOYSTICK_AUTO_AXIS
if (position < minAxisValues[axis]) {
minAxisValues[axis] = position;
}
range = origin - minAxisValues[axis];
#else
range = origin - minAxisValue;
#endif
direction = -1;
} else {
distanceFromOrigin = position - origin;
range = maxAxisValue - origin;
direction = 1;

#ifdef ANALOG_JOYSTICK_AUTO_AXIS
if (position > maxAxisValues[axis]) {
maxAxisValues[axis] = position;
}
range = maxAxisValues[axis] - origin;
#else
range = maxAxisValue - origin;
#endif
direction = 1;
}

float percent = (float)distanceFromOrigin / range;
Expand All @@ -62,23 +88,38 @@ int16_t axisCoordinate(pin_t pin, uint16_t origin) {
}
}

int8_t axisToMouseComponent(pin_t pin, int16_t origin, uint8_t maxSpeed) {
int16_t coordinate = axisCoordinate(pin, origin);
int8_t axisToMouseComponent(pin_t pin, int16_t origin, uint8_t maxSpeed, uint8_t axis) {
int16_t coordinate = axisCoordinate(pin, origin, axis);
int8_t result;
#ifndef ANALOG_JOYSTICK_WEIGHTS
if (coordinate != 0) {
float percent = (float)coordinate / 100;
return percent * maxCursorSpeed * (abs(coordinate) / speedRegulator);
result = percent * maxCursorSpeed * (abs(coordinate) / speedRegulator);
} else {
return 0;
}
#else
result = weights[abs(coordinate)] * (coordinate < 0 ? -1 : 1) * maxCursorSpeed / speedRegulator;
#endif

#ifdef ANALOG_JOYSTICK_CUTOFF
uint8_t pv = prevValues[axis];
prevValues[axis] = abs(result);
if (pv > abs(result)) {
return 0;
}
#endif

return result;
}

report_analog_joystick_t analog_joystick_read(void) {
report_analog_joystick_t report = {0};

if (timer_elapsed(lastCursor) > ANALOG_JOYSTICK_READ_INTERVAL) {
lastCursor = timer_read();
report.x = axisToMouseComponent(ANALOG_JOYSTICK_X_AXIS_PIN, xOrigin, maxCursorSpeed);
report.y = axisToMouseComponent(ANALOG_JOYSTICK_Y_AXIS_PIN, yOrigin, maxCursorSpeed);
report.x = axisToMouseComponent(ANALOG_JOYSTICK_X_AXIS_PIN, xOrigin, maxCursorSpeed, 0);
report.y = axisToMouseComponent(ANALOG_JOYSTICK_Y_AXIS_PIN, yOrigin, maxCursorSpeed, 1);
}
#ifdef ANALOG_JOYSTICK_CLICK_PIN
report.button = !readPin(ANALOG_JOYSTICK_CLICK_PIN);
Expand All @@ -93,4 +134,11 @@ void analog_joystick_init(void) {
// Account for drift
xOrigin = analogReadPin(ANALOG_JOYSTICK_X_AXIS_PIN);
yOrigin = analogReadPin(ANALOG_JOYSTICK_Y_AXIS_PIN);

#ifdef ANALOG_JOYSTICK_AUTO_AXIS
minAxisValues[0] = xOrigin - 100;
minAxisValues[1] = yOrigin - 100;
maxAxisValues[0] = xOrigin + 100;
maxAxisValues[1] = yOrigin + 100;
#endif
}
1 change: 0 additions & 1 deletion keyboards/0xcb/splaytoraid/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_BREATHING
#define RGB_MATRIX_DEFAULT_HUE 152
#define RGB_MATRIX_DEFAULT_SAT 232
#define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
#define RGB_MATRIX_DEFAULT_SPD 50

#define ENABLE_RGB_MATRIX_BREATHING
Expand Down
2 changes: 0 additions & 2 deletions keyboards/atlantis/ak81_ve/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#define RGB_DISABLE_WHEN_USB_SUSPENDED true
#define RGB_MATRIX_LED_COUNT 96
#define RGB_MATRIX_DEFAULT_HUE 170
#define RGB_MATRIX_DEFAULT_SAT 255
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 130
#define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS

#define ENABLE_RGB_MATRIX_ALPHAS_MODS // Static dual hue, speed is hue for secondary hue
#define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN // Static gradient top to bottom, speed controls how much gradient changes
Expand Down
1 change: 0 additions & 1 deletion keyboards/bandominedoni/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
# define LED_HITS_TO_REMEMBER 10

# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 50
# define RGB_MATRIX_DEFAULT_SPD 127
// the above brighness setting has no effect on rgb_matrix_set_color().
// Use darker colors instead.
/* RGB darker COLORS */
Expand Down
2 changes: 0 additions & 2 deletions keyboards/bastardkb/charybdis/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
# define RGB_MATRIX_KEYPRESSES

// Startup values.
# define RGB_MATRIX_DEFAULT_HUE 0
# define RGB_MATRIX_DEFAULT_SAT 255
# define RGB_MATRIX_DEFAULT_VAL 64

// Rainbow swirl as startup mode.
Expand Down
1 change: 0 additions & 1 deletion keyboards/bastardkb/scylla/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
# define RGB_MATRIX_LED_COUNT 58
# define RGB_MATRIX_SPLIT { 29, 29 }
# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 50
# define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
# define RGB_DISABLE_WHEN_USB_SUSPENDED
# define RGB_MATRIX_KEYPRESSES
#endif
1 change: 0 additions & 1 deletion keyboards/bastardkb/skeletyl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
# define RGB_MATRIX_LED_COUNT 36
# define RGB_MATRIX_SPLIT { 18, 18 }
# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 50
# define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
# define RGB_DISABLE_WHEN_USB_SUSPENDED
# define RGB_MATRIX_KEYPRESSES
#endif
1 change: 0 additions & 1 deletion keyboards/bastardkb/tbkmini/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
# define RGB_MATRIX_LED_COUNT 42
# define RGB_MATRIX_SPLIT { 21, 21 }
# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 50
# define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
# define RGB_DISABLE_WHEN_USB_SUSPENDED
# define RGB_MATRIX_KEYPRESSES
#endif
43 changes: 43 additions & 0 deletions keyboards/bestway/bestway.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright 2022 LXF-YZP(yuezp)
*
* 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 "quantum.h"

#ifdef RGBLIGHT_ENABLE

const rgblight_segment_t PROGMEM my_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 1, HSV_RED}
);

const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
my_capslock_layer
);

bool led_update_kb(led_t led_state) {
if (!led_update_user(led_state)) { return false; }
rgblight_set_layer_state(0, led_state.caps_lock);
return true;
}

void keyboard_post_init_kb(void) {
rgblight_layers = my_rgb_layers;
keyboard_post_init_user();
}

#endif
void board_init(void) {
AFIO->MAPR |= AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2;
}
22 changes: 22 additions & 0 deletions keyboards/bestway/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright 2022 LXF-YZP(yuezp)
*
* 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

#define WS2812_PWM_DRIVER PWMD2
#define WS2812_PWM_CHANNEL 4
#define WS2812_DMA_STREAM STM32_DMA1_STREAM2
#define WS2812_DMA_CHANNEL 2
21 changes: 21 additions & 0 deletions keyboards/bestway/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright 2022 LXF-YZP(yuezp)
*
* 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

#define HAL_USE_PWM TRUE

#include_next <halconf.h>
Loading

0 comments on commit 8533d74

Please sign in to comment.