[add] added new hal level led/can
This commit is contained in:
36
interfaces/can/can_if.c
Normal file
36
interfaces/can/can_if.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "can_if.h"
|
||||
|
||||
static const can_ops_t *g_can_ops = 0;
|
||||
|
||||
void can_register_ops(const can_ops_t *ops)
|
||||
{
|
||||
g_can_ops = ops;
|
||||
}
|
||||
|
||||
int can_if_init(void)
|
||||
{
|
||||
if (!g_can_ops || !g_can_ops->init)
|
||||
return -1;
|
||||
return g_can_ops->init();
|
||||
}
|
||||
|
||||
int can_if_send(const can_message_t *msg)
|
||||
{
|
||||
if (!g_can_ops || !g_can_ops->send)
|
||||
return -1;
|
||||
return g_can_ops->send(msg);
|
||||
}
|
||||
|
||||
int can_if_recv(can_message_t *msg)
|
||||
{
|
||||
if (!g_can_ops || !g_can_ops->recv)
|
||||
return -1;
|
||||
return g_can_ops->recv(msg);
|
||||
}
|
||||
|
||||
int can_if_filter_config(uint8_t filter_id, uint32_t id, uint32_t mask)
|
||||
{
|
||||
if (!g_can_ops || !g_can_ops->filter_config)
|
||||
return -1;
|
||||
return g_can_ops->filter_config(filter_id, id, mask);
|
||||
}
|
||||
28
interfaces/can/can_if.h
Normal file
28
interfaces/can/can_if.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef CAN_IF_H
|
||||
#define CAN_IF_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t id; // CAN ID
|
||||
uint8_t data[8]; // CAN 数据
|
||||
uint8_t length; // 数据长度 (0-8)
|
||||
} can_message_t;
|
||||
|
||||
typedef struct {
|
||||
int (*init)(void);
|
||||
int (*send)(const can_message_t *msg);
|
||||
int (*recv)(can_message_t *msg);
|
||||
int (*filter_config)(uint8_t filter_id, uint32_t id, uint32_t mask);
|
||||
} can_ops_t;
|
||||
|
||||
// 注册接口(由 HAL 调用)
|
||||
void can_register_ops(const can_ops_t *ops);
|
||||
|
||||
// 对上层暴露统一 API
|
||||
int can_if_init(void);
|
||||
int can_if_send(const can_message_t *msg);
|
||||
int can_if_recv(can_message_t *msg);
|
||||
int can_if_filter_config(uint8_t filter_id, uint32_t id, uint32_t mask);
|
||||
|
||||
#endif
|
||||
36
interfaces/led/led_if.c
Normal file
36
interfaces/led/led_if.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "led_if.h"
|
||||
|
||||
static const led_ops_t *g_led_ops = 0;
|
||||
|
||||
void led_register_ops(const led_ops_t *ops)
|
||||
{
|
||||
g_led_ops = ops;
|
||||
}
|
||||
|
||||
int led_if_init(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->init)
|
||||
return -1;
|
||||
return g_led_ops->init(id);
|
||||
}
|
||||
|
||||
int led_if_write(int id, int state)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->write)
|
||||
return -1;
|
||||
return g_led_ops->write(id, state);
|
||||
}
|
||||
|
||||
int led_if_read(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->read)
|
||||
return -1;
|
||||
return g_led_ops->read(id);
|
||||
}
|
||||
|
||||
int led_if_toggle(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->toggle)
|
||||
return -1;
|
||||
return g_led_ops->toggle(id);
|
||||
}
|
||||
20
interfaces/led/led_if.h
Normal file
20
interfaces/led/led_if.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef LED_IF_H
|
||||
#define LED_IF_H
|
||||
|
||||
typedef struct {
|
||||
int (*init)(int id);
|
||||
int (*write)(int id, int state);
|
||||
int (*read)(int id);
|
||||
int (*toggle)(int id);
|
||||
} led_ops_t;
|
||||
|
||||
// 注册接口(由HAL调用)
|
||||
void led_register_ops(const led_ops_t *ops);
|
||||
|
||||
// 对上层暴露统一API
|
||||
int led_if_init(int id);
|
||||
int led_if_write(int id, int state);
|
||||
int led_if_read(int id);
|
||||
int led_if_toggle(int id);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user