XCORE SDK
XCORE Software Development Kit
device_control_host.h
1 // Copyright 2016-2021 XMOS LIMITED.
2 // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 #ifndef __control_host_h__
4 #define __control_host_h__
5 
6 #include "device_control_shared.h"
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #if USE_I2C && __xcore__
13 #include "i2c.h"
14 #include <xccompat.h>
15 #endif
16 
24 // #if USE_SPI
25 // /* Taken from spi.h in lib_spi. Not included as it's an XC header */
26 // /* TODO: Wrap spi.h in #ifdef __XC__ */
27 // typedef enum spi_mode_t {
28 // SPI_MODE_0, /**< SPI Mode 0 - Polarity = 0, Clock Edge = 1 */
29 // SPI_MODE_1, /**< SPI Mode 1 - Polarity = 0, Clock Edge = 0 */
30 // SPI_MODE_2, /**< SPI Mode 2 - Polarity = 1, Clock Edge = 0 */
31 // SPI_MODE_3, /**< SPI Mode 3 - Polarity = 1, Clock Edge = 1 */
32 // } spi_mode_t;
33 // #endif
34 
35 // #if USE_XSCOPE || __DOXYGEN__
36 // /** Initialize the xscope host interface
37 // *
38 // * \param host_str String containing the name of the xscope host. Eg. "localhost"
39 // * \param port_str String containing the port number of the xscope host
40 // *
41 // * \returns Whether the initialization was successful or not
42 // */
43 // control_ret_t control_init_xscope(const char *host_str, const char *port_str);
44 // /** Shutdown the xscope host interface
45 // *
46 // * \returns Whether the shutdown was successful or not
47 // */
48 // control_ret_t control_cleanup_xscope(void);
49 // #endif
50 
51 // #if USE_SPI || __DOXYGEN__
52 // #if RPI
53 // #include "bcm2835.h"
54 // /** Initialize the SPI host (master) interface for the Raspberry Pi
55 // *
56 // * \param spi_mode Mode that the SPI will run in
57 // * \param clock_divider The amount to divide the Raspberry Pi's clock by, e.g.
58 // * BCM2835_SPI_CLOCK_DIVIDER_1024 gives a clock of ~122kHz
59 // * on the RPI 2.
60 // * \param delay_for_read Delay between send and recieve for read command
61 // *
62 // * \returns Whether the initialization was successful or not
63 // */
64 // control_ret_t control_init_spi_pi(spi_mode_t spi_mode, bcm2835SPIClockDivider clock_divider, unsigned delay_for_read);
65 // #else
66 // /** Initialize the SPI host (master) interface
67 // *
68 // * \param spi_mode Mode that the SPI will run in
69 // * \param spi_bitrate Bitrate for SPI to run at
70 // * \param delay_for_read Delay between send and recieve for read command
71 // *
72 // * \returns Whether the initialization was successful or not
73 // */
74 // control_ret_t control_init_spi(spi_mode_t spi_mode, int spi_bitrate, unsigned delay_for_read);
75 // #endif // RPI
76 // /** Shutdown the SPI host (master) interface connection
77 // *
78 // * \returns Whether the shutdown was successful or not
79 // */
80 // control_ret_t control_cleanup_spi(void);
81 // #endif
82 
83 #if USE_I2C || __DOXYGEN__
90 control_ret_t control_init_i2c(unsigned char i2c_slave_address);
96 #endif
97 #if USE_USB || __DOXYGEN__
106 control_ret_t control_init_usb(int vendor_id, int product_id, int interface_num);
112 #endif
113 
114 //#if (!USE_USB && !USE_XSCOPE && !USE_I2C && !USE_SPI)
115 #if (!USE_USB && !USE_I2C)
116 #error "Please specify transport for device control using USE_xxx define in build file"
117 #error "Eg. -DUSE_I2C=1 or -DUSE_USB=1"
118 #endif
119 
120 #if USE_I2C && __xcore__
128 control_ret_t control_query_version(control_version_t *version,
129  CLIENT_INTERFACE(i2c_master_if, i_i2c));
130 #else
137 control_ret_t control_query_version(control_version_t *version);
138 #endif
139 
152 control_write_command(control_resid_t resid, control_cmd_t cmd,
153 #if USE_I2C && __xcore__
154  CLIENT_INTERFACE(i2c_master_if, i_i2c),
155 #endif
156  const uint8_t payload[], size_t payload_len);
157 
170 control_read_command(control_resid_t resid, control_cmd_t cmd,
171 #if USE_I2C && __xcore__
172  CLIENT_INTERFACE(i2c_master_if, i_i2c),
173 #endif
174  uint8_t payload[], size_t payload_len);
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
182 #endif // __control_host_h__
control_ret_t control_cleanup_usb(void)
control_ret_t control_init_i2c(unsigned char i2c_slave_address)
control_ret_t control_read_command(control_resid_t resid, control_cmd_t cmd, uint8_t payload[], size_t payload_len)
control_ret_t control_cleanup_i2c(void)
control_ret_t control_init_usb(int vendor_id, int product_id, int interface_num)
control_ret_t control_write_command(control_resid_t resid, control_cmd_t cmd, const uint8_t payload[], size_t payload_len)
control_ret_t control_query_version(control_version_t *version)
uint8_t control_resid_t
Definition: device_control_shared.h:27
control_ret_t
Definition: device_control_shared.h:36