Initial commit of firmware

This commit is contained in:
2025-04-12 13:30:57 +01:00
commit 264a3462e0
374 changed files with 332649 additions and 0 deletions

View File

@@ -0,0 +1,183 @@
/***************************************************************************//**
* @file
* @brief LED Driver
*******************************************************************************
* # License
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef SL_LED_H
#define SL_LED_H
#include <stdint.h>
#include "sl_status.h"
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************//**
* @addtogroup led LED Driver
* @brief Generic LED Driver
* @{
******************************************************************************/
/*******************************************************************************
****************************** DEFINES ************************************
******************************************************************************/
#define SL_LED_CURRENT_STATE_OFF 0U ///< LED state off
#define SL_LED_CURRENT_STATE_ON 1U ///< LED state on
/*******************************************************************************
***************************** DATA TYPES **********************************
******************************************************************************/
typedef uint8_t sl_led_state_t; ///< LED state
/// A LED instance
typedef struct {
void *context; ///< The context for this LED instance
sl_status_t (*init)(void *context); ///< Member function to initialize LED instance
void (*turn_on)(void *context); ///< Member function to turn on LED
void (*turn_off)(void *context); ///< Member function to turn off LED
void (*toggle)(void *context); ///< Member function to toggle LED
sl_led_state_t (*get_state)(void *context); ///< Member function to retrieve LED state
} sl_led_t;
/*******************************************************************************
***************************** PROTOTYPES **********************************
******************************************************************************/
/***************************************************************************//**
* Initialize the LED driver. Call this function before any other LED
* function. Initializes the selected LED GPIO, mode, and polarity.
*
* @param[in] led_handle Pointer to instance of sl_led_t to initialize
*
* @return Status Code:
* - SL_STATUS_OK
******************************************************************************/
sl_status_t sl_led_init(const sl_led_t *led_handle);
/***************************************************************************//**
* Turn on the LED.
*
* @param[in] led_handle Pointer to instance of sl_led_t to turn on
******************************************************************************/
void sl_led_turn_on(const sl_led_t *led_handle);
/***************************************************************************//**
* Turn off the LED.
*
* @param[in] led_handle Pointer to instance of sl_led_t to turn off
******************************************************************************/
void sl_led_turn_off(const sl_led_t *led_handle);
/***************************************************************************//**
* Toggle the LED. Turn it on if it is off, and off if it is on.
*
* @param[in] led_handle Pointer to instance of sl_led_t to toggle
******************************************************************************/
void sl_led_toggle(const sl_led_t *led_handle);
/***************************************************************************//**
* Get the current state of the LED.
*
* @param[in] led_handle Pointer to instance of sl_led_t to check
*
* @return sl_led_state_t Current state of LED. 1 for on, 0 for off
******************************************************************************/
sl_led_state_t sl_led_get_state(const sl_led_t *led_handle);
/** @} (end group led) */
// ******** THE REST OF THE FILE IS DOCUMENTATION ONLY !***********************
/// @addtogroup led LED Driver
/// @{
///
/// @details
///
///
/// @n @section leddrv_intro Introduction
///
/// The LED driver is a platfom level software module that manages the control of
/// various types of LEDs. There are currently two types of LEDs supported by the
/// LED driver:
///
/// @li @ref simple_led
/// @li @ref simple_rgbw_pwm_led
///
/// The common LED functions are called through the generic LED driver, while other
/// functions specific to a certain type of LED are called directly through their own
/// driver.
///
/// @n @section leddrv_config Configuration
///
/// All LED instances are configured using an @ref sl_led_t struct along with a
/// type-specific context struct, and sometimes additional structs. For `sl_led_XXX`
/// functions, the `sl_led_t *led_handle` is used, while for `sl_simple_led_XXX`
/// functions, the `sl_simple_led_context_t *context` is used.
///
/// These structs are automatically generated when an LED is set up using Simplicity
/// Studio's wizard. Specific configuration setups for the various LED types are
/// described in the following sections.
///
/// - [Simple LED Configuration](/gecko-platform/<docspace-docleaf-version>/platform-driver/simple-led#simple-led-configuration)
/// - [RGBW PWM LED Configuration](/gecko-platform/<docspace-docleaf-version>/platform-driver/simple-rgb-pwm-led#rgb-pwm-led-configuration)
///
/// @n @section leddrv_usage Usage
///
/// Once the LED structs are defined, the common LED functions can be called being passed an instance
/// of sl_led_t, which will be redirected to calling the type specific version of that function. The
/// common functions include the following:
///
/// @li @ref sl_led_init
/// @li @ref sl_led_turn_on
/// @li @ref sl_led_turn_off
/// @li @ref sl_led_toggle
/// @li @ref sl_led_get_state
///
/// These functions allow for initializing the LED, turning it on and off, toggling it, and retrieving
/// its current state (on/off). Other functions specific to certain types of LEDs are called through
/// their respective APIs. The usages of the different types of LEDs are described in detail in the
/// following sections:
///
/// @li @ref simple_led_usage
/// @li @ref rgbw_led_usage
///
/// Ensure that the appropriate context type is used in the function calls:
/// - Use `sl_led_t *led_handle` for `sl_led_XXX` functions.
/// - Use `sl_simple_led_context_t *context` for `sl_simple_led_XXX` functions.
///
/// These distinctions are handled by the Simplicity Studio auto-generated code.
///
/// @} end group led ********************************************************/
#ifdef __cplusplus
}
#endif
#endif // SL_LED_H

View File

@@ -0,0 +1,226 @@
/***************************************************************************//**
* @file
* @brief Simple LED Driver
*******************************************************************************
* # License
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef SL_SIMPLE_LED_H
#define SL_SIMPLE_LED_H
#include "sl_led.h"
#include "sl_gpio.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************//**
* @addtogroup led
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup simple_led Simple LED Driver
* @brief Simple LED Driver can be used to execute basic LED functionalities
* such as on, off, toggle, or retrive the on/off status on Silicon Labs
* devices. Subsequent sections provide more insight into this module.
* @{
******************************************************************************/
/*******************************************************************************
****************************** DEFINES ************************************
******************************************************************************/
#define SL_SIMPLE_LED_POLARITY_ACTIVE_LOW 0U ///< LED Active polarity Low
#define SL_SIMPLE_LED_POLARITY_ACTIVE_HIGH 1U ///< LED Active polarity High
/*******************************************************************************
***************************** DATA TYPES **********************************
******************************************************************************/
typedef uint8_t sl_led_polarity_t; ///< LED GPIO polarities (active high/low)
/// A Simple LED instance
typedef struct {
sl_gpio_port_t port; ///< LED port
uint8_t pin; ///< LED pin
sl_led_polarity_t polarity; ///< Initial state of LED
} sl_simple_led_context_t;
/*******************************************************************************
***************************** PROTOTYPES **********************************
******************************************************************************/
/***************************************************************************//**
* Initialize the simple LED driver.
*
* @param[in] led_handle Pointer to simple-led specific data:
* - sl_simple_led_context_t
*
* @return Status Code:
* - SL_STATUS_OK
******************************************************************************/
sl_status_t sl_simple_led_init(void *led_handle);
/***************************************************************************//**
* Turn on a simple LED.
*
* @param[in] led_handle Pointer to simple-led specific data:
* - sl_simple_led_context_t
*
******************************************************************************/
void sl_simple_led_turn_on(void *led_handle);
/***************************************************************************//**
* Turn off a simple LED.
*
* @param[in] led_handle Pointer to simple-led specific data:
* - sl_simple_led_context_t
*
******************************************************************************/
void sl_simple_led_turn_off(void *led_handle);
/***************************************************************************//**
* Toggle a simple LED.
*
* @param[in] led_handle Pointer to simple-led specific data:
* - sl_simple_led_context_t
*
******************************************************************************/
void sl_simple_led_toggle(void *led_handle);
/***************************************************************************//**
* Get the current state of the simple LED.
*
* @param[in] led_handle Pointer to simple-led specific data:
* - sl_simple_led_context_t
*
* @return sl_led_state_t Current state of simple LED. 1 for on, 0 for off
******************************************************************************/
sl_led_state_t sl_simple_led_get_state(void *led_handle);
/** @} (end group simple_led) */
/** @} (end group led) */
// ******** THE REST OF THE FILE IS DOCUMENTATION ONLY !***********************
/// @addtogroup simple_led Simple LED Driver
/// @{
///
/// @details
///
///
/// @n @section simple_led_intro Introduction
///
/// The Simple LED driver is a module of the LED driver that provides the functionality
/// to control simple on/off LEDs.
///
/// @n @section simple_led_config Simple LED Configuration
///
/// Simple LEDs use the @ref sl_led_t struct and their @ref sl_simple_led_context_t
/// struct. These are automatically generated into the following files, as well as
/// instance specific headers with macro definitions in them. The samples below
/// are for a single instance called "inst0".
///
/// @code{.c}
///// sl_simple_led_instances.c
///
///#include "sl_simple_led.h"
///#include "sl_gpio.h"
///#include "sl_simple_led_inst0_config.h"
///
///sl_simple_led_context_t simple_inst0_context = {
/// .port = SL_SIMPLE_LED_INST0_PORT,
/// .pin = SL_SIMPLE_LED_INST0_PIN,
/// .polarity = SL_SIMPLE_LED_INST0_POLARITY,
///};
///
///const sl_led_t sl_led_inst0 = {
/// .context = &simple_inst0_context,
/// .init = sl_simple_led_init,
/// .turn_on = sl_simple_led_turn_on,
/// .turn_off = sl_simple_led_turn_off,
/// .toggle = sl_simple_led_toggle,
/// .get_state = sl_simple_led_get_state,
///};
///
///void sl_simple_led_init_instances(void)
///{
/// sl_led_init(&sl_led_inst0);
///}
/// @endcode
///
/// @note The sl_simple_led_instances.c file is shown with only one instance, but if more
/// were in use they would all appear in this .c file.
///
/// @code{.c}
///// sl_simple_led_instances.h
///
///#ifndef SL_SIMPLE_LED_INSTANCES_H
///#define SL_SIMPLE_LED_INSTANCES_H
///
///#include "sl_simple_led.h"
///
///extern const sl_led_t sl_led_inst0;
///
///void sl_simple_led_init_instances(void);
///
///#endif // SL_SIMPLE_LED_INIT_H
/// @endcode
///
/// @note The sl_simple_led_instances.h file is shown with only one instance, but if more
/// were in use they would all appear in this .h file.
///
/// @n @section simple_led_usage Simple LED Usage
///
/// The simple LED driver is for LEDs with basic on off functionality, and there
/// are no additional functions beyond those in the common driver. The LEDs can be
/// turned on and off, toggled, and their on/off state can be retrieved. The following
/// code shows how to control these LEDs. An LED should always be initialized before
/// calling any other functions with it.
///
/// @code{.c}
///// initialize simple LED
///sl_simple_led_init(&simple_led_inst0);
///
///// turn on simple LED, turn off simple LED, and toggle the simple LED
///sl_simple_led_turn_on(&simple_led_inst0);
///sl_simple_led_turn_off(&simple_led_inst0);
///sl_simple_led_toggle(&simple_led_inst0);
///
///// get the state of the simple LED
///sl_led_state_t state = sl_simple_led_get_state(&simple_led_instance0);
/// @endcode
///
/// @} end group simple_led ********************************************************/
#ifdef __cplusplus
}
#endif
#endif // SL_SIMPLE_LED_H

View File

@@ -0,0 +1,56 @@
/***************************************************************************//**
* @file
* @brief LED Driver
*******************************************************************************
* # License
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#include "sl_led.h"
sl_status_t sl_led_init(const sl_led_t *led_handle)
{
return led_handle->init(led_handle->context);
}
void sl_led_turn_on(const sl_led_t *led_handle)
{
led_handle->turn_on(led_handle->context);
}
void sl_led_turn_off(const sl_led_t *led_handle)
{
led_handle->turn_off(led_handle->context);
}
void sl_led_toggle(const sl_led_t *led_handle)
{
led_handle->toggle(led_handle->context);
}
sl_led_state_t sl_led_get_state(const sl_led_t *led_handle)
{
return led_handle->get_state(led_handle->context);
}

View File

@@ -0,0 +1,104 @@
/***************************************************************************//**
* @file
* @brief Simple LED Driver
*******************************************************************************
* # License
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#include "sl_simple_led.h"
#include "sl_gpio.h"
#include "sl_clock_manager.h"
sl_status_t sl_simple_led_init(void *context)
{
sl_simple_led_context_t *led = context;
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
sl_gpio_t gpio;
gpio.port = led->port;
gpio.pin = led->pin;
sl_gpio_set_pin_mode(&gpio,
SL_GPIO_MODE_PUSH_PULL,
!led->polarity);
return SL_STATUS_OK;
}
void sl_simple_led_turn_on(void *context)
{
sl_simple_led_context_t *led = context;
sl_gpio_t gpio;
gpio.port = led->port;
gpio.pin = led->pin;
if (led->polarity == SL_SIMPLE_LED_POLARITY_ACTIVE_LOW) {
sl_gpio_clear_pin(&gpio);
} else {
sl_gpio_set_pin(&gpio);
}
}
void sl_simple_led_turn_off(void *context)
{
sl_simple_led_context_t *led = context;
sl_gpio_t gpio;
gpio.port = led->port;
gpio.pin = led->pin;
if (led->polarity == SL_SIMPLE_LED_POLARITY_ACTIVE_LOW) {
sl_gpio_set_pin(&gpio);
} else {
sl_gpio_clear_pin(&gpio);
}
}
void sl_simple_led_toggle(void *context)
{
sl_simple_led_context_t *led = context;
sl_gpio_t gpio;
gpio.port = led->port;
gpio.pin = led->pin;
sl_gpio_toggle_pin(&gpio);
}
sl_led_state_t sl_simple_led_get_state(void *context)
{
sl_simple_led_context_t *led = context;
sl_led_state_t value;
sl_gpio_t gpio;
bool pin_value;
gpio.port = led->port;
gpio.pin = led->pin;
sl_gpio_get_pin_output(&gpio, &pin_value);
value = (sl_led_state_t)pin_value;
if (led->polarity == SL_SIMPLE_LED_POLARITY_ACTIVE_LOW) {
return !value;
} else {
return value;
}
}