EVE 1.0
board-ref-card.h
Go to the documentation of this file.
1 #ifndef BOARD_REF_CARD_H
2 #define BOARD_REF_CARD_H
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2015, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * @brief System example file.
36  *
37  * @author KLO, Jetro AS
38  */ /******************************************************************/
39 
40 #include <dev/adc0.h>
41 
42 //AØ!!PE! Per vil du slette unødvendige?
43 #include <dev/port.h>
44 #include <lib/env.h>
45 #include <dev/led.h>
46 #include <dev/key.h>
47 #include <em_cmu.h>
48 #include <em_gpio.h>
49 #include <stdbool.h>
50 #include <core/mwork.h>
52 #include <dev/i2c-master.h>
53 #include <gpiointerrupt.h>
54 
55 
56 /**********************************************************************/
57 /**
58  * @brief Name: PortsBoardInit\n
59  * Initializes ports available for the board.
60  **********************************************************************/
61 extern void PortsBoardInit(void);
62 
63 /**
64  **********************************************************************
65  * Configuration for adc0.c
66  **********************************************************************/
67 #define NUMBER_OF_CONFIG_ADC_CHANNELS 2
68 
69 extern const struct adc_schedule_t AdcScheduleRef;
70 extern const struct adc_channel_t Vcc1Channel;
71 extern const struct adc_channel_t Vcc2Channel;
72 extern const struct adc_channel_t AnalogMux;
73 extern const struct adc_channel_t DigitalMux;
74 
75 /**
76  **********************************************************************
77  * Configuration for i2c-master.c
78  **********************************************************************/
79 extern const struct i2c_t I2c0;
80 
81 /**
82  **********************************************************************
83  * Configuration for io-expander-pcal9535a.c
84  **********************************************************************/
85 
86 /**
87  * Number of IO expanders in the system
88  *
89  */
90 
91 #define IO_EXPANDER_INTn EVE_P19_PC6
92 #define IO_EXPANDER_INTn_PORT EVE_P19_PC6_PORT
93 
94 /* Configuration for IoExpanderA */
95 // PORT defines
96 #define KEY0_INn 0
97 #define KEY1_INn 1
98 #define KEY2_INn 2
99 #define KEY3_INn 3
100 #define WAKEUP_INT 4
101 #define ACCELEROMETER_INTn 5
102 #define BATTERY_CHARGE_STATUS_IN 6
103 #define ANALOG_4_20mA_ERROR_INn 7
104 #define LED_RED0_OUTn 8
105 #define LED_RED1_OUTn 9
106 #define LED_RED2_OUTn 10
107 #define LED_RED3_OUTn 11
108 #define LED_YELLOW_OUTn 12
109 #define LED_GREEN_OUTn 13
110 #define LCD_BACKLIGHT0_OUTn 14
111 #define LCD_BACKLIGHT1_OUT 15
112 
113 /* Configuration for IoExpanderB */
114 // PORT defines
115 #define DIGITAL_OUT0_OUT 0
116 #define DIGITAL_OUT1_OUT 1
117 #define DIGITAL_OUT2_OUT 2
118 #define DIGITAL_OUT3_OUT 3
119 #define DIGITAL_IO4 4
120 #define DIGITAL_IO5 5
121 #define ANALOG_4_20mA_ENABLE_OUT 7
122 #define POWER_5V_ENABLE_OUT 8
123 #define POWER_AUX_ENABLE_OUT 9
124 #define POWER_RS485_ENABLE_OUTn 10
125 #define POWER_USB_HOST_ENABLE_OUT 11
126 #define POWER_LED_RGB_OUTn 12
127 #define BATTERY_CHARGE_STATUS_RESISTOR_OUT 13
128 #define BATTERY_CHARGE_ENABLE_100mA_OUT 14
129 #define BATTERY_CHARGE_ENABLE_250mA_OUT 15
130 
131 extern const struct io_expander_t IoExpanderA;
132 extern const struct io_expander_t IoExpanderB;
133 
134 /**
135  * The array collects pointers to all IO expanders in the system
136  *
137  */
138 extern const struct io_expander_t *IoExpanders[NUMBER_OF_IO_EXPANDERS];
139 
140 /**
141  **********************************************************************
142  * Configuration for lcd-pcf85162.c
143  **********************************************************************/
144 extern const struct lcd_driver_t Pcf85162;
145 
146 /**
147  **********************************************************************
148  * Configuration for temp-sensor-stlm75.c
149  **********************************************************************/
150 extern const struct temp_sensor_t STLM75;
151 
152 /**
153  * Configuration for accelerometer-MMA8652.c
154  *
155  */
156 /**
157  *********************************************************************
158  * Configuration for accelerometer-MMA8652.c
159  ***********************************************************************/
160 extern const struct accel_config_t MMA8652FC;
161 
162 /**
163  *********************************************************************
164  * Configuration for pwm.c
165  ***********************************************************************/
166 extern const struct pwm_t Timer0;
167 
168 /***********************************************************************
169  * Configuration for led.c
170 ***********************************************************************/
171 #define LED_ENABLED true
172 
173 #if (LED_ENABLED == true)
174 #define LED_FLASHING_ENABLED false
175 #define LED_COUNTING_ENABLED true
176 
177 #define COUNTING_ON_TIME MWORK_MSEC(100)
178 #define COUNTING_OFF_TIME MWORK_MSEC(400)
179 
180 /**
181  * Inline code for updating leds.
182  * Return true if Leds can be updated, else false
183  */
184 static __inline void UpdateLeds(uint32_t BitLedOn)
185 {
186  uint16_t Mask = (1UL << LED_RED0_OUTn) | (1UL << LED_RED1_OUTn)
187  | (1UL << LED_RED2_OUTn) | (1UL << LED_RED3_OUTn)
188  | (1UL << LED_YELLOW_OUTn) | (1UL << LED_GREEN_OUTn);
189  uint16_t PortData = (~(BitLedOn << LED_RED0_OUTn)) & Mask;
190 
191  IoExpPortWrite(&IoExpanderA, PortData, Mask);
192 
193  if (BitLedOn & LED_RGB_RED)
194  GPIO_PinOutClear(gpioPortE, EVE_P15_PE14);
195  else
196  GPIO_PinOutSet(gpioPortE, EVE_P15_PE14);
197 
198  if (BitLedOn & LED_RGB_GREEN)
199  GPIO_PinOutClear(gpioPortE, EVE_P16_PE15);
200  else
201  GPIO_PinOutSet(gpioPortE, EVE_P16_PE15);
202 
203  if (BitLedOn & LED_RGB_BLUE)
204  GPIO_PinOutClear(gpioPortA, EVE_P20_PA15);
205  else
206  GPIO_PinOutSet(gpioPortA, EVE_P20_PA15);
207 };
208 #endif
209 
210 /***********************************************************************
211  * Configuration for beeper.c
212 ***********************************************************************/
213 #define BEEPER_ENABLED true
214 
215 #if (BEEPER_ENABLED == true)
216 #define BEEPER_CLICK_ENABLED true
217 #define BEEPER_CLICK_TIME MWORK_MSEC(50) // Click duration in ms
218 
219 /**
220  * Inline code for output or output function for beeper.
221  */
222 static __inline void BeepOn(bool On)
223 {
224  if (On)
225  GPIO_PinModeSet(gpioPortE, EVE_P16_PE15, gpioModePushPull, GPIO_HIGH); // SetPwmPercent(TIMER1, 0, 50)
226  else
227  GPIO_PinModeSet(gpioPortE, EVE_P16_PE15, gpioModePushPull, GPIO_LOW); // SetPwmPercent(TIMER1, 0, 0)
228 }
229 #endif
230 
231 /***********************************************************************
232  * Configuration for key.c
233  **********************************************************************/
234 #define KEY_ENABLED true
235 
236 #if (KEY_ENABLED == true)
237 #define REPEAT_KEY_ENABLED true
238 #define REPEAT_KEY_STEP2_ENABLED true
239 #define COMBI_KEYS_ENABLED true
240 #define COMBI_KEY_RELEASE_ENABLED true
241 
242 #define NUMBER_OF_KEYS 4
243 #define NUMBER_OF_REPEAT_KEYS 2
244 #define NUMBER_OF_COMBI_GROUPS 1
245 
246 #define KEY_SIGNAL_RECEIVER &ApplicMain
247 #define SCAN_KEY_INTERVAL 20 // ms
248 #define KEY_PRELL_TIME 80 // ms
249 
250 #if (REPEAT_KEY_ENABLED == true)
251  extern const bool RepeatKeyEnable[NUMBER_OF_KEYS];
252  extern const struct key_repeat_t ConfigKeyRepeat[NUMBER_OF_REPEAT_KEYS];
253 #endif
254 #if (COMBI_KEYS_ENABLED == true)
255  extern const struct key_combi_t ConfigKeyCombi[NUMBER_OF_COMBI_GROUPS];
256 #endif
257 
258 /**
259  * Inline code for reading key inputs.
260  */
261 static __inline uint32_t ReadKeyInput(void)
262 {
263  uint16_t KeyInput;
264 
265  IoExpPortRead(&IoExpanderA, &KeyInput);
266  KeyInput = (KeyInput ^ 0x0f) & 0x0f;
267 
268  return (KeyInput);
269 }
270 #endif
271 
272 #endif //BOARD_REF_CARD_H
bool IoExpPortWrite(const struct io_expander_t *IoExpander, const uint8_t Port0, const uint8_t Port1)
Name: IoExpPortWrite Write to IO expander PORT0 and PORT1.
Header file for the EVE millisecond-scale work scheduling.
const struct i2c_t I2c0
static __inline void BeepOn(bool On)
static __inline uint32_t ReadKeyInput(void)
Definition: pwm.h:114
const struct accel_config_t MMA8652FC
Driver for I2C-based IO expander type NXP PCAL9535A.
bool IoExpPortRead(const struct io_expander_t *IoExpander, uint8_t *Port0, uint8_t *Port1)
Name: IoExpPortRead Read IO expander PORT0 and PORT1.
Driver for ADC scheduling and integration.
EVE build environment.
const struct lcd_driver_t Pcf85162
void PortsBoardInit(void)
Name: PortsBoardInit Initializes ports available for the board.
static __inline void UpdateLeds(uint32_t BitLedOn)
The structure defines combi key parameters. Note that it is possible to define individual debounce ti...
Definition: key.h:109
The structure defines key repeat parameters.
Definition: key.h:96
Driver for I2C in nRF52 uC.
Driver for Leds.
Interface for Key driver in key.c.
const struct temp_sensor_t STLM75
const struct pwm_t Timer0
const struct io_expander_t * IoExpanders[NUMBER_OF_IO_EXPANDERS]