macaddress  2.0.0.0
macaddress.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 MACADDRESS_H
36 #define MACADDRESS_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define MACADDRESS_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
56 
62 #define MACADDRESS_RETVAL uint8_t
63 
64 #define MACADDRESS_OK 0x00
65 #define MACADDRESS_INIT_ERROR 0xFF
66 
72 #define MACADDRESS_I2C_ADDRESS_0 0x50
73 #define MACADDRESS_I2C_ADDRESS_1 0x51
74 #define MACADDRESS_I2C_ADDRESS_2 0x52
75 #define MACADDRESS_I2C_ADDRESS_3 0x53
76 
82 #define MACADDRESS_END_ADDR 0x80
83 #define MACADDRESS_MAC_ADDR 0xF8
84 
90 #define MACADDRESS_OK 0x00
91 #define MACADDRESS_PAR_ERR 0x01
92 #define MACADDRESS_COM_ERR 0x02
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
103 typedef struct
104 {
105  // Modules
106 
107  i2c_master_t i2c;
108 
109  // ctx variable
110 
111  uint8_t slave_address;
112 
113 } macaddress_t;
114 
118 typedef struct
119 {
120  // Communication gpio pins
121 
122  pin_name_t scl;
123  pin_name_t sda;
124 
125  uint32_t i2c_speed;
126  uint8_t i2c_address;
127 
129  // End types group
131 
132 #ifdef __cplusplus
133 extern "C"{
134 #endif
135 
144 
154 
165 void macaddress_generic_write ( macaddress_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
166 
178 void macaddress_generic_read ( macaddress_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
179 
190 void macaddress_get_mac ( macaddress_t *ctx, uint8_t *read_mac );
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 #endif // _MACADDRESS_H_
196  // End public_function group
199 
200 // ------------------------------------------------------------------------- END
MACADDRESS_RETVAL
#define MACADDRESS_RETVAL
Definition: macaddress.h:62
macaddress_init
MACADDRESS_RETVAL macaddress_init(macaddress_t *ctx, macaddress_cfg_t *cfg)
Initialization function.
macaddress_cfg_t
Click configuration structure definition.
Definition: macaddress.h:118
macaddress_get_mac
void macaddress_get_mac(macaddress_t *ctx, uint8_t *read_mac)
Generic read mac address function.
macaddress_t::slave_address
uint8_t slave_address
Definition: macaddress.h:111
macaddress_cfg_t::scl
pin_name_t scl
Definition: macaddress.h:122
macaddress_generic_read
void macaddress_generic_read(macaddress_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
macaddress_generic_write
void macaddress_generic_write(macaddress_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
macaddress_cfg_t::i2c_address
uint8_t i2c_address
Definition: macaddress.h:126
macaddress_cfg_t::sda
pin_name_t sda
Definition: macaddress.h:123
macaddress_t::i2c
i2c_master_t i2c
Definition: macaddress.h:107
macaddress_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: macaddress.h:125
macaddress_t
Definition: macaddress.h:103
macaddress_cfg_setup
void macaddress_cfg_setup(macaddress_cfg_t *cfg)
Config Object Initialization function.