Skip to content

Commit

Permalink
Working rising edge
Browse files Browse the repository at this point in the history
  • Loading branch information
echavemann committed Dec 9, 2024
1 parent 0dca39f commit 564701d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions include/drivers/captouch_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class CapsenseController {

bool touched;

bool prev_touched;

uint32_t time_test_started;

GPIOPinEvent event;
Expand Down
6 changes: 5 additions & 1 deletion include/drivers/driver_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ enum class DriverCommand {
CAPTOUCH = 5,
};

enum class DriverSubscribe { NOTIFY_BUTTON_PRESS = 0, TIMER_START = 1, NOTIFY_CAPTOUCH = 2 };
enum class DriverSubscribe {
NOTIFY_BUTTON_PRESS = 0,
TIMER_START = 1,
NOTIFY_CAPTOUCH = 2
};

enum class GPIOConfiguration { OUT, IN_NORES, IN_PDR, IN_PUR };

Expand Down
26 changes: 12 additions & 14 deletions src/drivers/captouch_controller.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#include "drivers/captouch_controller.hpp"

#include "config.hpp"
#include "drivers/driver_enums.hpp"
#include "drivers/gpio_pin_event.hpp"
#include "drivers/virtual_timer_controller.hpp"
#include "hal/gpio_wrapper.hpp"
#include "hal/hal_enums.hpp"
#include "microbit_v2.h"
#include "nrf_gpio.h"
#include "userlib/syscalls.hpp"

namespace edge::drivers {

CapsenseController::CapsenseController() :
touched(false),
touched(false), prev_touched(false),
event{
TOUCH_LOGO, GPIOConfiguration::IN_NORES,
aidan::GPIOEventController::GPIOEventCallback::create<
Expand Down Expand Up @@ -47,6 +40,7 @@ bool CapsenseController::get_captouch_pressed()

void CapsenseController::handle_gpio_interrupt(nrf_gpio_pin_sense_t sense, int pin)
{
prev_touched = touched;
if (sense == NRF_GPIO_PIN_SENSE_LOW) {
touched = true;
}
Expand All @@ -56,13 +50,17 @@ void CapsenseController::handle_gpio_interrupt(nrf_gpio_pin_sense_t sense, int p
else {
printf("Unexpected cap sense pin sense\n");
}
for (int process_id = 0; process_id < MAX_PROCESSES; ++process_id)
{
if (subscriptions.has_callback(process_id))
{
subscriptions.call_callback(process_id, static_cast<int>(sense), static_cast<int>(pin));
}
if ((prev_touched == false) && (touched == true)) {
printf("Detected change in touch.\n");
}
/* for (int process_id = 0; process_id < MAX_PROCESSES; ++process_id) */
/* { */
/* if (subscriptions.has_callback(process_id)) */
/* { */
/* subscriptions.call_callback(process_id, static_cast<int>(sense),
* static_cast<int>(pin)); */
/* } */
/* } */
}

} // namespace edge::drivers
1 change: 0 additions & 1 deletion src/user_programs/user_program_captouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ void captouch_task(void)
else {
edge::userlib::debug_print("not pressed\n");
}
edge::userlib::yield();
}
}
1 change: 0 additions & 1 deletion src/userlib/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ void USER_CODE subscribe_captouch_pressed(void (*callback)(int, int))
SET_REGISTER(r0, (int)drivers::DriverSubscribe::NOTIFY_CAPTOUCH);
SET_REGISTER(r1, (int)callback);
TRIGGER_SVC(SystemCallType::SUBSCRIBE);

}

int USER_CODE get_time_us()
Expand Down

0 comments on commit 564701d

Please sign in to comment.