Skip to content

Commit

Permalink
Merge pull request #3 from mxihan/master
Browse files Browse the repository at this point in the history
update freertos-kernel and pico-sdk version, use freertos-smp to manage tasks, move aime task to core1 and add lever sampling task to core0
  • Loading branch information
Lee65535 committed Mar 1, 2024
2 parents 73dd8d9 + 0f8d444 commit c4c4889
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 120 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
- run: |
sudo apt update
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "pico-sdk"]
path = pico-sdk
url = https://github.com/raspberrypi/pico-sdk/
[submodule "freertos/FreeRTOS-Kernel"]
path = freertos/FreeRTOS-Kernel
url = https://github.com/FreeRTOS/FreeRTOS-Kernel/
[submodule "src/PicoLed"]
path = src/PicoLed
url = https://github.com/ForsakenNGS/PicoLED
[submodule "FreeRTOS-Kernel"]
path = FreeRTOS-Kernel
url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ include(pico-sdk/pico_sdk_init.cmake)

project(LKICK)


set(PICO_CXX_ENABLE_EXCEPTIONS 1)

pico_sdk_init()
Expand Down Expand Up @@ -34,9 +33,8 @@ target_include_directories(LKICK PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/analogRead
)

add_subdirectory(freertos)
add_subdirectory(src/PicoLed)
target_link_libraries(LKICK pico_stdlib pico_multicore hardware_adc hardware_i2c tinyusb_device tinyusb_board freertos PicoLed hardware_flash)

add_subdirectory(FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040 FreeRTOS-Kernel)
target_link_libraries(LKICK pico_stdlib pico_multicore hardware_adc hardware_i2c FreeRTOS-Kernel FreeRTOS-Kernel-Heap4 tinyusb_device tinyusb_board PicoLed hardware_flash)
#pico_enable_stdio_uart(LKICK 1)
pico_add_extra_outputs(LKICK)
1 change: 1 addition & 0 deletions FreeRTOS-Kernel
Submodule FreeRTOS-Kernel added at 0240cd
17 changes: 0 additions & 17 deletions freertos/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion freertos/FreeRTOS-Kernel
Submodule FreeRTOS-Kernel deleted from b00250
2 changes: 1 addition & 1 deletion pico-sdk
Submodule pico-sdk updated 387 files
2 changes: 1 addition & 1 deletion src/PicoLed
Submodule PicoLed updated 1 files
+2 −2 PicoLed.hpp
179 changes: 96 additions & 83 deletions freertos/FreeRTOSConfig.h → src/components/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -1,84 +1,97 @@
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/* Use Pico SDK ISR handlers */
#define vPortSVCHandler isr_svcall
#define xPortPendSVHandler isr_pendsv
#define xPortSysTickHandler isr_systick

#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ 133000000
#define configTICK_RATE_HZ 100
#define configMAX_PRIORITIES 5
#define configMINIMAL_STACK_SIZE 128
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
#define configUSE_MUTEXES 0
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_COUNTING_SEMAPHORES 0
#define configQUEUE_REGISTRY_SIZE 10
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
#define configSTACK_DEPTH_TYPE uint16_t
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t

/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configAPPLICATION_ALLOCATED_HEAP 1

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0

/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0

/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 1

/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE

/* Define to trap errors during development. */
#define configASSERT( x )

/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 0
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0
#define INCLUDE_xTaskResumeFromISR 1

/* A header file that defines trace macro can be included here. */

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/* Use Pico SDK ISR handlers */
#define vPortSVCHandler isr_svcall
#define xPortPendSVHandler isr_pendsv
#define xPortSysTickHandler isr_systick

#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ 133000000
#define configTICK_RATE_HZ 100
#define configMAX_PRIORITIES 5
#define configMINIMAL_STACK_SIZE 128
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
#define configUSE_MUTEXES 0
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_COUNTING_SEMAPHORES 0
#define configQUEUE_REGISTRY_SIZE 10
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
#define configSTACK_DEPTH_TYPE uint16_t
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t

/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configAPPLICATION_ALLOCATED_HEAP 0
#define configTOTAL_HEAP_SIZE (128*1024)

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0

/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0

/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 1

/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE

/* SMP port only */
#define configNUMBER_OF_CORES 2
#define configNUM_CORES 2
#define configTICK_CORE 0
#define configRUN_MULTIPLE_PRIORITIES 1
#define configUSE_CORE_AFFINITY 1
#define configUSE_PASSIVE_IDLE_HOOK 0

/* RP2040 specific */
#define configSUPPORT_PICO_SYNC_INTEROP 1
#define configSUPPORT_PICO_TIME_INTEROP 1

/* Define to trap errors during development. */
#define configASSERT( x )

/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0
#define INCLUDE_xTaskResumeFromISR 1

/* A header file that defines trace macro can be included here. */

#endif /* FREERTOS_CONFIG_H */
17 changes: 16 additions & 1 deletion src/components/io4_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ namespace component {
output_keyboard_t output_keyboard_data;

void usb_init() {
xTaskCreate(tud, "tud", 2048, NULL, 10, NULL);
TaskHandle_t tud_handle = nullptr;
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 @@ -71,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);
}
}
10 changes: 8 additions & 2 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.0005);
ResponsiveAnalogRead analog(LEVER_PIN, true, 0.002);
namespace ongeki_hardware {
void init() {
for (unsigned char i: PIN_MAP) {
Expand Down Expand Up @@ -192,13 +192,19 @@ namespace component {
// tud_cdc_write_char('\r');
// tud_cdc_write_char('\n');
} else {
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
17 changes: 11 additions & 6 deletions src/components/serial.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "stdinclude.h"
#define configUSE_CORE_AFFINITY 1

#include "pico/multicore.h"
namespace component {
namespace serial {
stream streams[CFG_TUD_CDC] = {
Expand All @@ -10,17 +8,24 @@ namespace component {
};


[[noreturn]] void core1(){
[[noreturn]] void led_board(void *pVoid){
led_board::init(&component::serial::streams[1]);
while(true){
led_board::update();
vTaskDelay(2 / portTICK_PERIOD_MS);
}
}

void init() {
xTaskCreate(component::serial::aimeUpdate, "aime", 2048, NULL, 6, NULL);

multicore_launch_core1(core1);
TaskHandle_t aime_handle = nullptr;
xTaskCreate(component::serial::aimeUpdate, "aime", 2048, NULL, 6, &aime_handle);
UBaseType_t aime_CoreAffinityMask = (1 << 1);
vTaskCoreAffinitySet(aime_handle, aime_CoreAffinityMask);

TaskHandle_t led_board_handle = nullptr;
xTaskCreate(component::serial::led_board, "led_board", 4096, NULL, 6, &led_board_handle);
UBaseType_t led_board_CoreAffinityMask = (1 << 1);
vTaskCoreAffinitySet(led_board_handle, led_board_CoreAffinityMask);
}

[[noreturn]] void aimeUpdate(void *pVoid) {
Expand Down

0 comments on commit c4c4889

Please sign in to comment.