Skip to content

Commit

Permalink
Merge pull request #27 from xrobot-org/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Jiu-xiao authored Jul 31, 2023
2 parents a8e6bb7 + d3abe5e commit c5e3d5c
Show file tree
Hide file tree
Showing 114 changed files with 718 additions and 454 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,3 @@
[submodule "lib/magic_enum"]
path = lib/magic_enum
url = https://github.com/Neargye/magic_enum.git
[submodule "hw/mcu/esp/ESP32_BleSerial"]
path = hw/mcu/esp/ESP32_BleSerial
url = https://github.com/avinabmalla/ESP32_BleSerial.git
2 changes: 1 addition & 1 deletion hw/bsp/MiniPC/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_library(${PROJECT_NAME} STATIC)

target_sources(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_SOURCES})

include(${MCU_DIR}/default/CMakeLists.txt)
include(${MCU_DIR}/linux/driver/CMakeLists.txt)

target_link_libraries(
${PROJECT_NAME}
Expand Down
1 change: 1 addition & 0 deletions hw/bsp/MiniPC/drivers/bsp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "bsp.h"

#include "bsp_time.h"
#include "bsp_wifi_client.h"

void bsp_init() { bsp_time_init(); }
3 changes: 2 additions & 1 deletion hw/bsp/MiniPC/drivers/bsp_dns_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

#include "bsp.h"

int8_t bsp_dns_prase_domain(const char* domain_name, bsp_dns_addr_t* result) {
bsp_status_t bsp_dns_prase_domain(const char* domain_name,
bsp_dns_addr_t* result) {
struct addrinfo hints;
struct addrinfo* tmp = NULL;

Expand Down
3 changes: 2 additions & 1 deletion hw/bsp/MiniPC/drivers/bsp_dns_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ extern "C" {

typedef char bsp_dns_addr_t[INET_ADDRSTRLEN];

int8_t bsp_dns_prase_domain(const char* domain_name, bsp_dns_addr_t* result);
bsp_status_t bsp_dns_prase_domain(const char* domain_name,
bsp_dns_addr_t* result);

#ifdef __cplusplus
}
Expand Down
8 changes: 4 additions & 4 deletions hw/bsp/MiniPC/drivers/bsp_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#include <stdlib.h>

inline int8_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value) {
inline bsp_status_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value) {
(void)gpio;

if (value) {
if (!system("spd-say -r 100 -p 100 -R 100 滴")) {
return BSP_OK;
}
// if (!system("spd-say -r 100 -p 100 -R 100 滴")) {
// return BSP_OK;
// }
}

return BSP_ERR;
Expand Down
2 changes: 1 addition & 1 deletion hw/bsp/MiniPC/drivers/bsp_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef enum {
BSP_GPIO_NUM,
} bsp_gpio_t;

int8_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value);
bsp_status_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value);

#ifdef __cplusplus
}
Expand Down
11 changes: 6 additions & 5 deletions hw/bsp/MiniPC/drivers/bsp_udp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include <assert.h>
#include <hv/hloop.h>

int8_t bsp_udp_client_start(bsp_udp_client_t *udp) {
bsp_status_t bsp_udp_client_start(bsp_udp_client_t *udp) {
hio_read(udp->io);
hloop_run(udp->loop);
hloop_free(&udp->loop);

return BSP_OK;
}

int8_t bsp_udp_client_init(bsp_udp_client_t *udp, int port, const char *addr) {
bsp_status_t bsp_udp_client_init(bsp_udp_client_t *udp, int port,
const char *addr) {
udp->loop = hloop_new(0);
udp->io = hloop_create_udp_client(udp->loop, addr, port);

Expand Down Expand Up @@ -42,7 +43,7 @@ static void bsp_udp_tx_cb(hio_t *io, const void *buf, int readbytes) {
}
}

int8_t bsp_udp_client_register_callback(
bsp_status_t bsp_udp_client_register_callback(
bsp_udp_client_t *udp, bsp_udp_client_callback_t type,
void (*callback)(void *, void *, uint32_t), void *callback_arg) {
udp->cb[type].fn = callback;
Expand All @@ -59,8 +60,8 @@ int8_t bsp_udp_client_register_callback(
return BSP_OK;
}

int8_t bsp_udp_client_transmit(bsp_udp_client_t *udp, const uint8_t *data,
uint32_t size) {
bsp_status_t bsp_udp_client_transmit(bsp_udp_client_t *udp, const uint8_t *data,
uint32_t size) {
hio_write(udp->io, data, size);
return BSP_OK;
}
11 changes: 6 additions & 5 deletions hw/bsp/MiniPC/drivers/bsp_udp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ typedef struct {
udp_callback_t cb[BSP_UDP_CLIENT_CB_NUM];
} bsp_udp_client_t;

int8_t bsp_udp_client_init(bsp_udp_client_t* udp, int port, const char* addr);
bsp_status_t bsp_udp_client_init(bsp_udp_client_t* udp, int port,
const char* addr);

int8_t bsp_udp_client_start(bsp_udp_client_t* udp);
bsp_status_t bsp_udp_client_start(bsp_udp_client_t* udp);

int8_t bsp_udp_client_register_callback(
bsp_status_t bsp_udp_client_register_callback(
bsp_udp_client_t* udp, bsp_udp_client_callback_t type,
void (*callback)(void*, void*, uint32_t), void* callback_arg);

int8_t bsp_udp_client_transmit(bsp_udp_client_t* udp, const uint8_t* data,
uint32_t size);
bsp_status_t bsp_udp_client_transmit(bsp_udp_client_t* udp, const uint8_t* data,
uint32_t size);

#ifdef __cplusplus
}
Expand Down
10 changes: 5 additions & 5 deletions hw/bsp/MiniPC/drivers/bsp_udp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#include <assert.h>
#include <hv/hloop.h>

int8_t bsp_udp_server_start(bsp_udp_server_t *udp) {
bsp_status_t bsp_udp_server_start(bsp_udp_server_t *udp) {
hio_read(udp->io);
hloop_run(udp->loop);
hloop_free(&udp->loop);

return BSP_OK;
}

int8_t bsp_udp_server_init(bsp_udp_server_t *udp, int port) {
bsp_status_t bsp_udp_server_init(bsp_udp_server_t *udp, int port) {
udp->loop = hloop_new(0);
udp->io = hloop_create_udp_server(udp->loop, "0.0.0.0", port);

Expand Down Expand Up @@ -42,7 +42,7 @@ static void bsp_udp_tx_cb(hio_t *io, const void *buf, int readbytes) {
}
}

int8_t bsp_udp_server_register_callback(
bsp_status_t bsp_udp_server_register_callback(
bsp_udp_server_t *udp, bsp_udp_server_callback_t type,
void (*callback)(void *, void *, uint32_t), void *callback_arg) {
udp->cb[type].fn = callback;
Expand All @@ -59,8 +59,8 @@ int8_t bsp_udp_server_register_callback(
return BSP_OK;
}

int8_t bsp_udp_server_transmit(bsp_udp_server_t *udp, const uint8_t *data,
uint32_t size) {
bsp_status_t bsp_udp_server_transmit(bsp_udp_server_t *udp, const uint8_t *data,
uint32_t size) {
hio_write(udp->io, data, size);
return BSP_OK;
}
10 changes: 5 additions & 5 deletions hw/bsp/MiniPC/drivers/bsp_udp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ typedef struct {
udp_callback_t cb[BSP_UDP_SERVER_CB_NUM];
} bsp_udp_server_t;

int8_t bsp_udp_server_init(bsp_udp_server_t* udp, int port);
bsp_status_t bsp_udp_server_init(bsp_udp_server_t* udp, int port);

int8_t bsp_udp_server_start(bsp_udp_server_t* udp);
bsp_status_t bsp_udp_server_start(bsp_udp_server_t* udp);

int8_t bsp_udp_server_register_callback(
bsp_status_t bsp_udp_server_register_callback(
bsp_udp_server_t* udp, bsp_udp_server_callback_t type,
void (*callback)(void*, void*, uint32_t), void* callback_arg);

int8_t bsp_udp_server_transmit(bsp_udp_server_t* udp, const uint8_t* data,
uint32_t size);
bsp_status_t bsp_udp_server_transmit(bsp_udp_server_t* udp, const uint8_t* data,
uint32_t size);

#ifdef __cplusplus
}
Expand Down
34 changes: 17 additions & 17 deletions hw/bsp/MiniPC/drivers/bsp_wifi_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
#include <unistd.h>

#include "bsp.h"
#include "bsp_def.h"
#include "bsp_linux_base.h"

static char cmd_buff[100];

void bsp_wifi_client_init() {}

int8_t bsp_wifi_connect(const char *name, const char *password) {
(void)name;
(void)password;
bsp_status_t bsp_wifi_connect(const char *name, const char *password) {
(void)snprintf(cmd_buff, sizeof(cmd_buff), "nmcli con delete %s", name);
(void)system(cmd_buff);
(void)snprintf(cmd_buff, sizeof(cmd_buff),
"nmcli dev wifi connect %s password \"%s\"", name, password);
int ans = system(cmd_buff);

if (-1 == ans) {
"nmcli dev wifi connect %s password \"%s\" name %s", name,
password, name);
if (bsp_shell_success(system(cmd_buff))) {
return BSP_OK;
} else {
return BSP_ERR;
}
}

bsp_status_t bsp_wifi_delete(const char *name) {
(void)snprintf(cmd_buff, sizeof(cmd_buff), "nmcli con del %s", name);
if (bsp_shell_success(system(cmd_buff))) {
return BSP_OK;
} else {
if (WIFEXITED(ans)) {
if (0 == WEXITSTATUS(ans)) {
return BSP_OK;
} else {
return BSP_ERR;
}
} else {
return BSP_ERR;
}
return BSP_ERR;
}
}

bool bsp_wifi_connected() {
int ret = open("/sys/class/net/wlan0/operstate", O_RDONLY);
int ret = open("/sys/class/net/wlp0s20f3/operstate", O_RDONLY);

char status[3] = "wl\0";
(void)read(ret, status, 2);
Expand Down
6 changes: 4 additions & 2 deletions hw/bsp/MiniPC/drivers/bsp_wifi_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
extern "C" {
#endif

#include "bsp.h"
#include "bsp_def.h"

void bsp_wifi_client_init();

int8_t bsp_wifi_connect(const char* name, const char* password);
bsp_status_t bsp_wifi_connect(const char* name, const char* password);

bsp_status_t bsp_wifi_delete(const char* name);

bool bsp_wifi_connected();

Expand Down
2 changes: 1 addition & 1 deletion hw/bsp/Webots/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_library(${PROJECT_NAME} STATIC)

target_sources(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_SOURCES})

include(${MCU_DIR}/default/CMakeLists.txt)
include(${MCU_DIR}/linux/driver/CMakeLists.txt)

target_link_directories(
${PROJECT_NAME}
Expand Down
2 changes: 1 addition & 1 deletion hw/bsp/Webots/drivers/bsp_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

static WbDeviceTag led = 0;

inline int8_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value) {
inline bsp_status_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value) {
(void)gpio;

if (!led) {
Expand Down
2 changes: 1 addition & 1 deletion hw/bsp/Webots/drivers/bsp_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef enum {
BSP_GPIO_NUM,
} bsp_gpio_t;

int8_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value);
bsp_status_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value);

#ifdef __cplusplus
}
Expand Down
16 changes: 8 additions & 8 deletions hw/bsp/c-mini/drivers/bsp_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) {
can_rx_cb_fn(BSP_CAN_2);
}

int8_t bsp_can_register_callback(bsp_can_t can, bsp_can_callback_t type,
void (*callback)(bsp_can_t can, uint32_t id,
uint8_t *data, void *arg),
void *callback_arg) {
bsp_status_t bsp_can_register_callback(
bsp_can_t can, bsp_can_callback_t type,
void (*callback)(bsp_can_t can, uint32_t id, uint8_t *data, void *arg),
void *callback_arg) {
assert_param(callback);
assert_param(type != BSP_CAN_CB_NUM);

Expand All @@ -267,8 +267,8 @@ int8_t bsp_can_register_callback(bsp_can_t can, bsp_can_callback_t type,
return BSP_OK;
}

int8_t bsp_ext_can_trans_packet(bsp_can_t can, bsp_can_format_t format,
uint32_t id, uint8_t *data) {
bsp_status_t bsp_ext_can_trans_packet(bsp_can_t can, bsp_can_format_t format,
uint32_t id, uint8_t *data) {
tx_ext_buff[can - BSP_CAN_BASE_NUM].id = id;
tx_ext_buff[can - BSP_CAN_BASE_NUM].type = format;
memcpy(tx_ext_buff[can - BSP_CAN_BASE_NUM].data, data, 8);
Expand All @@ -283,8 +283,8 @@ int8_t bsp_ext_can_trans_packet(bsp_can_t can, bsp_can_format_t format,
: BSP_ERR;
}

int8_t bsp_can_trans_packet(bsp_can_t can, bsp_can_format_t format, uint32_t id,
uint8_t *data) {
bsp_status_t bsp_can_trans_packet(bsp_can_t can, bsp_can_format_t format,
uint32_t id, uint8_t *data) {
if (can >= BSP_CAN_BASE_NUM) {
return bsp_ext_can_trans_packet(can, format, id, data);
}
Expand Down
14 changes: 7 additions & 7 deletions hw/bsp/c-mini/drivers/bsp_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ typedef enum {
} bsp_can_format_t;

void bsp_can_init(void);
int8_t bsp_can_register_callback(bsp_can_t can, bsp_can_callback_t type,
void (*callback)(bsp_can_t can, uint32_t id,
uint8_t *data, void *arg),
void *callback_arg);
int8_t bsp_can_trans_packet(bsp_can_t can, bsp_can_format_t format, uint32_t id,
uint8_t *data);
int8_t bsp_cantouart_get_msg(bsp_can_t can, uint8_t *data);
bsp_status_t bsp_can_register_callback(
bsp_can_t can, bsp_can_callback_t type,
void (*callback)(bsp_can_t can, uint32_t id, uint8_t *data, void *arg),
void *callback_arg);
bsp_status_t bsp_can_trans_packet(bsp_can_t can, bsp_can_format_t format,
uint32_t id, uint8_t *data);
bsp_status_t bsp_cantouart_get_msg(bsp_can_t can, uint8_t *data);
#ifdef __cplusplus
}
#endif
11 changes: 6 additions & 5 deletions hw/bsp/c-mini/drivers/bsp_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
}
}

int8_t bsp_gpio_register_callback(bsp_gpio_t gpio, void (*callback)(void *),
void *callback_arg) {
bsp_status_t bsp_gpio_register_callback(bsp_gpio_t gpio,
void (*callback)(void *),
void *callback_arg) {
assert_param(callback);

uint16_t pin = bsp_gpio_map[gpio].pin;
Expand All @@ -44,7 +45,7 @@ int8_t bsp_gpio_register_callback(bsp_gpio_t gpio, void (*callback)(void *),
return BSP_ERR;
}

int8_t bsp_gpio_enable_irq(bsp_gpio_t gpio) {
bsp_status_t bsp_gpio_enable_irq(bsp_gpio_t gpio) {
uint16_t pin = bsp_gpio_map[gpio].pin;

switch (pin) {
Expand All @@ -67,7 +68,7 @@ int8_t bsp_gpio_enable_irq(bsp_gpio_t gpio) {
return BSP_OK;
}

int8_t bsp_gpio_disable_irq(bsp_gpio_t gpio) {
bsp_status_t bsp_gpio_disable_irq(bsp_gpio_t gpio) {
uint16_t pin = bsp_gpio_map[gpio].pin;

switch (pin) {
Expand All @@ -90,7 +91,7 @@ int8_t bsp_gpio_disable_irq(bsp_gpio_t gpio) {
return BSP_OK;
}

inline int8_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value) {
inline bsp_status_t bsp_gpio_write_pin(bsp_gpio_t gpio, bool value) {
HAL_GPIO_WritePin(bsp_gpio_map[gpio].gpio, bsp_gpio_map[gpio].pin, value);
return BSP_OK;
}
Expand Down
Loading

0 comments on commit c5e3d5c

Please sign in to comment.