Skip to content

Commit

Permalink
remove uses of deprecated watch_gpio functions
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Oct 7, 2024
1 parent ab861d8 commit 4933a84
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion movement/watch_faces/complication/day_one_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool day_one_face_loop(movement_event_t event, void *context) {
case EVENT_LOW_ENERGY_UPDATE:
case EVENT_TICK:
if (state->quick_cycle) {
if (watch_get_pin_level(BTN_ALARM)) {
if (HAL_GPIO_BTN_ALARM_read()) {
_day_one_face_increment(state);
} else {
_day_one_face_abort_quick_cycle(state);
Expand Down
2 changes: 1 addition & 1 deletion movement/watch_faces/complication/deadline_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static bool _setting_loop(movement_event_t event, void *context)
switch (event.event_type) {
case EVENT_TICK:
if (state->tick_freq == 8) {
if (watch_get_pin_level(BTN_ALARM)) {
if (HAL_GPIO_BTN_ALARM_read()) {
_increment_date(state, date_time);
_setting_display(event, state, date_time);
} else {
Expand Down
2 changes: 1 addition & 1 deletion movement/watch_faces/complication/endless_runner_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static void update_game(endless_runner_state_t *state, uint8_t subsecond) {
game_state.jump_state = JUMPING_FINAL_FRAME;
else
game_state.fuel--;
if (!watch_get_pin_level(BTN_ALARM) && !watch_get_pin_level(BTN_LIGHT)) stop_jumping(state);
if (!HAL_GPIO_BTN_ALARM_read() && !HAL_GPIO_BTN_LIGHT_read()) stop_jumping(state);
}
else {
curr_jump_frame = game_state.jump_state - NOT_JUMPING;
Expand Down
15 changes: 5 additions & 10 deletions movement/watch_faces/complication/flashlight_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void flashlight_face_setup(uint8_t watch_face_index, void ** context_ptr) {
void flashlight_face_activate(void *context) {
(void) context;

watch_enable_digital_output(A2);
watch_set_pin_level(A2, false);
HAL_GPIO_A2_out();
HAL_GPIO_A2_clr();
}

bool flashlight_face_loop(movement_event_t event, void *context) {
Expand All @@ -53,11 +53,7 @@ bool flashlight_face_loop(movement_event_t event, void *context) {
case EVENT_LIGHT_BUTTON_DOWN:
break;
case EVENT_LIGHT_BUTTON_UP:
if (watch_get_pin_level(A2)) {
watch_set_pin_level(A2, false);
} else {
watch_set_pin_level(A2, true);
}
HAL_GPIO_A2_toggle();
break;
case EVENT_TIMEOUT:
movement_move_to_face(0);
Expand All @@ -72,7 +68,6 @@ bool flashlight_face_loop(movement_event_t event, void *context) {
void flashlight_face_resign(void *context) {
(void) context;

watch_set_pin_level(A2, false);
watch_disable_digital_output(A2);
HAL_GPIO_A2_clr();
HAL_GPIO_A2_off();
}

6 changes: 3 additions & 3 deletions movement/watch_faces/complication/periodic_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static void _handle_backward(periodic_state_t *state, bool should_sound){

static void _handle_mode_still_pressed(periodic_state_t *state, bool should_sound) {
if (_ts_ticks != 0){
if (!watch_get_pin_level(BTN_MODE)) {
if (!HAL_GPIO_BTN_MODE_read()) {
_ts_ticks = 0;
return;
}
Expand Down Expand Up @@ -401,8 +401,8 @@ bool periodic_face_loop(movement_event_t event, void *context)
if (state->mode == SCREEN_TITLE) _text_pos = _loop_text(_text_looping, _text_pos, 5);
else if (state->mode == SCREEN_FULL_NAME) _text_pos = _loop_text(_text_looping, _text_pos, 6);
if (_quick_ticks_running) {
if (watch_get_pin_level(BTN_LIGHT)) _handle_backward(state, false);
else if (watch_get_pin_level(BTN_ALARM)) _handle_forward(state, false);
if (HAL_GPIO_BTN_LIGHT_read()) _handle_backward(state, false);
else if (HAL_GPIO_BTN_ALARM_read()) _handle_forward(state, false);
else stop_quick_cyc();
}

Expand Down
8 changes: 4 additions & 4 deletions movement/watch_faces/complication/tally_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool tally_face_loop(movement_event_t event, void *context) {
static bool using_led = false;

if (using_led) {
if(!watch_get_pin_level(BTN_MODE) && !watch_get_pin_level(BTN_LIGHT) && !watch_get_pin_level(BTN_ALARM))
if(!HAL_GPIO_BTN_MODE_read() && !HAL_GPIO_BTN_LIGHT_read() && !HAL_GPIO_BTN_ALARM_read())
using_led = false;
else {
if (event.event_type == EVENT_LIGHT_BUTTON_DOWN || event.event_type == EVENT_ALARM_BUTTON_DOWN)
Expand All @@ -125,8 +125,8 @@ bool tally_face_loop(movement_event_t event, void *context) {
switch (event.event_type) {
case EVENT_TICK:
if (_quick_ticks_running) {
bool light_pressed = watch_get_pin_level(BTN_LIGHT);
bool alarm_pressed = watch_get_pin_level(BTN_ALARM);
bool light_pressed = HAL_GPIO_BTN_LIGHT_read();
bool alarm_pressed = HAL_GPIO_BTN_ALARM_read();
if (light_pressed && alarm_pressed) stop_quick_cyc();
else if (light_pressed) tally_face_increment(state, movement_button_should_sound());
else if (alarm_pressed) tally_face_decrement(state, movement_button_should_sound());
Expand Down Expand Up @@ -160,7 +160,7 @@ bool tally_face_loop(movement_event_t event, void *context) {
break;
case EVENT_LIGHT_BUTTON_DOWN:
case EVENT_ALARM_BUTTON_DOWN:
if (watch_get_pin_level(BTN_MODE)) {
if (HAL_GPIO_BTN_MODE_read()) {
movement_illuminate_led();
using_led = true;
}
Expand Down
2 changes: 1 addition & 1 deletion movement/watch_faces/complication/time_left_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ bool time_left_face_loop(movement_event_t event, void *context) {
case EVENT_TICK: {
uint8_t subsecond = event.subsecond;
if (_quick_ticks_running) {
if (watch_get_pin_level(BTN_ALARM)) {
if (HAL_GPIO_BTN_ALARM_read()) {
_handle_alarm_button(state);
subsecond = 0;
} else _abort_quick_ticks();
Expand Down
2 changes: 1 addition & 1 deletion movement/watch_faces/complication/timer_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ bool timer_face_loop(movement_event_t event, void *context) {
if (state->mode == running) state->now_ts++;
else if (state->mode == pausing) state->pausing_seconds++;
else if (state->quick_cycle) {
if (watch_get_pin_level(BTN_ALARM)) {
if (HAL_GPIO_BTN_ALARM_read()) {
_settings_increment(state);
subsecond = 0;
} else _abort_quick_cycle(state);
Expand Down
4 changes: 2 additions & 2 deletions movement/watch_faces/complication/wareki_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ bool wareki_loop(movement_event_t event, void *context) {

//printf("tick %d\n",state->disp_year );

if (_alarm_button_press && watch_get_pin_level(BTN_ALARM)){
if (_alarm_button_press && HAL_GPIO_BTN_ALARM_read()){
//printf("ALARM ON\n");
}
else{
//printf("ALARM OFF\n");
_alarm_button_press = false;
}

if (_light_button_press && watch_get_pin_level(BTN_LIGHT)){
if (_light_button_press && HAL_GPIO_BTN_LIGHT_read()){
//printf("LIGHT ON\n");
}
else{
Expand Down
2 changes: 1 addition & 1 deletion movement/watch_faces/complication/wordle_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ bool wordle_face_loop(movement_event_t event, void *context) {
display_letter(state, true);
if (state->word_elements[state->position] == WORDLE_NUM_VALID_LETTERS) break;
#if (WORDLE_USE_RANDOM_GUESS != 0)
if (watch_get_pin_level(BTN_LIGHT) &&
if (HAL_GPIO_BTN_LIGHT_read() &&
(state->using_random_guess || (state->attempt == 0 && state->position == 0))) {
insert_random_guess(state);
break;
Expand Down
4 changes: 2 additions & 2 deletions movement/watch_faces/demo/lis2dw_logging_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void lis2dh_logging_face_activate(void *context) {
lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
logger_state->display_index = 0;
logger_state->log_ticks = 0;
watch_enable_digital_input(A4);
HAL_GPIO_A4_in();
}

bool lis2dw_logging_face_loop(movement_event_t event, void *context) {
Expand Down Expand Up @@ -184,7 +184,7 @@ bool lis2dw_logging_face_loop(movement_event_t event, void *context) {

void lis2dw_logging_face_resign(void *context) {
(void) context;
watch_disable_digital_input(A4);
HAL_GPIO_A4_off();
}

movement_watch_face_advisory_t lis2dw_logging_face_advise(void *context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void accelerometer_data_acquisition_face_setup(uint8_t watch_face_index, void **
// mark first four pages as used
buf[0] = 0x0F;
wait_for_flash_ready();
watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
spi_flash_command(CMD_ENABLE_WRITE);
wait_for_flash_ready();
spi_flash_write_data(0, buf, 256);
Expand Down Expand Up @@ -351,15 +351,15 @@ static void write_buffer_to_page(uint8_t *buf, uint16_t page) {
uint32_t address = 256 * page;

wait_for_flash_ready();
watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
spi_flash_command(CMD_ENABLE_WRITE);
wait_for_flash_ready();
watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
spi_flash_write_data(address, buf, 256);
wait_for_flash_ready();

uint8_t buf2[256];
watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
spi_flash_read_data(address, buf2, 256);
wait_for_flash_ready();

Expand All @@ -376,26 +376,26 @@ static void write_buffer_to_page(uint8_t *buf, uint16_t page) {
}
}

watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
spi_flash_read_data(header_page * 256, used_pages, 256);
used_pages[offset_in_buf] = used_byte;
watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
spi_flash_command(CMD_ENABLE_WRITE);
wait_for_flash_ready();
watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
spi_flash_write_data(header_page * 256, used_pages, 256);
wait_for_flash_ready();
}

static bool wait_for_flash_ready(void) {
watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
bool ok = true;
uint8_t read_status_response[1] = {0x00};
do {
ok = spi_flash_read_command(CMD_READ_STATUS, read_status_response, 1);
} while ((read_status_response[0] & 0x3) != 0);
delay_ms(1); // why do i need this?
watch_set_pin_level(A3, true);
HAL_GPIO_A3_set();
return ok;
}

Expand Down
4 changes: 2 additions & 2 deletions watch-library/shared/driver/spiflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
#define SPI_FLASH_FAST_READ false

static void flash_enable(void) {
watch_set_pin_level(A3, false);
HAL_GPIO_A3_clr();
}

static void flash_disable(void) {
watch_set_pin_level(A3, true);
HAL_GPIO_A3_set();
}

static bool transfer(uint8_t *command, uint32_t command_length, uint8_t *data_in, uint8_t *data_out, uint32_t data_length) {
Expand Down
18 changes: 10 additions & 8 deletions watch-library/shared/driver/thermistor_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ void thermistor_driver_enable(void) {
// Enable the ADC peripheral, which we'll use to read the thermistor value.
watch_enable_adc();
// Enable analog circuitry on the sense pin, which is tied to the thermistor resistor divider.
watch_enable_analog_input(THERMISTOR_SENSE_PIN);
HAL_GPIO_TEMPSENSE_in();
HAL_GPIO_TEMPSENSE_pmuxen(HAL_GPIO_PMUX_ADC);
// Enable digital output on the enable pin, which is the power to the thermistor circuit.
watch_enable_digital_output(THERMISTOR_ENABLE_PIN);
HAL_GPIO_TS_ENABLE_out();
// and make sure it's off.
watch_set_pin_level(THERMISTOR_ENABLE_PIN, !THERMISTOR_ENABLE_VALUE);
HAL_GPIO_TS_ENABLE_write(!THERMISTOR_ENABLE_VALUE);
}

void thermistor_driver_disable(void) {
// Disable the ADC peripheral.
watch_disable_adc();
// Disable analog circuitry on the sense pin to save power.
watch_disable_analog_input(THERMISTOR_SENSE_PIN);
HAL_GPIO_TEMPSENSE_pmuxdis();
HAL_GPIO_TEMPSENSE_off();
// Disable the enable pin's output circuitry.
watch_disable_digital_output(THERMISTOR_ENABLE_PIN);
HAL_GPIO_TS_ENABLE_off();
}
#if __EMSCRIPTEN__
#include <emscripten.h>
Expand All @@ -56,11 +58,11 @@ float thermistor_driver_get_temperature(void)
#else
float thermistor_driver_get_temperature(void) {
// set the enable pin to the level that powers the thermistor circuit.
watch_set_pin_level(THERMISTOR_ENABLE_PIN, THERMISTOR_ENABLE_VALUE);
HAL_GPIO_TS_ENABLE_write(THERMISTOR_ENABLE_VALUE);
// get the sense pin level
uint16_t value = watch_get_analog_pin_level(THERMISTOR_SENSE_PIN);
uint16_t value = watch_get_analog_pin_level(HAL_GPIO_TEMPSENSE_pin());
// and then set the enable pin to the opposite value to power down the thermistor circuit.
watch_set_pin_level(THERMISTOR_ENABLE_PIN, !THERMISTOR_ENABLE_VALUE);
HAL_GPIO_TS_ENABLE_write(!THERMISTOR_ENABLE_VALUE);

return watch_utility_thermistor_temperature(value, THERMISTOR_HIGH_SIDE, THERMISTOR_B_COEFFICIENT, THERMISTOR_NOMINAL_TEMPERATURE, THERMISTOR_NOMINAL_RESISTANCE, THERMISTOR_SERIES_RESISTANCE);
}
Expand Down

0 comments on commit 4933a84

Please sign in to comment.