一点五编程 硬件平台实现
在硬件实现层io_led.h中添加device结构体 用于平台层接口
typedef int (*io_led_write_pin_fn_t)(void *self,char io_level);
typedef int (*io_led_read_pin_fn_t)(void *self);
struct io_led_i
{
io_led_write_pin_fn_t io_led_write_pin;
io_led_read_pin_fn_t io_led_read_pin;
};
例如io_led中添加io_led_i结构体 lsd中添加lsd_i结构体 iic_led中添加iic_led_i结构体
结构体内是对应的硬件操作 如io_led_i中进行io口电平设置
iic_led_i中进行iic_writeh_byte和iic_read_byte操作
创建好之后 将其添加进硬件实现结构体中
struct io_led
{
struct light_i* interface;
struct io_led_i** device;
int status;
const char *name;
};
创建后进行封装
static inline int io_led_write_pin(void *self,char io_level)
{
return (*(struct io_led_i **)self)->io_led_write_pin(self, io_level);
}
static inline int io_led_read_pin(void *self)