Skip to content

Commit

Permalink
update pp2ic driver
Browse files Browse the repository at this point in the history
  • Loading branch information
htotoo committed Oct 20, 2024
1 parent 6fe3223 commit 006cc7a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
9 changes: 9 additions & 0 deletions Source/main/ppi2c/pp_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,13 @@ bool PPHandler::add_app(uint8_t *binary, uint32_t size)

app_list.push_back({binary, size});
return true;
}

void PPHandler::add_custom_command(uint16_t command, pp_i2c_command got_command, pp_i2c_command send_command)
{
pp_custom_command_list_element_t element;
element.command = command;
element.got_command = got_command;
element.send_command = send_command;
custom_command_list.push_back(element);
}
15 changes: 9 additions & 6 deletions Source/main/ppi2c/pp_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@
#include <algorithm>
#include "driver/i2c.h"

/*
All callbasck are from IRQ, so a lot of things won't work from it. Also the code needs to be as fast as possible.
*/
class PPHandler
{
public:
static void init(gpio_num_t scl, gpio_num_t sda, uint8_t addr_);
static void set_module_name(std::string name); // this will set the module name
static void set_module_version(uint32_t version); // this will set the module version

static void set_get_features_CB(get_features_CB cb); // this will be called to get the features of the module see SupportedFeatures
static void set_get_gps_data_CB(get_gps_data_CB cb); // this will be called when the module asked for gps data
static void set_get_orientation_data_CB(get_orientation_data_CB cb); // this will be called when the module asked for orientation data
static void set_get_environment_data_CB(get_environment_data_CB cb); // this will be called when the module asked for environment data
static void set_get_light_data_CB(get_light_data_CB cb); // this will be called when the module asked for light data
static void set_get_features_CB(get_features_CB cb); // IRQ CALLBACK! this will be called to get the features of the module see SupportedFeatures
static void set_get_gps_data_CB(get_gps_data_CB cb); // IRQ CALLBACK! this will be called when the module asked for gps data
static void set_get_orientation_data_CB(get_orientation_data_CB cb); // IRQ CALLBACK! this will be called when the module asked for orientation data
static void set_get_environment_data_CB(get_environment_data_CB cb); // IRQ CALLBACK! this will be called when the module asked for environment data
static void set_get_light_data_CB(get_light_data_CB cb); // IRQ CALLBACK! this will be called when the module asked for light data

static uint32_t get_appCount(); // this will return the app count
static bool add_app(uint8_t *binary, uint32_t size); // this will add an app to the module.app size must be %32 == 0

static void add_cutsom_command(pp_custom_command_list_element_t element); // this will add a custom command to the module, see pp_custom_command_list_element_t!
static void add_custom_command(uint16_t command, pp_i2c_command got_command, pp_i2c_command send_command); // Callbacks are from IRQ! This will add a custom command to the module, see pp_custom_command_list_element_t!

private:
// base working code
Expand Down
15 changes: 3 additions & 12 deletions Source/main/ppi2c/pp_structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ typedef struct
uint32_t binary_size;
} standalone_app_info;

#define USER_COMMANDS_START 0x7F01

enum class Command : uint16_t
{
COMMAND_NONE = 0,
Expand All @@ -106,12 +104,6 @@ enum class Command : uint16_t
COMMAND_GETFEAT_DATA_ORIENTATION,
COMMAND_GETFEAT_DATA_ENVIRONMENT,
COMMAND_GETFEAT_DATA_LIGHT,
// UART specific commands
COMMAND_UART_REQUESTDATA_SHORT = USER_COMMANDS_START,
COMMAND_UART_REQUESTDATA_LONG,
COMMAND_UART_BAUDRATE_INC,
COMMAND_UART_BAUDRATE_DEC,
COMMAND_UART_BAUDRATE_GET,

};

Expand All @@ -132,14 +124,13 @@ typedef struct
std::vector<uint8_t> *data;
} pp_command_data_t;

typedef void (*pp_got_command)(pp_command_data_t data);
typedef void (*pp_send_command)(pp_command_data_t data);
typedef void (*pp_i2c_command)(pp_command_data_t data);

typedef struct
{
uint16_t command;
pp_got_command got_command;
pp_send_command send_command;
pp_i2c_command got_command;
pp_i2c_command send_command;
} pp_custom_command_list_element_t;

#endif

0 comments on commit 006cc7a

Please sign in to comment.