1 /* 2 * Copyright (c) 2006-2023, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2021-10-11 kyle first version 9 * 2022-6-14 solar Remove the const attribute of private data in ops 10 */ 11 12 #ifndef __DEV_SPI_BIT_OPS_H__ 13 #define __DEV_SPI_BIT_OPS_H__ 14 15 #include <rtdevice.h> 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 struct rt_spi_bit_ops 22 { 23 void *data; /* private data for lowlevel routines */ 24 void (*const pin_init)(void); 25 void (*const tog_sclk)(void *data); 26 void (*const set_sclk)(void *data, rt_int32_t state); 27 void (*const set_mosi)(void *data, rt_int32_t state); 28 void (*const set_miso)(void *data, rt_int32_t state); 29 rt_int32_t (*const get_sclk)(void *data); 30 rt_int32_t (*const get_mosi)(void *data); 31 rt_int32_t (*const get_miso)(void *data); 32 33 void (*const dir_mosi)(void *data, rt_int32_t state); 34 void (*const dir_miso)(void *data, rt_int32_t state); 35 36 void (*const udelay)(rt_uint32_t us); 37 rt_uint32_t delay_us; /* sclk, mosi and miso line delay */ 38 }; 39 40 struct rt_spi_bit_obj 41 { 42 struct rt_spi_bus bus; 43 struct rt_spi_bit_ops *ops; 44 struct rt_spi_configuration config; 45 }; 46 47 rt_err_t rt_spi_bit_add_bus(struct rt_spi_bit_obj *obj, 48 const char *bus_name, 49 struct rt_spi_bit_ops *ops); 50 51 #ifdef __cplusplus 52 } 53 #endif 54 55 #endif 56