spi.h
浏览该文件的文档.
1 /*
2  * Copyright (C) 2020-2021 Alibaba Group Holding Limited
3  */
4 
5 #ifndef AOS_SPI_H
6 #define AOS_SPI_H
7 
8 #include <aos/device.h>
9 
18 #define AOS_SPI_MCFG_MODE_MASK ((uint32_t)0x3 << 0)
19 #define AOS_SPI_MCFG_MODE_0 ((uint32_t)0x0 << 0)
20 #define AOS_SPI_MCFG_MODE_1 ((uint32_t)0x1 << 0)
21 #define AOS_SPI_MCFG_MODE_2 ((uint32_t)0x2 << 0)
22 #define AOS_SPI_MCFG_MODE_3 ((uint32_t)0x3 << 0)
23 #define AOS_SPI_MCFG_WIDTH_MASK ((uint32_t)0x3 << 2)
24 #define AOS_SPI_MCFG_WIDTH_1 ((uint32_t)0x0 << 2)
25 #define AOS_SPI_MCFG_WIDTH_2 ((uint32_t)0x1 << 2)
26 #define AOS_SPI_MCFG_WIDTH_4 ((uint32_t)0x2 << 2)
27 #define AOS_SPI_MCFG_WIDTH_8 ((uint32_t)0x3 << 2)
28 #define AOS_SPI_MCFG_MSB_FIRST ((uint32_t)0x0 << 4)
29 #define AOS_SPI_MCFG_LSB_FIRST ((uint32_t)0x1 << 4)
30 
31 typedef aos_dev_ref_t aos_spi_ref_t;
32 
33 typedef struct {
34  uint32_t cfg;
35  uint32_t cs;
36  uint32_t hz;
37  uint32_t pre_cs;
38  uint32_t post_cs;
39  uint32_t pre_clk;
40  uint32_t post_clk;
41  size_t count;
42  void *rx_buf;
43  const void *tx_buf;
45 
46 #define AOS_SPI_MSG_INIT_VAL \
47  { \
48  .cfg = 0, \
49  .cs = 0, \
50  .hz = 0, \
51  .pre_cs = 0, \
52  .post_cs = 0, \
53  .pre_clk = 0, \
54  .post_clk = 0, \
55  .count = 0, \
56  .rx_buf = NULL, \
57  .tx_buf = NULL, \
58  }
59 
60 #define aos_spi_msg_init(x) do { *(x) = (aos_spi_msg_t)AOS_SPI_MSG_INIT_VAL; } while (0)
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
86 aos_status_t aos_spi_transfer(aos_spi_ref_t *ref, const aos_spi_msg_t *msgs, size_t num_msgs);
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
94 #endif /* AOS_SPI_H */
int32_t aos_status_t
Definition: kernel.h:185
void aos_spi_put(aos_spi_ref_t *ref)
Release a SPI device.
aos_status_t aos_spi_get(aos_spi_ref_t *ref, uint32_t id)
Get a SPI device.
aos_dev_ref_t aos_spi_ref_t
Definition: spi.h:31
aos_status_t aos_spi_transfer(aos_spi_ref_t *ref, const aos_spi_msg_t *msgs, size_t num_msgs)
Synchronous SPI data transfer.
uint32_t post_cs
Definition: spi.h:38
uint32_t hz
Definition: spi.h:36
uint32_t pre_clk
Definition: spi.h:39
uint32_t pre_cs
Definition: spi.h:37
uint32_t cfg
Definition: spi.h:34
size_t count
Definition: spi.h:41
uint32_t cs
Definition: spi.h:35
void * rx_buf
Definition: spi.h:42
const void * tx_buf
Definition: spi.h:43
uint32_t post_clk
Definition: spi.h:40