-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
021787e
commit 9b5a5ce
Showing
11 changed files
with
173 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "drivers/driver_enums.hpp" | ||
#include "hal/gpio_wrapper.hpp" | ||
#include "userlib/syscalls.hpp" | ||
|
||
void captouch_task(void) | ||
{ | ||
while (1) | ||
{ | ||
if (edge::userlib::get_captouch_pressed()) | ||
{ | ||
/* edge::userlib::debug_print("pressed\n"); */ | ||
} | ||
else | ||
{ | ||
/* edge::userlib::debug_print("not pressed"); */ | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "drivers/timer2.hpp" | ||
|
||
extern "C" { | ||
void TIMER3_IRQHandler(void) | ||
{ | ||
printf("Interrupt!\n"); | ||
using edge::timer3_controller; | ||
|
||
switch (timer3_controller.event_triggered_()) { | ||
case timer3_controller.GET_TIME: | ||
printf("FATAL: GET_TIME register incorrectly triggered callback\n"); | ||
timer3_controller.clear_event_(timer3_controller.GET_TIME); | ||
break; | ||
case timer3_controller.CLOCK_OVERFLOW: | ||
printf( | ||
"Clock overflow detected. Count: %lu\n", timer3_controller.clock_wraps_ | ||
); | ||
timer3_controller.mark_clock_wrapped(); | ||
timer3_controller.clear_event_(timer3_controller.CLOCK_OVERFLOW); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
namespace edge { | ||
Timer3Controller timer3_controller; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#pragma once | ||
|
||
#include "nrf52833.h" | ||
#include "nrf_timer.h" | ||
|
||
extern "C" { | ||
void TIMER3_IRQHandler(void); | ||
} | ||
|
||
namespace edge { | ||
|
||
// Reserves timer 4 | ||
class Timer3Controller { | ||
enum CallbackType : uint8_t { GET_TIME = 0, CLOCK_OVERFLOW = 1 }; | ||
|
||
inline static NRF_TIMER_Type* const TIMER = NRF_TIMER4; | ||
static constexpr nrf_timer_frequency_t TIMER_FREQUENCY = NRF_TIMER_FREQ_16MHz; | ||
static constexpr auto OVERFLOW_CYCLES = UINT_MAX; | ||
|
||
uint32_t clock_wraps_; | ||
|
||
public: | ||
uint32_t get_time_us() | ||
{ | ||
nrf_timer_task_trigger(TIMER, NRF_TIMER_TASK_CAPTURE0); | ||
return nrf_timer_cc_read(TIMER, NRF_TIMER_CC_CHANNEL0) / 16; | ||
} | ||
|
||
Timer3Controller() { initialize_timer_(); } | ||
|
||
private: | ||
static CallbackType event_triggered_() | ||
{ | ||
if (nrf_timer_event_check(TIMER, NRF_TIMER_EVENT_COMPARE0)) [[unlikely]] { | ||
return GET_TIME; | ||
} | ||
else if (nrf_timer_event_check(TIMER, NRF_TIMER_EVENT_COMPARE1)) { | ||
return CLOCK_OVERFLOW; | ||
} | ||
else { | ||
printf("FATAL: event_triggered called but no event detected"); | ||
NVIC_SystemReset(); | ||
} | ||
} | ||
|
||
static void clear_event_(CallbackType type) | ||
{ | ||
switch (type) { | ||
case GET_TIME: | ||
nrf_timer_event_clear(TIMER, NRF_TIMER_EVENT_COMPARE0); | ||
break; | ||
case CLOCK_OVERFLOW: | ||
nrf_timer_event_clear(TIMER, NRF_TIMER_EVENT_COMPARE1); | ||
break; | ||
} | ||
} | ||
|
||
static void initialize_timer_() | ||
{ | ||
// High frequency timer | ||
nrf_timer_frequency_set(TIMER, TIMER_FREQUENCY); | ||
nrf_timer_mode_set(TIMER, NRF_TIMER_MODE_TIMER); | ||
nrf_timer_bit_width_set(TIMER, NRF_TIMER_BIT_WIDTH_32); | ||
nrf_timer_task_trigger(TIMER, NRF_TIMER_TASK_START); | ||
|
||
NVIC_EnableIRQ(TIMER4_IRQn); | ||
nrf_timer_cc_write(TIMER, NRF_TIMER_CC_CHANNEL1, OVERFLOW_CYCLES); | ||
nrf_timer_int_enable(TIMER, NRF_TIMER_INT_COMPARE1_MASK); | ||
} | ||
|
||
void mark_clock_wrapped() { clock_wraps_++; } | ||
|
||
friend void ::TIMER3_IRQHandler(void); | ||
}; | ||
|
||
extern Timer3Controller timer4_controller; | ||
} // namespace edge |