Skip to content

Commit

Permalink
Almost working
Browse files Browse the repository at this point in the history
  • Loading branch information
echavemann committed Nov 26, 2024
1 parent 021787e commit 4c5cb2e
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 16 deletions.
3 changes: 3 additions & 0 deletions external/nrf52x-base/make/Configuration.mk
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ override CXXFLAGS += \
-DETL_NO_STL \
-Wall \
-Wextra \
-fno-exceptions \
-fno-unwind-tables \
-fno-asynchronous-unwind-tables \
-Wno-date-time \
-Wno-unused-parameter \
-Werror=return-type \
Expand Down
14 changes: 9 additions & 5 deletions include/drivers/capsense_driver.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# pragma once
#pragma once

#include "config.hpp"
#include "drivers/driver_enums.hpp"
#include "drivers/gpio_pin.hpp"
#include "drivers/gpio_pin_event.hpp"
#include "microbit_v2.h"
#include "app_timer.h"
#include "nrfx_timer.h"
#include "nrf_gpio.h"
#include "util.hpp"

Expand All @@ -13,7 +16,10 @@ class CapsenseController {
GPIOPin touch_logo{TOUCH_LOGO, GPIOConfiguration::IN_NORES};

etl::array<ProcessCallbackPtr, MAX_PROCESSES> subscriptions;
bool touched = false;

bool touched;

GPIOPinEvent event;

CapsenseController();
~CapsenseController() = default;
Expand All @@ -30,9 +36,7 @@ class CapsenseController {

bool get_captouch_pressed();

void handle_gpio_interrupt(nrf_gpio_pin_sense_t sense);

void handle_timer_interrupt(nrf_timer_event_t event, void* context);
void handle_gpio_interrupt(nrf_gpio_pin_sense_t sense, int pin);

};

Expand Down
2 changes: 1 addition & 1 deletion include/drivers/gpio_pin_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GPIOPinEvent {
{
// TODO: add resistance
aidan::GPIOEventController::get().set_gpio_callback(
pin, aidan::PinPullMode::PUR, callback
pin, aidan::PinPullMode::NONE, callback
);
}

Expand Down
2 changes: 2 additions & 0 deletions include/userlib/syscalls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void get_button_pressed(
void (*callback)(drivers::ButtonType, drivers::ButtonState)
);

bool get_captouch_pressed();

void send_ipc(const char* name, uint32_t message);

void subscribe_ipc(const char* name, void (*callback)(int message));
Expand Down
24 changes: 18 additions & 6 deletions src/drivers/captouch_driver.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#include "drivers/driver_enums.hpp"
#include "drivers/driver_enums.hpp"
#include "drivers/capsense_driver.hpp"
#include "drivers/gpio_pin_event.hpp"
#include "hal/gpio_wrapper.hpp"
#include "hal/hal_enums.hpp"
#include "microbit_v2.h"
#include "userlib/syscalls.hpp"

namespace edge::drivers {

CapsenseController::CapsenseController() :
touched(false),
event{
TOUCH_LOGO, GPIOConfiguration::IN_NORES,
aidan::GPIOEventController::GPIOEventCallback::create<
CapsenseController, &CapsenseController::handle_gpio_interrupt>(*this)
}
{
aidan::clear_gpio_pin(TOUCH_LOGO);
};

CapsenseController& CapsenseController::get()
{
static CapsenseController capsenseController;
Expand All @@ -21,13 +37,9 @@ bool CapsenseController::get_captouch_pressed()
return touched;
}

void CapsenseController::handle_gpio_interrupt(nrf_gpio_pin_sense_t sense)
{
touched = true;
}

void CapsenseController::handle_timer_interrupt(nrf_timer_event_t event, void* context)
void CapsenseController::handle_gpio_interrupt(nrf_gpio_pin_sense_t sense, int pin)
{
printf("interrupt?");
touched = false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/drivers/driver_commands.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "drivers/driver_commands.hpp"

#include "drivers/button_driver.hpp"
#include "drivers/capsense_driver.hpp"
#include "drivers/driver_enums.hpp"
#include "drivers/led_display.hpp"
#include "drivers/timer.hpp"
Expand Down Expand Up @@ -31,7 +32,7 @@ etl::optional<int> handle_command(DriverCommand type, int arg1, int arg2, int ar
static_cast<ButtonType>(arg1)
);
case DriverCommand::CAPTOUCH:
break;
return CapsenseController::get().get_captouch_pressed();
}
return etl::nullopt;
}
Expand Down
8 changes: 5 additions & 3 deletions src/entrypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
extern void ipc_part1(void);
extern void ipc_part2(void);
extern void exception_task(void);
extern void captouch_task(void);

int main(void)
{
printf("Starting EdgeOS\n");

edge::FaultHandler::get();

edge::scheduler.add_task(exception_task);
/* edge::scheduler.add_task(exception_task); */
edge::scheduler.add_task(captouch_task);

edge::scheduler.add_task(ipc_part1);
edge::scheduler.add_task(ipc_part2);
/* edge::scheduler.add_task(ipc_part1); */
/* edge::scheduler.add_task(ipc_part2); */

edge::scheduler.start_scheduler();
}
22 changes: 22 additions & 0 deletions src/user_programs/user_program_captouch.cpp
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"); */
}


}


}
7 changes: 7 additions & 0 deletions src/userlib/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ bool USER_CODE get_button_pressed(drivers::ButtonType button_type)
RETURN_REGISTER(r0);
}

bool USER_CODE get_captouch_pressed()
{
SET_REGISTER(r0, (int)drivers::DriverCommand::CAPTOUCH);
TRIGGER_SVC(SystemCallType::COMMAND);
RETURN_REGISTER(r0);
}

int USER_CODE get_time_us()
{
SET_REGISTER(r0, (int)drivers::DriverCommand::GET_TIME);
Expand Down

0 comments on commit 4c5cb2e

Please sign in to comment.