Skip to content

Commit ea6defe

Browse files
committed
Update code, change documentation
1 parent 948c9ad commit ea6defe

9 files changed

Lines changed: 70 additions & 56 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ These are all of the files we've created to make the project more *readable*:
6363
- `util.c` (& `util.h`)
6464
- Here we have some *utility functionality* like:
6565
- A **Delay** method with it's **interrupt handler** and a function to **enable or disable** `systicks`.
66-
- A method to **initialize the LED's**.
66+
- A method to **initialize the LED's** and to **turn on or off LED0**.
6767
- A method to **stop code execution when an error occured**.
6868

6969
- `handlers.c` (& `handlers.h`)

code/SLSTK3400A_ADXL362/inc/accel.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************//**
22
* @file accel.h
33
* @brief All code for the ADXL362 accelerometer.
4-
* @version 2.1
4+
* @version 3.0
55
* @author Brecht Van Eeckhoudt
66
******************************************************************************/
77

@@ -24,20 +24,20 @@
2424

2525

2626
/* ADXL SPI GPOI */
27-
#define ADXL_CLK_PORT gpioPortE
28-
#define ADXL_CLK_PIN 12
27+
#define ADXL_CLK_PORT gpioPortE
28+
#define ADXL_CLK_PIN 12
2929
#define ADXL_MOSI_PORT gpioPortE
30-
#define ADXL_MOSI_PIN 10
30+
#define ADXL_MOSI_PIN 10
3131
#define ADXL_MISO_PORT gpioPortE
32-
#define ADXL_MISO_PIN 11
33-
#define ADXL_NCS_PORT gpioPortD /* Can't use the US0_CS port (PE13) to manually set/clear CS line */
34-
#define ADXL_NCS_PIN 4
32+
#define ADXL_MISO_PIN 11
33+
#define ADXL_NCS_PORT gpioPortD /* Can't use the US0_CS port (PE13) to manually set/clear CS line */
34+
#define ADXL_NCS_PIN 4
3535

3636
/* Other ADXL GPOI */
3737
#define ADXL_INT1_PORT gpioPortD
38-
#define ADXL_INT1_PIN 7
39-
#define ADXL_VCC_PORT gpioPortD
40-
#define ADXL_VCC_PIN 5
38+
#define ADXL_INT1_PIN 7
39+
#define ADXL_VCC_PORT gpioPortD
40+
#define ADXL_VCC_PIN 5
4141

4242

4343
/* ADXL REGISTERS */

code/SLSTK3400A_ADXL362/inc/debugging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This header file is called in every other file where there are UART
66
* debugging statements. Commenting the line in this file can remove all
77
* UART functionality in the whole project.
8-
* @version 2.0
8+
* @version 3.0
99
* @author Brecht Van Eeckhoudt
1010
******************************************************************************/
1111

code/SLSTK3400A_ADXL362/inc/handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************//**
22
* @file handlers.h
33
* @brief Interrupt handlers.
4-
* @version 2.0
4+
* @version 3.0
55
* @author Brecht Van Eeckhoudt
66
******************************************************************************/
77

code/SLSTK3400A_ADXL362/inc/util.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************//**
22
* @file util.h
33
* @brief Utility functions.
4-
* @version 2.0
4+
* @version 3.0
55
* @author Brecht Van Eeckhoudt
66
******************************************************************************/
77

@@ -19,12 +19,19 @@
1919
#include "../inc/debugging.h" /* Enable or disable printing to UART */
2020

2121

22+
/* PORT and PIN definitoons */
23+
#define LED0_PORT gpioPortF
24+
#define LED0_PIN 4
25+
#define LED1_PORT gpioPortF
26+
#define LED1_PIN 5
27+
28+
2229
/* Prototypes */
2330
void initLEDS (void);
31+
void led0 (bool enabled);
2432
void Error (uint8_t number);
2533
void Delay (uint32_t dlyTicks);
26-
void disableSystick (void);
27-
void enableSystick (void);
34+
void systickInterrupts (bool enabled);
2835

2936

3037
#endif /* _UTIL_H_ */

code/SLSTK3400A_ADXL362/src/accel.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file accel.c
33
* @brief All code for the ADXL362 accelerometer.
44
* @details Started with code from the UART example (main_series0_HG.c) from SiLabs Github.
5-
* @version 2.1
5+
* @version 3.0
66
* @author Brecht Van Eeckhoudt
77
******************************************************************************/
88

@@ -187,7 +187,7 @@ void testADXL (void)
187187

188188
/**************************************************************************//**
189189
* @brief
190-
* Read and display g values forever with a one second interval.
190+
* Read and display g values forever with a 100ms interval.
191191
*
192192
* @details
193193
* The accelerometer is put in measurement mode at 12.5Hz ODR, new
@@ -204,7 +204,7 @@ void readValuesADXL (void)
204204
/* Infinite loop */
205205
while (1)
206206
{
207-
GPIO_PinOutSet(gpioPortF, 4); /* Enable LED0 */
207+
led0(true); /* Enable LED0 */
208208

209209
/* Read XYZ sensor data */
210210
readADXL_XYZDATA();
@@ -224,7 +224,7 @@ void readValuesADXL (void)
224224
//dbprintln("");
225225
#endif /* DEBUGGING */
226226

227-
GPIO_PinOutClear(gpioPortF, 4); /* Disable LED0 */
227+
led0(false); /* Disable LED0 */
228228

229229
counter++;
230230

@@ -576,7 +576,7 @@ void softResetADXL (void)
576576

577577

578578
/**************************************************************************//**
579-
* @brief Check if the ID is correct
579+
* @brief Check if the ID is correct.
580580
*
581581
* @return
582582
* @li true - Correct ID returned.

code/SLSTK3400A_ADXL362/src/handlers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************//**
22
* @file handlers.c
33
* @brief Interrupt handlers.
4-
* @version 2.0
4+
* @version 3.0
55
* @author Brecht Van Eeckhoudt
66
******************************************************************************/
77

code/SLSTK3400A_ADXL362/src/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************//**
22
* @file main.c
33
* @brief The main file for the program to interface to the accelerometer.
4-
* @version 2.1
4+
* @version 3.0
55
* @author Brecht Van Eeckhoudt
66
*
77
* ******************************************************************************
@@ -59,7 +59,7 @@
5959
* Initialize buttons PB0 and PB1 on falling-edge interrupts and
6060
* ADXL_INT1 on rising-edge interrupts.
6161
*****************************************************************************/
62-
void initWakeup (void)
62+
void initGPIOwakeup (void)
6363
{
6464
/* Enable necessary clock */
6565
CMU_ClockEnable(cmuClock_GPIO, true);
@@ -89,7 +89,7 @@ void initWakeup (void)
8989
/**************************************************************************//**
9090
* @brief RTCC initialization
9191
*****************************************************************************/
92-
void initRTCC (void)
92+
void initRTCcomp (void)
9393
{
9494
/* Enable the oscillator for the RTC */
9595
CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
@@ -132,10 +132,10 @@ int main (void)
132132
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1);
133133

134134
/* Initialize RTC compare settings */
135-
initRTCC();
135+
initRTCcomp();
136136

137137
/* Initialize GPIO wakeup */
138-
initWakeup();
138+
initGPIOwakeup();
139139

140140
#ifdef DEBUGGING /* DEBUGGING */
141141
dbprint_INIT(USART1, 4, true, false); /* VCOM */
@@ -196,9 +196,9 @@ int main (void)
196196

197197
while(1)
198198
{
199-
GPIO_PinOutSet(gpioPortF, 4); /* Enable LED0 */
199+
led0(true); /* Enable LED0 */
200200
Delay(1000);
201-
GPIO_PinOutClear(gpioPortF, 4); /* Disable LED0 */
201+
led0(false); /* Disable LED0 */
202202

203203
/* Read status register to acknowledge interrupt
204204
* (can be disabled by changing LINK/LOOP mode in ADXL_REG_ACT_INACT_CTL) */
@@ -212,8 +212,8 @@ int main (void)
212212
dbinfo("Disabling systick & going to sleep...\r\n");
213213
#endif /* DEBUGGING */
214214

215-
disableSystick();
215+
systickInterrupts(false); /* Disable SysTick interrupts */
216216
EMU_EnterEM2(true); /* "true": Save and restore oscillators, clocks and voltage scaling */
217-
enableSystick();
217+
systickInterrupts(true); /* Enable SysTick interrupts */
218218
}
219219
}

code/SLSTK3400A_ADXL362/src/util.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************//**
22
* @file util.c
33
* @brief Utility functions.
4-
* @version 2.0
4+
* @version 3.0
55
* @author Brecht Van Eeckhoudt
66
******************************************************************************/
77

@@ -19,10 +19,25 @@ volatile uint32_t msTicks; /* Volatile because it's a global variable that's mod
1919
*****************************************************************************/
2020
void initLEDS (void)
2121
{
22-
GPIO_PinModeSet(gpioPortF, 4, gpioModePushPull, 1); /* LED0 */
23-
GPIO_PinModeSet(gpioPortF, 5, gpioModePushPull, 1); /* LED1 */
24-
GPIO_PinOutClear(gpioPortF, 4); /* Disable LED0 */
25-
GPIO_PinOutClear(gpioPortF, 5); /* Disable LED1 */
22+
GPIO_PinModeSet(LED0_PORT, LED0_PIN, gpioModePushPull, 1);
23+
GPIO_PinModeSet(LED1_PORT, LED1_PIN, gpioModePushPull, 1);
24+
GPIO_PinOutClear(LED0_PORT, LED0_PIN); /* Disable LED0 */
25+
GPIO_PinOutClear(LED1_PORT, LED1_PIN); /* Disable LED1 */
26+
}
27+
28+
29+
/**************************************************************************//**
30+
* @brief
31+
* Enable or disable LED0.
32+
*
33+
* @param[in] enabled
34+
* @li True - Enable LED0
35+
* @li False - Disable LED0.
36+
*****************************************************************************/
37+
void led0 (bool enabled)
38+
{
39+
if (enabled) GPIO_PinOutSet(LED0_PORT, LED0_PIN);
40+
else GPIO_PinOutClear(LED0_PORT, LED0_PIN);
2641
}
2742

2843

@@ -44,14 +59,14 @@ void Error (uint8_t number)
4459
dbcritInt(">>> Error (", number, ")! Please reset MCU. <<<", false);
4560
#endif /* DEBUGGING */
4661

47-
GPIO_PinOutClear(gpioPortF, 4); /* Disable LED0 */
48-
GPIO_PinOutSet(gpioPortF, 5); /* Enable LED1 */
62+
GPIO_PinOutClear(LED0_PORT, LED0_PIN); /* Disable LED0 */
63+
GPIO_PinOutSet(LED1_PORT, LED1_PIN); /* Enable LED1 */
4964

5065
while(1)
5166
{
5267
Delay(100);
53-
GPIO_PinOutToggle(gpioPortF, 4); /* Toggle LED0 */
54-
GPIO_PinOutToggle(gpioPortF, 5); /* Toggle LED1 */
68+
GPIO_PinOutToggle(LED0_PORT, LED0_PIN); /* Toggle LED0 */
69+
GPIO_PinOutToggle(LED1_PORT, LED1_PIN); /* Toggle LED1 */
5570
}
5671
}
5772

@@ -83,27 +98,19 @@ void Delay (uint32_t dlyTicks)
8398

8499
/**************************************************************************//**
85100
* @brief
86-
* Disable SysTick interrupt and counter by clearing their bits.
101+
* Disable
87102
*
88103
* @note
89104
* SysTick interrupt and counter (used by Delay) need to
90105
* be disabled before going to EM2.
91-
*****************************************************************************/
92-
void disableSystick (void)
93-
{
94-
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk & ~SysTick_CTRL_ENABLE_Msk;
95-
}
96-
97-
98-
/**************************************************************************//**
99-
* @brief
100-
* Enable SysTick interrupt and counter by setting their bits.
101106
*
102-
* @note
103-
* SysTick interrupt and counter (used by Delay) need to
104-
* be enabled after waking up from EM2.
107+
* @param[in] enabled
108+
* @li True - Enable SysTick interrupt and counter by setting their bits.
109+
* @li False - Disable SysTick interrupt and counter by clearing their bits.
105110
*****************************************************************************/
106-
void enableSystick (void)
111+
void systickInterrupts (bool enabled)
107112
{
108-
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
113+
if (enabled) SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
114+
else SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk & ~SysTick_CTRL_ENABLE_Msk;
109115
}
116+

0 commit comments

Comments
 (0)