From 792d00bc055cffe915c3dfad0948be1d091df3cc Mon Sep 17 00:00:00 2001 From: embr Date: Tue, 25 Apr 2023 14:47:56 +0200 Subject: [PATCH] ayy we can remote control an LED --- CMakeLists.txt | 1 + src/main.c | 1 - src/state.c | 18 ++++++++++++++++-- src/state.h | 4 ++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2a7445..3a89bbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ target_link_libraries(vibe-check pico_cyw43_arch_none pico_btstack_ble pico_btstack_cyw43 + hardware_pwm ) pico_btstack_make_gatt_header(vibe-check PRIVATE "${CMAKE_SOURCE_DIR}/src/vibe.gatt") diff --git a/src/main.c b/src/main.c index 52ab993..56055b4 100644 --- a/src/main.c +++ b/src/main.c @@ -41,7 +41,6 @@ int main() { // set initial state state_init(); - state_set_power(0); att_server_init(profile_data, bt_att_read_callback, bt_att_write_callback); diff --git a/src/state.c b/src/state.c index 665b807..81238a7 100644 --- a/src/state.c +++ b/src/state.c @@ -1,10 +1,24 @@ #include "state.h" +#include "hardware/pwm.h" +#include "pico/stdlib.h" + +#define PWM_PIN_0 16 +#define PWM_PIN_1 17 + +static int pwm_slice = 0; void state_init() { - // TODO: Assign GPIO pins to PWM. + pwm_slice = pwm_gpio_to_slice_num(PWM_PIN_0); + + gpio_set_function(PWM_PIN_0, GPIO_FUNC_PWM); + gpio_set_function(PWM_PIN_1, GPIO_FUNC_PWM); + + pwm_set_wrap(pwm_slice, 99); state_set_power(0); + pwm_set_enabled(pwm_slice, true); } void state_set_power(uint8_t power) { - // TODO: Set power! + pwm_set_chan_level(pwm_slice, PWM_CHAN_A, power); + pwm_set_chan_level(pwm_slice, PWM_CHAN_B, power); } diff --git a/src/state.h b/src/state.h index 0a6e097..b52b69c 100644 --- a/src/state.h +++ b/src/state.h @@ -3,10 +3,10 @@ #include -// Initializes wand state. +// Initialize wand state. void state_init(); -// Sets the wand's power, 0-100. +// Set the wand's power, 0-100. void state_set_power(uint8_t power); #endif