ledringr  2.0.0.0
ledringr.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef LEDRINGR_H
36 #define LEDRINGR_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define LEDRINGR_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.mr = MIKROBUS( mikrobus, MIKROBUS_RST );
70 
77 #define LEDRINGR_RETVAL uint8_t
78 
79 #define LEDRINGR_OK 0x00
80 #define LEDRINGR_INIT_ERROR 0xFF
81  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
94 typedef struct
95 {
96  // Output pins
97 
98  digital_out_t mr;
99  digital_out_t cs;
100 
101  // Modules
102 
103  spi_master_t spi;
104  pin_name_t chip_select;
105 
106 } ledringr_t;
107 
111 typedef struct
112 {
113  // Communication gpio pins
114 
115  pin_name_t miso;
116  pin_name_t mosi;
117  pin_name_t sck;
118  pin_name_t cs;
119 
120  // Additional gpio pins
121 
122  pin_name_t mr;
123 
124  // static variable
125 
126  uint32_t spi_speed;
127  uint8_t spi_mode;
128  spi_master_chip_select_polarity_t cs_polarity;
129 
131  // End types group
133 
134 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
153 
162 
175 (
176  ledringr_t *ctx,
177  uint8_t *write_buf,
178  uint16_t wbuf_size,
179  uint8_t *read_buf,
180  uint16_t rbuf_size
181 );
182 
191 void ledringr_write_data ( ledringr_t *ctx, uint32_t data_to_write );
192 
201 void ledringr_turn_on_led ( ledringr_t *ctx, uint8_t led_position );
202 
211 
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 #endif // _LEDRINGR_H_
225  // End public_function group
228 
229 // ------------------------------------------------------------------------- END
ledringr_cfg_t::cs
pin_name_t cs
Definition: ledringr.h:118
ledringr_t::mr
digital_out_t mr
Definition: ledringr.h:98
ledringr_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ledringr.h:128
ledringr_cfg_t::spi_speed
uint32_t spi_speed
Definition: ledringr.h:126
ledringr_transfer_data
void ledringr_transfer_data(ledringr_t *ctx, uint8_t *write_buf, uint16_t wbuf_size, uint8_t *read_buf, uint16_t rbuf_size)
Transfer data function.
ledringr_cfg_t
Click configuration structure definition.
Definition: ledringr.h:112
ledringr_turn_on_led
void ledringr_turn_on_led(ledringr_t *ctx, uint8_t led_position)
Turn On LED by position.
ledringr_cfg_t::mosi
pin_name_t mosi
Definition: ledringr.h:116
ledringr_cfg_t::mr
pin_name_t mr
Definition: ledringr.h:122
ledringr_cfg_t::sck
pin_name_t sck
Definition: ledringr.h:117
ledringr_init
LEDRINGR_RETVAL ledringr_init(ledringr_t *ctx, ledringr_cfg_t *cfg)
Initialization function.
ledringr_cfg_t::spi_mode
uint8_t spi_mode
Definition: ledringr.h:127
ledringr_led_ring_reset
void ledringr_led_ring_reset(ledringr_t *ctx)
Set led.
ledringr_cfg_t::miso
pin_name_t miso
Definition: ledringr.h:115
ledringr_t::spi
spi_master_t spi
Definition: ledringr.h:103
ledringr_t::chip_select
pin_name_t chip_select
Definition: ledringr.h:104
ledringr_t::cs
digital_out_t cs
Definition: ledringr.h:99
ledringr_t
Click ctx object definition.
Definition: ledringr.h:95
ledringr_cfg_setup
void ledringr_cfg_setup(ledringr_cfg_t *cfg)
Config Object Initialization function.
ledringr_write_data
void ledringr_write_data(ledringr_t *ctx, uint32_t data_to_write)
Generic write function.
LEDRINGR_RETVAL
#define LEDRINGR_RETVAL
Definition: ledringr.h:77
ledringr_led_ring_set
void ledringr_led_ring_set(ledringr_t *ctx)
Set led.