Skip to content

Commit

Permalink
add lever sampling task and change TaskCoreAffinity
Browse files Browse the repository at this point in the history
  • Loading branch information
mxihan committed Mar 1, 2024
1 parent 53e0647 commit d62c5eb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/components/io4_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace component {
xTaskCreate(tud, "tud", 2048, NULL, 10, &tud_handle);
UBaseType_t tud_CoreAffinityMask = (1 << 0);
vTaskCoreAffinitySet(tud_handle, tud_CoreAffinityMask);

TaskHandle_t lever_sampling_handle = nullptr;
xTaskCreate(lever_sampling, "lever_sampling", 2048, NULL, 10, &lever_sampling_handle);
UBaseType_t lever_sampling_CoreAffinityMask = (1 << 0);
vTaskCoreAffinitySet(lever_sampling_handle, lever_sampling_CoreAffinityMask);
}

[[noreturn]] void tud(void *pVoid) {
Expand Down Expand Up @@ -74,6 +79,13 @@ namespace component {
}
}

[[noreturn]] void lever_sampling(void *pVoid) {
while (true) {
component::ongeki_hardware::update_analog();
vTaskDelay(1 / portTICK_PERIOD_MS);
}
}

void process_data(const input_t *data) {
switch (data->cmd) {
case io4_usb::SET_COMM_TIMEOUT:
Expand Down
2 changes: 2 additions & 0 deletions src/components/io4_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace component {

[[noreturn]] void tud(void *pVoid);

[[noreturn]] void lever_sampling(void *pVoid);

void process_data(const input_t *data);
}
}
12 changes: 8 additions & 4 deletions src/components/ongeki_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace component {
bool hasI2cLever = false;
uint8_t addr = 0b0000110;
uint8_t reg1 = 0x03, reg2 = 0x04;
ResponsiveAnalogRead analog(LEVER_PIN, true, 0.01);
ResponsiveAnalogRead analog(LEVER_PIN, true, 0.002);
namespace ongeki_hardware {
void init() {
for (unsigned char i: PIN_MAP) {
Expand Down Expand Up @@ -192,15 +192,19 @@ namespace component {
// tud_cdc_write_char('\r');
// tud_cdc_write_char('\n');
} else {
for (int i = 0; i < 10; i++) {
analog.update();
}
uint16_t raw = analog.getValue() << 4;
data->analog[0] = *(int16_t *) &raw;
data->rotary[0] = *(int16_t *) &raw;
}
}

void update_analog()
{
for (int i = 0; i < 10; i++) {
analog.update();
}
}

void add_key(uint8_t *keycodes, uint8_t key, int index) {
if (index >= 6) return;
keycodes[index] = key;
Expand Down
1 change: 1 addition & 0 deletions src/components/ongeki_hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace component {
void init();
void update_hardware(component::io4_usb::output_t *data);
void update_keyboard(component::io4_usb::output_keyboard_t *data);
void update_analog();
void set_led(uint ledData);
void set_led_brightness(uint8_t brightness);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace component {
void init() {
TaskHandle_t aime_handle = nullptr;
xTaskCreate(component::serial::aimeUpdate, "aime", 2048, NULL, 6, &aime_handle);
UBaseType_t aime_CoreAffinityMask = (1 << 0);
UBaseType_t aime_CoreAffinityMask = (1 << 1);
vTaskCoreAffinitySet(aime_handle, aime_CoreAffinityMask);

TaskHandle_t led_board_handle = nullptr;
Expand Down

0 comments on commit d62c5eb

Please sign in to comment.