ism  2.0.0.0
ism.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef ISM_H
29 #define ISM_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 
69 #define ISM_REG_BANK_0_CONFIG 0x00
70 #define ISM_REG_BANK_0_EN_AA 0x01
71 #define ISM_REG_BANK_0_EN_RXADDR 0x02
72 #define ISM_REG_BANK_0_SETUP_AW 0x03
73 #define ISM_REG_BANK_0_SETUP_RETR 0x04
74 #define ISM_REG_BANK_0_RF_CH 0x05
75 #define ISM_REG_BANK_0_RF_SETUP 0x06
76 #define ISM_REG_BANK_0_STATUS 0x07
77 #define ISM_REG_BANK_0_OBSERVE_TX 0x08
78 #define ISM_REG_BANK_0_CD 0x09
79 #define ISM_REG_BANK_0_RX_ADDR_P0 0x0A
80 #define ISM_REG_BANK_0_RX_ADDR_P1 0x0B
81 #define ISM_REG_BANK_0_RX_ADDR_P2 0x0C
82 #define ISM_REG_BANK_0_RX_ADDR_P3 0x0D
83 #define ISM_REG_BANK_0_RX_ADDR_P4 0x0E
84 #define ISM_REG_BANK_0_RX_ADDR_P5 0x0F
85 #define ISM_REG_BANK_0_TX_ADDR 0x10
86 #define ISM_REG_BANK_0_RX_PW_P0 0x11
87 #define ISM_REG_BANK_0_RX_PW_P1 0x12
88 #define ISM_REG_BANK_0_RX_PW_P2 0x13
89 #define ISM_REG_BANK_0_RX_PW_P3 0x14
90 #define ISM_REG_BANK_0_RX_PW_P4 0x15
91 #define ISM_REG_BANK_0_RX_PW_P5 0x16
92 #define ISM_REG_BANK_0_FIFO_STATUS 0x17
93 #define ISM_REG_BANK_0_PAYLOAD_WIDTH 0x1F
94 #define ISM_REG_BANK_1_REG_0 0x00
95 #define ISM_REG_BANK_1_REG_1 0x01
96 #define ISM_REG_BANK_1_REG_2 0x02
97 #define ISM_REG_BANK_1_REG_3 0x03
98 #define ISM_REG_BANK_1_REG_4 0x04
99 #define ISM_REG_BANK_1_REG_5 0x05
100 #define ISM_REG_BANK_1_REG_6 0x06
101 #define ISM_REG_BANK_1_REG_7 0x07
102 #define ISM_REG_BANK_1_REG_8 0x08
103 #define ISM_REG_BANK_1_REG_9 0x09
104 #define ISM_REG_BANK_1_REG_A 0x0A
105 #define ISM_REG_BANK_1_REG_B 0x0B
106 #define ISM_REG_BANK_1_REG_C 0x0C
107 #define ISM_REG_BANK_1_REG_D 0x0D
108 #define ISM_REG_BANK_1_REG_E 0x0E
109  // ism_reg
111 
121 #define ISM_CMD_FLUSH_TX 0xE1
122 #define ISM_CMD_FLUSH_RX 0xE2
123 #define ISM_CMD_REUSE_TX_PL 0xE3
124 #define ISM_CMD_W_TX_PAYLOAD_NOACK 0xB0
125 #define ISM_CMD_W_ACK_PAYLOAD 0xA8
126 #define ISM_CMD_ACTIVATE 0x50
127 #define ISM_CMD_R_RX_PL_WID 0x60
128 #define ISM_CMD_NOP_NOP 0xFF
129  // ism_cmd
131 
146 #define ISM_STATUS_RX_DR 0x40
147 #define ISM_STATUS_TX_DS 0x20
148 #define ISM_STATUS_MAX_RT 0x10
149 #define STATUS_TX_FULL 0x01
150 #define ISM_FIFO_STATUS_TX_REUSE 0x40
151 #define ISM_FIFO_STATUS_TX_FULL 0x20
152 #define ISM_FIFO_STATUS_TX_EMPTY 0x10
153 #define ISM_FIFO_STATUS_RX_FULL 0x02
154 #define ISM_FIFO_STATUS_RX_EMPTY 0x01
155 
160 #define ISM_SEL_BANK_0 0
161 #define ISM_SEL_BANK_1 1
162 
167 #define ISM_MAX_PACKET_LEN 32
168 
173 #define ISM_RT_PIN_STATE_LOW 0
174 #define ISM_RT_PIN_STATE_HIGH 1
175 
180 #define ISM_RD_RX_PLOAD 0x61
181 #define ISM_WR_TX_PLOAD 0xA0
182 
187 #define ISM_READ_BIT_MASK 0x00
188 #define ISM_WRITE_BIT_MASK 0x20
189  // ism_set
191 
206 #define ISM_MAP_MIKROBUS( cfg, mikrobus ) \
207  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
208  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
209  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
210  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
211  cfg.tl = MIKROBUS( mikrobus, MIKROBUS_AN ); \
212  cfg.ce = MIKROBUS( mikrobus, MIKROBUS_RST ); \
213  cfg.rl = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
214  cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
215  // ism_map // ism
218 
223 typedef struct
224 {
225  // Output pins
226  digital_out_t tl;
227  digital_out_t ce;
228  digital_out_t rl;
230  // Input pins
231  digital_in_t irq;
233  // Modules
234  spi_master_t spi;
236  pin_name_t chip_select;
238 } ism_t;
239 
244 typedef struct
245 {
246  // Communication gpio pins
247  pin_name_t miso;
248  pin_name_t mosi;
249  pin_name_t sck;
250  pin_name_t cs;
252  // Additional gpio pins
253  pin_name_t tl;
254  pin_name_t ce;
255  pin_name_t rl;
256  pin_name_t irq;
258  // static variable
259  uint32_t spi_speed;
260  spi_master_mode_t spi_mode;
261  spi_master_chip_select_polarity_t cs_polarity;
263 } ism_cfg_t;
264 
269 typedef enum
270 {
271  ISM_OK = 0,
272  ISM_ERROR = -1
273 
275 
291 void ism_cfg_setup ( ism_cfg_t *cfg );
292 
306 err_t ism_init ( ism_t *ctx, ism_cfg_t *cfg );
307 
317 void ism_default_cfg ( ism_t *ctx );
318 
333 err_t ism_generic_write ( ism_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
334 
349 err_t ism_generic_read ( ism_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
350 
363 err_t ism_set_cmd ( ism_t *ctx, uint8_t cmd, uint8_t cmd_data );
364 
375 void ism_chip_enable ( ism_t *ctx );
376 
387 void ism_chip_disable ( ism_t *ctx );
388 
402 void ism_set_rl_pin_state ( ism_t *ctx, uint8_t rt_pin_state );
403 
417 void ism_set_tl_pin_state ( ism_t *ctx, uint8_t tl_pin_state );
418 
431 
447 err_t ism_switch_bank ( ism_t *ctx, uint8_t bank_sel );
448 
461 err_t ism_switch_rx_mode ( ism_t *ctx );
462 
475 err_t ism_switch_tx_mode ( ism_t *ctx );
476 
489 err_t ism_device_config ( ism_t *ctx );
490 
504 err_t ism_receive_packet ( ism_t *ctx, uint8_t *rx_data );
505 
521 err_t ism_transmit_packet ( ism_t *ctx, uint8_t type, uint8_t *tx_data, uint8_t len );
522 
523 #ifdef __cplusplus
524 }
525 #endif
526 #endif // ISM_H
527  // ism
529 
530 // ------------------------------------------------------------------------ END
ism_generic_read
err_t ism_generic_read(ism_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
ISM data reading function.
ism_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: ism.h:260
ism_t::ce
digital_out_t ce
Definition: ism.h:227
ism_cfg_t::rl
pin_name_t rl
Definition: ism.h:255
ism_t::tl
digital_out_t tl
Definition: ism.h:226
ism_t::rl
digital_out_t rl
Definition: ism.h:228
ism_set_tl_pin_state
void ism_set_tl_pin_state(ism_t *ctx, uint8_t tl_pin_state)
ISM TL pin setting function.
ism_switch_rx_mode
err_t ism_switch_rx_mode(ism_t *ctx)
ISM switch RX mode function.
ism_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ism.h:261
ism_cfg_setup
void ism_cfg_setup(ism_cfg_t *cfg)
ISM configuration object setup function.
ism_default_cfg
void ism_default_cfg(ism_t *ctx)
ISM default configuration function.
ism_generic_write
err_t ism_generic_write(ism_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
ISM data writing function.
ISM_ERROR
@ ISM_ERROR
Definition: ism.h:272
ism_check_interrupt_request
uint8_t ism_check_interrupt_request(ism_t *ctx)
ISM check interrupt request function.
ism_t
ISM Click context object.
Definition: ism.h:224
ISM_OK
@ ISM_OK
Definition: ism.h:271
ism_cfg_t::spi_speed
uint32_t spi_speed
Definition: ism.h:259
ism_switch_tx_mode
err_t ism_switch_tx_mode(ism_t *ctx)
ISM switch TX mode function.
ism_set_cmd
err_t ism_set_cmd(ism_t *ctx, uint8_t cmd, uint8_t cmd_data)
ISM set command function.
ism_switch_bank
err_t ism_switch_bank(ism_t *ctx, uint8_t bank_sel)
ISM switch bank function.
ism_receive_packet
err_t ism_receive_packet(ism_t *ctx, uint8_t *rx_data)
ISM receive packet function.
ism_cfg_t::mosi
pin_name_t mosi
Definition: ism.h:248
ism_cfg_t::tl
pin_name_t tl
Definition: ism.h:253
ism_cfg_t::irq
pin_name_t irq
Definition: ism.h:256
ism_cfg_t::miso
pin_name_t miso
Definition: ism.h:247
ism_t::spi
spi_master_t spi
Definition: ism.h:234
ism_chip_enable
void ism_chip_enable(ism_t *ctx)
ISM set chip enable function.
ism_t::chip_select
pin_name_t chip_select
Definition: ism.h:236
ism_device_config
err_t ism_device_config(ism_t *ctx)
ISM device configuration function.
ism_cfg_t::cs
pin_name_t cs
Definition: ism.h:250
ism_t::irq
digital_in_t irq
Definition: ism.h:231
ism_set_rl_pin_state
void ism_set_rl_pin_state(ism_t *ctx, uint8_t rt_pin_state)
ISM RL pin setting function.
ism_chip_disable
void ism_chip_disable(ism_t *ctx)
ISM set chip disable function.
ism_cfg_t
ISM Click configuration object.
Definition: ism.h:245
ism_init
err_t ism_init(ism_t *ctx, ism_cfg_t *cfg)
ISM initialization function.
ism_cfg_t::sck
pin_name_t sck
Definition: ism.h:249
ism_cfg_t::ce
pin_name_t ce
Definition: ism.h:254
ism_transmit_packet
err_t ism_transmit_packet(ism_t *ctx, uint8_t type, uint8_t *tx_data, uint8_t len)
ISM transmit package function.
ism_return_value_t
ism_return_value_t
ISM Click return value data.
Definition: ism.h:270