Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions bluetooth/ble_pointer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_executable(ble_pointer
ble_pointer.c
ble_pointer_nosys_main.c
mpu6050_i2c_lib.c
)
target_link_libraries(ble_pointer
Expand All @@ -20,3 +21,35 @@ target_compile_definitions(ble_pointer PRIVATE
pico_btstack_make_gatt_header(ble_pointer PRIVATE "${CMAKE_CURRENT_LIST_DIR}/ble_pointer.gatt")
pico_add_extra_outputs(ble_pointer)

if (NOT FREERTOS_KERNEL_PATH AND NOT DEFINED ENV{FREERTOS_KERNEL_PATH})
return()
endif()
include(../../freertos/FreeRTOS_Kernel_import.cmake)

add_executable(ble_pointer_freertos
ble_pointer.c
ble_pointer_freertos_main.c
mpu6050_i2c_lib.c
)
target_link_libraries(ble_pointer_freertos
pico_stdlib
pico_btstack_ble
pico_btstack_cyw43
pico_cyw43_arch_sys_freertos
hardware_i2c
FreeRTOS-Kernel-Heap4
)
target_include_directories(ble_pointer_freertos PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/..
${CMAKE_CURRENT_LIST_DIR}/../config # for common btstack config
${CMAKE_CURRENT_LIST_DIR}/../../freertos # for FreeRTOSConfig.h
)
target_compile_definitions(ble_pointer_freertos PRIVATE
#WANT_HCI_DUMP=1
CYW43_LWIP=0
configNUMBER_OF_CORES=1 # run freertos on one core, the other core is doing something else
)
pico_btstack_make_gatt_header(ble_pointer_freertos PRIVATE "${CMAKE_CURRENT_LIST_DIR}/ble_pointer.gatt")
pico_add_extra_outputs(ble_pointer_freertos)

4 changes: 1 addition & 3 deletions bluetooth/ble_pointer/ble_pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
}
}

int main(void) {
stdio_init_all();
void run_ble_pointer(void) {

// Make the I2C pins available to picotool
bi_decl(bi_2pins_with_func(PICO_DEFAULT_I2C_SDA_PIN, PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C));
Expand Down Expand Up @@ -470,5 +469,4 @@ int main(void) {
sleep_ms(1000);
}
#endif
return 0;
}
66 changes: 66 additions & 0 deletions bluetooth/ble_pointer/ble_pointer_freertos_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <stdio.h>

#include "pico/stdio.h"
#include "pico/multicore.h"
#include "pico/flash.h"

#include "FreeRTOS.h"
#include "task.h"

#define START_CORE_1 0

extern void run_ble_pointer(void);

#define MAIN_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
#define MAIN_TASK_STACK_SIZE configMINIMAL_STACK_SIZE

static void main_task_core0(__unused void *params) {
run_ble_pointer();
}

static void vLaunch0( void) {
#if 1
// todo: is this right?
flash_safe_execute_core_init();
#endif

TaskHandle_t task;
static_assert(configSUPPORT_DYNAMIC_ALLOCATION, "");
xTaskCreate(main_task_core0, "MainThread_core0", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &task);
#if configNUMBER_OF_CORES > 1
vTaskCoreAffinitySet(task, 1<<0);
#endif

/* Start the tasks and timer running. */
vTaskStartScheduler();
}

#if START_CORE_1
static void main_task_core1(__unused void *params) {
printf("Hello from core1");
while(true) {
sleep_ms(100);
}
}

void vLaunch1( void) {

TaskHandle_t task;
static_assert(configSUPPORT_DYNAMIC_ALLOCATION, "");
xTaskCreate(main_task_core1, "MainThread_core1", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &task);
vTaskCoreAffinitySet(task, 1<<1);

/* Start the tasks and timer running. */
vTaskStartScheduler();
}
#endif

int main(void) {
stdio_init_all();
vLaunch0();
#if START_CORE_1
multicore_launch_core1(vLaunch1);
#endif
return 0;
}

9 changes: 9 additions & 0 deletions bluetooth/ble_pointer/ble_pointer_nosys_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "pico/stdio.h"

extern void run_ble_pointer(void);

int main(void) {
stdio_init_all();
run_ble_pointer();
return 0;
}
Loading