spi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2013, 2014 Damien P. George
  7. * Copyright (c) 2016 - 2018 Glenn Ruben Bakke
  8. * Copyright (c) 2018 Ayke van Laethem
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. * THE SOFTWARE.
  27. */
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include "py/runtime.h"
  31. #if MICROPY_PY_MACHINE_HW_SPI
  32. #include "py/nlr.h"
  33. #include "py/mphal.h"
  34. #include "extmod/machine_spi.h"
  35. #include "pin.h"
  36. #include "genhdr/pins.h"
  37. #include "spi.h"
  38. #if NRFX_SPI_ENABLED
  39. #include "nrfx_spi.h"
  40. #else
  41. #include "nrfx_spim.h"
  42. #endif
  43. /// \moduleref machine
  44. /// \class SPI - a master-driven serial protocol
  45. ///
  46. /// SPI is a serial protocol that is driven by a master. At the physical level
  47. /// there are 3 lines: SCK, MOSI, MISO.
  48. ///
  49. /// See usage model of I2C; SPI is very similar. Main difference is
  50. /// parameters to init the SPI bus:
  51. ///
  52. /// from machine import SPI
  53. /// spi = SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0, crc=0x7)
  54. ///
  55. /// Only required parameter is mode, SPI.MASTER or SPI.SLAVE. Polarity can be
  56. /// 0 or 1, and is the level the idle clock line sits at. Phase can be 0 or 1
  57. /// to sample data on the first or second clock edge respectively. Crc can be
  58. /// None for no CRC, or a polynomial specifier.
  59. ///
  60. /// Additional method for SPI:
  61. ///
  62. /// data = spi.send_recv(b'1234') # send 4 bytes and receive 4 bytes
  63. /// buf = bytearray(4)
  64. /// spi.send_recv(b'1234', buf) # send 4 bytes and receive 4 into buf
  65. /// spi.send_recv(buf, buf) # send/recv 4 bytes from/to buf
  66. #if NRFX_SPIM_ENABLED
  67. #define nrfx_spi_t nrfx_spim_t
  68. #define nrfx_spi_config_t nrfx_spim_config_t
  69. #define nrfx_spi_xfer_desc_t nrfx_spim_xfer_desc_t
  70. #define NRFX_SPI_PIN_NOT_USED NRFX_SPIM_PIN_NOT_USED
  71. #define NRFX_SPI_INSTANCE NRFX_SPIM_INSTANCE
  72. #define NRF_SPI_BIT_ORDER_LSB_FIRST NRF_SPIM_BIT_ORDER_LSB_FIRST
  73. #define NRF_SPI_BIT_ORDER_MSB_FIRST NRF_SPIM_BIT_ORDER_MSB_FIRST
  74. #define NRF_SPI_MODE_0 NRF_SPIM_MODE_0
  75. #define NRF_SPI_MODE_1 NRF_SPIM_MODE_1
  76. #define NRF_SPI_MODE_2 NRF_SPIM_MODE_2
  77. #define NRF_SPI_MODE_3 NRF_SPIM_MODE_3
  78. #define NRF_SPI_FREQ_125K NRF_SPIM_FREQ_125K
  79. #define NRF_SPI_FREQ_250K NRF_SPIM_FREQ_250K
  80. #define NRF_SPI_FREQ_500K NRF_SPIM_FREQ_500K
  81. #define NRF_SPI_FREQ_1M NRF_SPIM_FREQ_1M
  82. #define NRF_SPI_FREQ_2M NRF_SPIM_FREQ_2M
  83. #define NRF_SPI_FREQ_4M NRF_SPIM_FREQ_4M
  84. #define NRF_SPI_FREQ_8M NRF_SPIM_FREQ_8M
  85. #define nrfx_spi_init nrfx_spim_init
  86. #define nrfx_spi_uninit nrfx_spim_uninit
  87. #define nrfx_spi_xfer nrfx_spim_xfer
  88. #endif // NRFX_SPIM_ENABLED
  89. typedef struct _machine_hard_spi_obj_t {
  90. mp_obj_base_t base;
  91. const nrfx_spi_t * p_spi; // Driver instance
  92. nrfx_spi_config_t * p_config; // pointer to volatile part
  93. } machine_hard_spi_obj_t;
  94. STATIC const nrfx_spi_t machine_spi_instances[] = {
  95. NRFX_SPI_INSTANCE(0),
  96. NRFX_SPI_INSTANCE(1),
  97. #if defined(NRF52_SERIES)
  98. NRFX_SPI_INSTANCE(2),
  99. #if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
  100. NRFX_SPI_INSTANCE(3),
  101. #endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
  102. #endif // NRF52_SERIES
  103. };
  104. STATIC nrfx_spi_config_t configs[MP_ARRAY_SIZE(machine_spi_instances)];
  105. STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
  106. {{&machine_hard_spi_type}, .p_spi = &machine_spi_instances[0], .p_config = &configs[0]},
  107. {{&machine_hard_spi_type}, .p_spi = &machine_spi_instances[1], .p_config = &configs[1]},
  108. #if defined(NRF52_SERIES)
  109. {{&machine_hard_spi_type}, .p_spi = &machine_spi_instances[2], .p_config = &configs[2]},
  110. #if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
  111. {{&machine_hard_spi_type}, .p_spi = &machine_spi_instances[3], .p_config = &configs[3]},
  112. #endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
  113. #endif // NRF52_SERIES
  114. };
  115. void spi_init0(void) {
  116. }
  117. STATIC int spi_find(mp_obj_t id) {
  118. if (MP_OBJ_IS_STR(id)) {
  119. // given a string id
  120. const char *port = mp_obj_str_get_str(id);
  121. if (0) {
  122. #ifdef MICROPY_HW_SPI0_NAME
  123. } else if (strcmp(port, MICROPY_HW_SPI0_NAME) == 0) {
  124. return 1;
  125. #endif
  126. }
  127. nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
  128. "SPI(%s) does not exist", port));
  129. } else {
  130. // given an integer id
  131. int spi_id = mp_obj_get_int(id);
  132. if (spi_id >= 0 && spi_id < MP_ARRAY_SIZE(machine_hard_spi_obj)) {
  133. return spi_id;
  134. }
  135. nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
  136. "SPI(%d) does not exist", spi_id));
  137. }
  138. }
  139. void spi_transfer(const machine_hard_spi_obj_t * self, size_t len, const void * src, void * dest) {
  140. nrfx_spi_xfer_desc_t xfer_desc = {
  141. .p_tx_buffer = src,
  142. .tx_length = len,
  143. .p_rx_buffer = dest,
  144. .rx_length = len
  145. };
  146. nrfx_spi_xfer(self->p_spi, &xfer_desc, 0);
  147. }
  148. /******************************************************************************/
  149. /* MicroPython bindings for machine API */
  150. // for make_new
  151. enum {
  152. ARG_NEW_id,
  153. ARG_NEW_baudrate,
  154. ARG_NEW_polarity,
  155. ARG_NEW_phase,
  156. ARG_NEW_bits,
  157. ARG_NEW_firstbit,
  158. ARG_NEW_sck,
  159. ARG_NEW_mosi,
  160. ARG_NEW_miso
  161. };
  162. // for init
  163. enum {
  164. ARG_INIT_baudrate,
  165. ARG_INIT_polarity,
  166. ARG_INIT_phase,
  167. ARG_INIT_bits,
  168. ARG_INIT_firstbit
  169. };
  170. STATIC mp_obj_t machine_hard_spi_make_new(mp_arg_val_t *args);
  171. STATIC void machine_hard_spi_init(mp_obj_t self, mp_arg_val_t *args);
  172. STATIC void machine_hard_spi_deinit(mp_obj_t self);
  173. /* common code for both soft and hard implementations *************************/
  174. STATIC mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
  175. static const mp_arg_t allowed_args[] = {
  176. { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} },
  177. { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 1000000} },
  178. { MP_QSTR_polarity, MP_ARG_INT, {.u_int = 0} },
  179. { MP_QSTR_phase, MP_ARG_INT, {.u_int = 0} },
  180. { MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
  181. { MP_QSTR_firstbit, MP_ARG_INT, {.u_int = 0 /* SPI_FIRSTBIT_MSB */} },
  182. { MP_QSTR_sck, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
  183. { MP_QSTR_mosi, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
  184. { MP_QSTR_miso, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
  185. };
  186. // parse args
  187. mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
  188. mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
  189. if (args[ARG_NEW_id].u_obj == MP_OBJ_NEW_SMALL_INT(-1)) {
  190. // TODO: implement soft SPI
  191. // return machine_soft_spi_make_new(args);
  192. return mp_const_none;
  193. } else {
  194. // hardware peripheral id given
  195. return machine_hard_spi_make_new(args);
  196. }
  197. }
  198. STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
  199. static const mp_arg_t allowed_args[] = {
  200. { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000000} },
  201. { MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
  202. { MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
  203. { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
  204. { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
  205. };
  206. // parse args
  207. mp_obj_t self = pos_args[0];
  208. mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
  209. mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
  210. // dispatch to specific implementation
  211. if (mp_obj_get_type(self) == &machine_hard_spi_type) {
  212. machine_hard_spi_init(self, args);
  213. }
  214. return mp_const_none;
  215. }
  216. STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_spi_init_obj, 1, machine_spi_init);
  217. STATIC mp_obj_t machine_spi_deinit(mp_obj_t self) {
  218. // dispatch to specific implementation
  219. if (mp_obj_get_type(self) == &machine_hard_spi_type) {
  220. machine_hard_spi_deinit(self);
  221. }
  222. return mp_const_none;
  223. }
  224. STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_spi_deinit_obj, machine_spi_deinit);
  225. STATIC const mp_rom_map_elem_t machine_spi_locals_dict_table[] = {
  226. { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_spi_init_obj) },
  227. { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_spi_deinit_obj) },
  228. { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_machine_spi_read_obj) },
  229. { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_machine_spi_readinto_obj) },
  230. { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_machine_spi_write_obj) },
  231. { MP_ROM_QSTR(MP_QSTR_write_readinto), MP_ROM_PTR(&mp_machine_spi_write_readinto_obj) },
  232. { MP_ROM_QSTR(MP_QSTR_MSB), MP_ROM_INT(NRF_SPI_BIT_ORDER_MSB_FIRST) },
  233. { MP_ROM_QSTR(MP_QSTR_LSB), MP_ROM_INT(NRF_SPI_BIT_ORDER_LSB_FIRST) },
  234. };
  235. STATIC MP_DEFINE_CONST_DICT(machine_spi_locals_dict, machine_spi_locals_dict_table);
  236. /* code for hard implementation ***********************************************/
  237. STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
  238. machine_hard_spi_obj_t *self = self_in;
  239. mp_printf(print, "SPI(%u)", self->p_spi->drv_inst_idx);
  240. }
  241. STATIC mp_obj_t machine_hard_spi_make_new(mp_arg_val_t *args) {
  242. // get static peripheral object
  243. int spi_id = spi_find(args[ARG_NEW_id].u_obj);
  244. const machine_hard_spi_obj_t *self = &machine_hard_spi_obj[spi_id];
  245. // here we would check the sck/mosi/miso pins and configure them
  246. if (args[ARG_NEW_sck].u_obj != MP_OBJ_NULL
  247. && args[ARG_NEW_mosi].u_obj != MP_OBJ_NULL
  248. && args[ARG_NEW_miso].u_obj != MP_OBJ_NULL) {
  249. self->p_config->sck_pin = mp_hal_get_pin_obj(args[ARG_NEW_sck].u_obj)->pin;
  250. self->p_config->mosi_pin = mp_hal_get_pin_obj(args[ARG_NEW_mosi].u_obj)->pin;
  251. self->p_config->miso_pin = mp_hal_get_pin_obj(args[ARG_NEW_miso].u_obj)->pin;
  252. } else {
  253. self->p_config->sck_pin = MICROPY_HW_SPI0_SCK;
  254. self->p_config->mosi_pin = MICROPY_HW_SPI0_MOSI;
  255. self->p_config->miso_pin = MICROPY_HW_SPI0_MISO;
  256. }
  257. // Manually trigger slave select from upper layer.
  258. self->p_config->ss_pin = NRFX_SPI_PIN_NOT_USED;
  259. #ifdef NRF51
  260. self->p_config->irq_priority = 3;
  261. #else
  262. self->p_config->irq_priority = 6;
  263. #endif
  264. mp_obj_t self_obj = MP_OBJ_FROM_PTR(self);
  265. machine_hard_spi_init(self_obj, &args[1]); // Skip instance id param.
  266. return self_obj;
  267. }
  268. STATIC void machine_hard_spi_init(mp_obj_t self_in, mp_arg_val_t *args) {
  269. const machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
  270. int baudrate = args[ARG_INIT_baudrate].u_int;
  271. if (baudrate <= 125000) {
  272. self->p_config->frequency = NRF_SPI_FREQ_125K;
  273. } else if (baudrate <= 250000) {
  274. self->p_config->frequency = NRF_SPI_FREQ_250K;
  275. } else if (baudrate <= 500000) {
  276. self->p_config->frequency = NRF_SPI_FREQ_500K;
  277. } else if (baudrate <= 1000000) {
  278. self->p_config->frequency = NRF_SPI_FREQ_1M;
  279. } else if (baudrate <= 2000000) {
  280. self->p_config->frequency = NRF_SPI_FREQ_2M;
  281. } else if (baudrate <= 4000000) {
  282. self->p_config->frequency = NRF_SPI_FREQ_4M;
  283. } else if (baudrate <= 8000000) {
  284. self->p_config->frequency = NRF_SPI_FREQ_8M;
  285. #if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
  286. } else if (baudrate <= 16000000) {
  287. self->p_config->frequency = NRF_SPIM_FREQ_16M;
  288. } else if (baudrate <= 32000000) {
  289. self->p_config->frequency = NRF_SPIM_FREQ_32M;
  290. #endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
  291. } else { // Default
  292. self->p_config->frequency = NRF_SPI_FREQ_1M;
  293. }
  294. // Active high
  295. if (args[ARG_INIT_polarity].u_int == 0) {
  296. if (args[ARG_INIT_phase].u_int == 0) {
  297. // First clock edge
  298. self->p_config->mode = NRF_SPI_MODE_0;
  299. } else {
  300. // Second clock edge
  301. self->p_config->mode = NRF_SPI_MODE_1;
  302. }
  303. // Active low
  304. } else {
  305. if (args[ARG_INIT_phase].u_int == 0) {
  306. // First clock edge
  307. self->p_config->mode = NRF_SPI_MODE_2;
  308. } else {
  309. // Second clock edge
  310. self->p_config->mode = NRF_SPI_MODE_3;
  311. }
  312. }
  313. self->p_config->orc = 0xFF; // Overrun character
  314. self->p_config->bit_order = (args[ARG_INIT_firstbit].u_int == 0) ? NRF_SPI_BIT_ORDER_MSB_FIRST : NRF_SPI_BIT_ORDER_LSB_FIRST;
  315. // Set context to this instance of SPI
  316. nrfx_err_t err_code = nrfx_spi_init(self->p_spi, self->p_config, NULL, (void *)self);
  317. if (err_code == NRFX_ERROR_INVALID_STATE) {
  318. // Instance already initialized, deinitialize first.
  319. nrfx_spi_uninit(self->p_spi);
  320. // Initialize again.
  321. nrfx_spi_init(self->p_spi, self->p_config, NULL, (void *)self);
  322. }
  323. }
  324. STATIC void machine_hard_spi_deinit(mp_obj_t self_in) {
  325. const machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
  326. nrfx_spi_uninit(self->p_spi);
  327. }
  328. STATIC void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
  329. const machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t*)self_in;
  330. spi_transfer(self, len, src, dest);
  331. }
  332. STATIC mp_obj_t mp_machine_spi_read(size_t n_args, const mp_obj_t *args) {
  333. vstr_t vstr;
  334. vstr_init_len(&vstr, mp_obj_get_int(args[1]));
  335. memset(vstr.buf, n_args == 3 ? mp_obj_get_int(args[2]) : 0, vstr.len);
  336. spi_transfer(args[0], vstr.len, vstr.buf, vstr.buf);
  337. return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
  338. }
  339. MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_read_obj, 2, 3, mp_machine_spi_read);
  340. STATIC mp_obj_t mp_machine_spi_readinto(size_t n_args, const mp_obj_t *args) {
  341. mp_buffer_info_t bufinfo;
  342. mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE);
  343. memset(bufinfo.buf, n_args == 3 ? mp_obj_get_int(args[2]) : 0, bufinfo.len);
  344. spi_transfer(args[0], bufinfo.len, bufinfo.buf, bufinfo.buf);
  345. return mp_const_none;
  346. }
  347. MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_readinto_obj, 2, 3, mp_machine_spi_readinto);
  348. STATIC mp_obj_t mp_machine_spi_write(mp_obj_t self, mp_obj_t wr_buf) {
  349. mp_buffer_info_t src;
  350. mp_get_buffer_raise(wr_buf, &src, MP_BUFFER_READ);
  351. spi_transfer(self, src.len, (const uint8_t*)src.buf, NULL);
  352. return mp_const_none;
  353. }
  354. MP_DEFINE_CONST_FUN_OBJ_2(mp_machine_spi_write_obj, mp_machine_spi_write);
  355. STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self, mp_obj_t wr_buf, mp_obj_t rd_buf) {
  356. mp_buffer_info_t src;
  357. mp_get_buffer_raise(wr_buf, &src, MP_BUFFER_READ);
  358. mp_buffer_info_t dest;
  359. mp_get_buffer_raise(rd_buf, &dest, MP_BUFFER_WRITE);
  360. if (src.len != dest.len) {
  361. mp_raise_ValueError("buffers must be the same length");
  362. }
  363. spi_transfer(self, src.len, src.buf, dest.buf);
  364. return mp_const_none;
  365. }
  366. MP_DEFINE_CONST_FUN_OBJ_3(mp_machine_spi_write_readinto_obj, mp_machine_spi_write_readinto);
  367. STATIC const mp_machine_spi_p_t machine_hard_spi_p = {
  368. .transfer = machine_hard_spi_transfer,
  369. };
  370. const mp_obj_type_t machine_hard_spi_type = {
  371. { &mp_type_type },
  372. .name = MP_QSTR_SPI,
  373. .print = machine_hard_spi_print,
  374. .make_new = machine_spi_make_new,
  375. .protocol = &machine_hard_spi_p,
  376. .locals_dict = (mp_obj_dict_t*)&machine_spi_locals_dict,
  377. };
  378. #endif // MICROPY_PY_MACHINE_HW_SPI