Commit d3465d67 authored by Federico Vaga's avatar Federico Vaga

common: include kits/common code

Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent bf8a135e
================ Revision history ============================================
3.20.5:
- Added drivers for Si1147 and Si7013 sensors.
- Optimized write speed in microsd driver.
- Increased SPI baudrate in microsd driver for targets with USART that
supports SMSDELAY (see ref. man for further description).
- BSP_TraceSwoSetup() will no longer overwrite settings set by external debugger
3.20.3:
- Added drivers for the Si7013 and Si1147 sensors used on the sensor expansion
board.
- Fixed bug in memory LCD driver when accessing unaligned framebuffers.
3.20.2:
- Added DISPLAY device driver, and specifically support for the Sharp Memory
LCD (model LS013B7DH03) on the EFM32ZG_STK3200.
- Fixed bug in SWO setup.
3.20.0:
- Fixed bug in microsd driver.
- Fixed bug in segmentlcd driver.
- New functions SegmentLCD_LowerHex() and SegmentLCD_LowerNumber()in
segmentlcd driver.
- Added MCU plugin board and board controller communication (BCC) API.
- New function BSP_BusControlModeGet().
1.0.0:
- First release
====== Board Support Package and Drivers ======
This package includes the board support package and drivers
common to all Silicon Labs EFM32 kits.
====== Dependencies ======
This package _requires_ the EFM32 CMSIS package to be installed at the
same level as this package. If you did not get this as part of the
Simplicity Studio package, you should also download and install the
EFM32 CMSIS package. See the Changes file for required version.
The EFM32 CMSIS package includes the necessary EFM32 drivers, register,
and bit field definitions that are required for the included BSP and
example projects.
The CMSIS package requires C99 support, and so does this package.
====== File structure ======
common/bsp
C source and header files for kit specific functionality, such as
enabling kit specific peripherals to be accessible from the EFM32
(configures on board analog switches - that are there to prevent
current leakage, gives access to LEDs, dip switches, joystick, i2c
devices and so on).
common/bspdoc
Doxygen documentation of BSP and Drivers. Use a web browser and open the
index.html file in the html directory.
common/drivers
Various drivers for kit specific components.
====== Updates ======
Silicon Labs continually works to provide updated and improved example code,
header files and other software of use for our customers. Please check
http://www.silabs.com/support/pages/document-library.aspx?p=MCUs--32-bit&f=Low-Power%20MCUs--32-bit
for the latest releases.
====== License ======
License information for use of the source code is given at the top of
all C files.
(C) Copyright Silicon Laboratories Inc. 2013. All rights reserved.
END-USER LICENSE AGREEMENT
IMPORTANT: READ CAREFULLY
BEFORE AGREEING TO TERMS
THIS PRODUCT CONTAINS CERTAIN COMPUTER PROGRAMS AND OTHER THIRD PARTY
PROPRIETARY MATERIAL ("LICENSED PRODUCT"), THE USE OF WHICH IS SUBJECT TO THIS
END-USER LICENSE AGREEMENT. INDICATING YOUR AGREEMENT CONSTITUTES YOUR AND
(IF APPLICABLE) YOUR COMPANY'S ASSENT TO AND ACCEPTANCE OF THIS END-USER LICENSE
AGREEMENT (THE "LICENSE" OR "AGREEMENT"). IF YOU DO NOT AGREE WITH ALL OF THE
TERMS, YOU MUST NOT USE THIS PRODUCT. WRITTEN APPROVAL IS NOT A PREREQUISITE TO
THE VALIDITY OR ENFORCEABILITY OF THIS AGREEMENT, AND NO SOLICITATION OF SUCH
WRITTEN APPROVAL BY OR ON BEHALF OF SILICON LABORATORIES, INC. ("SILICON LABS")
SHALL BE CONSTRUED AS AN INFERENCE TO THE CONTRARY. IF THESE TERMS ARE
CONSIDERED AN OFFER BY SILICON LABS, ACCEPTANCE IS EXPRESSLY LIMITED TO THESE
TERMS.
LICENSE AND WARRANTY: The Licensed Product and the embedded Software which is
made the subject of this License is either the property of SILICON LABS or a
third party from whom SILICON LABS has the authorization to distribute to you
subject to the terms of this Agreement. This Licensed Product is protected by
state, federal, and international copyright law. Although SILICON LABS continues
to own the Licensed Product and the right to distribute the embedded third party
Software, you will have certain rights to use the Licensed Product and the
embedded Software after your acceptance of this License. Except as may be
modified by a license addendum which accompanies this License, your rights and
obligations with respect to the use of this Product and the embedded software
are as follows:
1. AS APPROPRIATE WITH RESPECT TO THE LICENSED PRODUCT, YOU MAY: Use, copy,
distribute and make derivative works of the Software for any purpose,
including commercial applications, subject to the following restrictions:
(i) The origin of this software must not be misrepresented; (ii) you must
not claim that you wrote the original software; (iii) altered source
versions must be plainly marked as such, and must not be misrepresented as
being the original software; and (iv) any notices contained in the Software
may not be removed or altered, including notices in source code versions.
2. YOU MAY NOT: (A) Sublicense, assign, rent or lease any portion of the
Licensed Product or the embedded Software; or (B) Remove any product
identification, copyright or other notices that appear on the Licensed
Product or embedded Software.
3. Limited Use: Use of any of the Software is strictly limited to use in
systems containing one or more SILICON LABS products when the Software is
enabled to be functional. Any unauthorized use is expressly prohibited and
will constitute a breach of this Agreement.
4. Warranty: SILICON LABS does not warrant that the Licensed Product or
embedded Software will meet your requirements or that operation of the
Licensed Product will be uninterrupted or that the embedded Software will be
error-free. You agree that the Licensed Product is provided "AS IS" and
that SILICON LABS makes no warranty as to the Licensed Product or embedded
Software. SILICON LABS DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT, RELATED TO THE
SOFTWARE, ITS USE OR ANY INABILITY TO USE IT, THE RESULTS OF ITS USE AND
THIS AGREEMENT.
YOU MAY HAVE OTHER RIGHTS, WHICH VARY FROM STATE TO STATE.
5. Disclaimer of Damages: IN NO EVENT WILL SILICON LABS BE LIABLE TO YOU FOR
ANY SPECIAL, CONSEQUENTIAL, INDIRECT, OR SIMILAR DAMAGES, INCLUDING ANY LOST
PROFITS OR LOST DATA ARISING OUT OF THE USE OR INABILITY TO USE THE LICENSED
PRODUCT EVEN IF SILICON LABS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
SOME STATES DO NOT ALLOW THE LIMITATION OR EXCLUSION OF LIABILITY FOR
INCIDENTAL OR CONSEQUENTIAL DAMAGES. SO THE ABOVE LIMITATION OR EXCLUSION
MAY NOT APPLY TO YOU.
IN NO CASE SHALL SILICON LABS' LIABILITY EXCEED THE PURCHASE PRICE FOR THE
LICENSED PRODUCT. The disclaimers and limitations set forth above will
apply regardless of whether you accept the Licensed Software.
6. Term and Termination: The term of this Agreement and the License granted
herein shall begin upon use of the Licensed Product and continue in
perpetuity unless you breach any of the obligations set out under this
Agreement. Upon your breach of this Agreement by you, the license granted
hereunder shall terminate immediately and you shall cease all use of the
Licensed Products and return same as well as any copies of the Licensed
Product and/or embedded Software to SILICON LABS immediately. Termination
of this License upon your breach is only one remedy available to SILICON
LABS. In addition to termination of this Agreement upon your breach,
SILICON LABS shall be entitled to seek any and all other available remedies,
at law or at equity, arising from your breach.
7. Export: You shall comply with all applicable federal, provincial, state and
local laws, regulations and ordinances including but not limited to
applicable U.S. Export Administration Laws and Regulations. You shall not
export or re-export, or allow the export or re-export of the Licensed
Product, any component of the Licensed Product, or any copy of the embedded
Software in violation of any such restrictions, laws or regulations, or to
Cuba, Libya, North Korea, Iran, Iraq, or Rwanda or to any Group D:1 or E:2
country (or any national of such country) specified in the then current
Supplement No. 1 to Part 740, or, in violation of the embargo provisions in
Part 746, of the U.S. Export Administration Regulations (or any successor
regulations or supplement), except in compliance with and with all licenses
and approvals required under applicable export laws and regulations,
including without limitation, those of the U.S. Department of Commerce.
8. General: This Agreement will be governed by the laws of the State of Texas
and any applicable federal laws or regulations. The waiver by either Party
of any default or breach of this Agreement shall not constitute a waiver of
any other or subsequent default or breach. This Agreement constitutes the
complete and exclusive statement of the mutual understanding between you and
SILICON LABS with respect to this subject matter herein. This Agreement may
only be modified by a written addendum, which has been signed by both you
and SILICON LABS. Should you have any questions concerning this Agreement,
or if you desire to contact SILICON LABS for any reason, please write:
Silicon Laboratories, Inc.
400 West Cesar Chavez
Austin, Texas 78701, U.S.A.
/***************************************************************************//**
* @file
* @brief Board support package API definitions.
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __BSP_H
#define __BSP_H
#include <stdbool.h>
#include "bspconfig.h"
#if defined( BSP_STK )
#include "em_usart.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup BSPCOMMON API common for all kits */ /** @{ */
#define BSP_STATUS_OK 0 /**< BSP API return code, no errors. */
#define BSP_STATUS_ILLEGAL_PARAM (-1) /**< BSP API return code, illegal input parameter. */
#define BSP_STATUS_NOT_IMPLEMENTED (-2) /**< BSP API return code, function not implemented (dummy). */
#define BSP_STATUS_UNSUPPORTED_MODE (-3) /**< BSP API return code, unsupported BSP mode. */
/* Initialization flag bitmasks for BSP_Init(). */
#define BSP_INIT_DK_SPI 0x01 /**< Mode flag for @ref BSP_Init(), init DK in SPI mode (DK3x50 only). */
#define BSP_INIT_DK_EBI 0x02 /**< Mode flag for @ref BSP_Init(), init DK in EBI mode (DK3x50 only). */
#define BSP_INIT_BCC 0x04 /**< Mode flag for @ref BSP_Init(), init board controller communication. */
/** @} */
#if defined( BSP_DK )
/** @addtogroup BSP_DK API for DK's */ /** @{ */
/** Display Control */
typedef enum
{
BSP_Display_EBI, /**< SSD2119 TFT controller driven by EFM32 EBI interface */
BSP_Display_SPI, /**< SSD2119 TFT controller driven by EFM32 SPI interface */
BSP_Display_BC, /**< SSD2119 TFT controller driven by board controller (AEM) */
BSP_Display_PowerEnable, /**< SSD2119 Enable power */
BSP_Display_PowerDisable, /**< SSD2119 Disable power */
BSP_Display_ResetAssert, /**< Hold SSD2119 in reset */
BSP_Display_ResetRelease, /**< Release SSD2119 in reset */
BSP_Display_Mode8080, /**< Configure SSD2119 for 8080 mode of operation */
BSP_Display_ModeGeneric, /**< Configure SSD2119 for Generic+SPI mode of operation */
} BSP_Display_TypeDef;
/** Bus control access mode */
typedef enum
{
BSP_BusControl_Undefined=0, /**< Board control mode unknown (not set) */
BSP_BusControl_OFF, /**< Board control disable */
BSP_BusControl_DIRECT, /**< GPIO direct drive (n/a) */
BSP_BusControl_SPI, /**< Configure Board controller for SPI mode */
BSP_BusControl_EBI, /**< Configure Board controller for EBI mode */
} BSP_BusControl_TypeDef;
#if defined( BSP_DK_3200 ) /* Gxxx_DK */
/** Peripherals control structure for Gxxx_DK's. */
typedef enum
{
BSP_ACCEL = BC_PERCTRL_ACCEL, /**< Accelerometer */
BSP_AMBIENT = BC_PERCTRL_AMBIENT, /**< Light sensor */
BSP_POTMETER = BC_PERCTRL_POTMETER, /**< Potentiometer */
BSP_RS232A = BC_PERCTRL_RS232A, /**< Serial port A */
BSP_RS232B = BC_PERCTRL_RS232B, /**< Serial port B */
BSP_SPI = BC_PERCTRL_SPI, /**< SPI interface */
BSP_I2C = BC_PERCTRL_I2C, /**< I2C interface */
BSP_IRDA = BC_PERCTRL_IRDA, /**< IrDA interface */
BSP_ANALOG_SE = BC_PERCTRL_ANALOG_SE, /**< Single ended analog input */
BSP_ANALOG_DIFF = BC_PERCTRL_ANALOG_DIFF, /**< Differential analog input */
BSP_AUDIO_OUT = BC_PERCTRL_AUDIO_OUT, /**< Audio Out */
BSP_AUDIO_IN = BC_PERCTRL_AUDIO_IN, /**< Audio In */
BSP_ACCEL_GSEL = BC_PERCTRL_ACCEL_GSEL, /**< Accelerometer range select */
BSP_ACCEL_SELFTEST = BC_PERCTRL_ACCEL_SELFTEST, /**< Accelerometer selftest mode */
BSP_RS232_SHUTDOWN = BC_PERCTRL_RS232_SHUTDOWN, /**< Disable RS232 */
BSP_IRDA_SHUTDOWN = BC_PERCTRL_IRDA_SHUTDOWN /**< Disable IrDA */
#ifdef DOXY_DOC_ONLY
} BSP_Peripheral_Typedef; /* Hack for doxygen doc ! */
#else
} BSP_Peripheral_TypeDef;
#endif
#endif /* BSP_DK_3200 */
#if defined( BSP_DK_3201 ) /* DK3x50 DK's */
/** Peripherals control structure for DK3x50 DK's. */
typedef enum
{
BSP_RS232_SHUTDOWN, /**< Disable RS232 */
BSP_RS232_UART, /**< UART control of RS232 */
BSP_RS232_LEUART, /**< LEUART control of RS232 */
BSP_I2C, /**< I2C interface */
BSP_ETH, /**< Ethernet */
BSP_I2S, /**< Audio I2S */
BSP_TRACE, /**< ETM Trace */
BSP_TOUCH, /**< Display touch interface */
BSP_AUDIO_IN, /**< Audio In */
BSP_AUDIO_OUT, /**< Audio Out */
BSP_ANALOG_DIFF, /**< Differential analog input */
BSP_ANALOG_SE, /**< Single ended analog input */
BSP_MICROSD, /**< MicroSD SPI interace */
BSP_TFT, /**< SSD2119 TFT controller */
} BSP_Peripheral_TypeDef;
#endif /* BSP_DK_3201 */
/** @} */
#endif /* BSP_DK */
/************************** The BSP API *******************************/
int BSP_Disable ( void );
int BSP_Init ( uint32_t flags );
int BSP_LedClear ( int ledNo );
int BSP_LedGet ( int ledNo );
int BSP_LedSet ( int ledNo );
uint32_t BSP_LedsGet ( void );
int BSP_LedsInit ( void );
int BSP_LedsSet ( uint32_t leds );
int BSP_LedToggle ( int ledNo );
#if defined( BSP_DK )
BSP_BusControl_TypeDef BSP_BusControlModeGet( void );
int BSP_BusControlModeSet ( BSP_BusControl_TypeDef mode );
uint32_t BSP_DipSwitchGet ( void );
int BSP_DisplayControl ( BSP_Display_TypeDef option );
int BSP_EbiExtendedAddressRange ( bool enable );
int BSP_EnergyModeSet ( uint16_t energyMode );
int BSP_InterruptDisable ( uint16_t flags );
int BSP_InterruptEnable ( uint16_t flags );
int BSP_InterruptFlagsClear ( uint16_t flags );
int BSP_InterruptFlagsSet ( uint16_t flags );
uint16_t BSP_InterruptFlagsGet ( void );
uint16_t BSP_JoystickGet ( void );
int BSP_McuBoard_DeInit ( void );
int BSP_McuBoard_Init ( void );
int BSP_McuBoard_UsbStatusLedEnable ( bool enable );
bool BSP_McuBoard_UsbVbusOcFlagGet ( void );
int BSP_McuBoard_UsbVbusPowerEnable ( bool enable );
int BSP_PeripheralAccess ( BSP_Peripheral_TypeDef perf, bool enable );
uint16_t BSP_PushButtonsGet ( void );
uint16_t BSP_RegisterRead ( volatile uint16_t *addr );
int BSP_RegisterWrite ( volatile uint16_t *addr, uint16_t data );
#endif
#if defined( BSP_STK )
int BSP_BccDeInit ( void );
int BSP_BccInit ( void );
bool BSP_BccPacketReceive ( BCP_Packet *pkt );
int BSP_BccPacketSend ( BCP_Packet *pkt );
void BSP_BccPinsEnable ( bool enable );
float BSP_CurrentGet ( void );
int BSP_EbiDeInit ( void );
int BSP_EbiInit ( void );
float BSP_VoltageGet ( void );
#endif
#ifdef __cplusplus
}
#endif
#endif /* __BSP_H */
/***************************************************************************//**
* @file
* @brief Board Controller Communications (BCC) definitions
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#include <string.h>
#include "em_device.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "bsp.h"
#if defined( BSP_BCC_LEUART )
#include "em_leuart.h"
#else
#include "em_usart.h"
#endif
#if defined( BSP_STK )
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
/* Module local variables */
static uint32_t rxByteCount;
static uint32_t txByteCount;
/* Module local prototypes */
static void TxByte( uint8_t data );
static uint8_t RxByte( void );
/** @endcond */
/***************************************************************************//**
* @addtogroup BSP
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup BSP_STK API for STK's
* @{
******************************************************************************/
/**************************************************************************//**
* @brief Deinitialize board controller communication support (BCC)
* functionality. Reverse actions performed by @ref BSP_BccInit().
*
* @return @ref BSP_STATUS_OK.
*****************************************************************************/
int BSP_BccDeInit( void )
{
/* Reset counters */
rxByteCount = 0xFFFFFFFFUL;
txByteCount = 0xFFFFFFFFUL;
BSP_BccPinsEnable( false );
#if defined( BSP_BCC_LEUART )
/* Reset LEUART */
LEUART_Reset( BSP_BCC_LEUART );
#else
/* Reset USART */
USART_Reset( BSP_BCC_USART );
#endif
/* Disable clock */
CMU_ClockEnable( BSP_BCC_CLK, false );
return BSP_STATUS_OK;
}
/**************************************************************************//**
* @brief Initialize board controller communication support (BCC)
* functionality.
*
* @return @ref BSP_STATUS_OK.
*****************************************************************************/
int BSP_BccInit( void )
{
#if defined( BSP_BCC_LEUART )
LEUART_Init_TypeDef leuartInit = LEUART_INIT_DEFAULT;
#else
USART_InitAsync_TypeDef usartInit = USART_INITASYNC_DEFAULT;
#endif
rxByteCount = 0;
txByteCount = 0;
/* Enable High Frequency Peripherals */
CMU_ClockEnable(cmuClock_HFPER, true);
/* Enable clocks to GPIO */
CMU_ClockEnable(cmuClock_GPIO, true);
/* Enable UART clock */
CMU_ClockEnable( BSP_BCC_CLK, true );
#if defined( BSP_BCC_LEUART )
/* Enable CORE LE clock in order to access LE modules */
CMU_ClockEnable(cmuClock_CORELE, true);
/* Select CORE LE clock for LE modules */
CMU_ClockSelectSet( cmuClock_LFB, cmuSelect_CORELEDIV2 );
/* Initialize LEUART */
leuartInit.baudrate = 115200;
LEUART_Init( BSP_BCC_LEUART, &leuartInit );
#else
/* Initialize USART */
USART_InitAsync( BSP_BCC_USART, &usartInit );
#endif
/* Initialize UART pins */
BSP_BccPinsEnable( true );
return BSP_STATUS_OK;
}
/**************************************************************************//**
* @brief Get a packet from the board controller.
*
* @param[in] pkt Pointer to a @ref BCP_Packet instance.
*
* @return True if packet received without errors, false otherwise.
*****************************************************************************/
bool BSP_BccPacketReceive( BCP_Packet *pkt )
{
int i;
int length;
uint8_t *bptr;
/* Setup a byte pointer to start of packet buffer */
bptr = (uint8_t *) pkt;
/* Receive packet magic */
*bptr++ = RxByte();
if (pkt->magic != BSP_BCP_MAGIC)
{
return false;
}
/* Receive packet type */
*bptr++ = RxByte();
if ( (pkt->type < BSP_BCP_FIRST) || (pkt->type > BSP_BCP_LAST) )
{
return false;
}
/* Receive packet length */
*bptr++ = RxByte();
if (pkt->payloadLength > BSP_BCP_PACKET_SIZE)
{
return false;
}
#if ( BSP_BCP_VERSION == 2 )
/* Receive reserved byte */
*bptr++ = RxByte();
#endif
/* Receive packet data length field and sanity check it */
length = pkt->payloadLength;
if (length > BSP_BCP_PACKET_SIZE)
{
length = BSP_BCP_PACKET_SIZE;
}
/* Receive packet payload */
for( i=0; i<length; i++ )
{
*bptr++ = RxByte();
}
return true;
}
/**************************************************************************//**
* @brief Send a packet to the board controller.
*
* @param[in] pkt Pointer to a @ref BCP_Packet instance.
*
* @return @ref BSP_STATUS_OK.
*****************************************************************************/
int BSP_BccPacketSend( BCP_Packet *pkt )
{
int i;
/* Apply magic */
pkt->magic = BSP_BCP_MAGIC;
/* Transmit packet magic */
TxByte( pkt->magic );
/* Transmit packet type */
TxByte( pkt->type );
/* Transmit packet length */
TxByte( pkt->payloadLength );
#if ( BSP_BCP_VERSION == 2 )
/* Transmit reserved byte */
TxByte( pkt->reserved );
#endif
/* Transmit packet payload */
for ( i=0; i<pkt->payloadLength; i++ )
{
TxByte( pkt->data[i] );
}
return BSP_STATUS_OK;
}
/**************************************************************************//**
* @brief Enable GPIO pins for the USART/LEUART used for board communication.
*
* @param[in] enable Set to true to enable pins, set to false to disable.
*****************************************************************************/
void BSP_BccPinsEnable( bool enable )
{
if (enable)
{
/* Configure GPIO pin for UART TX */
/* To avoid false start, configure output as high. */
GPIO_PinModeSet( BSP_BCC_TXPORT, BSP_BCC_TXPIN, gpioModePushPull, 1 );
/* Configure GPIO pin for UART RX */
GPIO_PinModeSet( BSP_BCC_RXPORT, BSP_BCC_RXPIN, gpioModeInput, 1 );
/* Enable the switch that enables UART communication. */
GPIO_PinModeSet( BSP_BCC_ENABLE_PORT, BSP_BCC_ENABLE_PIN, gpioModePushPull, 1 );
#if defined( BSP_BCC_LEUART )
BSP_BCC_LEUART->ROUTE |= LEUART_ROUTE_RXPEN | LEUART_ROUTE_TXPEN | BSP_BCC_LOCATION;
#else
BSP_BCC_USART->ROUTE |= USART_ROUTE_RXPEN | USART_ROUTE_TXPEN | BSP_BCC_LOCATION;
#endif
}
else
{
GPIO_PinModeSet( BSP_BCC_ENABLE_PORT, BSP_BCC_ENABLE_PIN, gpioModeDisabled, 0 );
#if defined( BSP_BCC_LEUART )
BSP_BCC_LEUART->ROUTE &= ~(LEUART_ROUTE_RXPEN | LEUART_ROUTE_TXPEN);
#else
BSP_BCC_USART->ROUTE &= ~(USART_ROUTE_RXPEN | USART_ROUTE_TXPEN);
#endif
GPIO_PinModeSet( BSP_BCC_TXPORT, BSP_BCC_TXPIN, gpioModeDisabled, 0 );
GPIO_PinModeSet( BSP_BCC_RXPORT, BSP_BCC_RXPIN, gpioModeDisabled, 0 );
}
}
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
static uint8_t RxByte( void )
{
uint8_t byte;
/* Poll RX data available flag and return a character when one is available */
#if defined( BSP_BCC_LEUART )
while (!(BSP_BCC_LEUART->IF & LEUART_IF_RXDATAV)) ;
byte = BSP_BCC_LEUART->RXDATA;
#else
while (!(BSP_BCC_USART->STATUS & USART_STATUS_RXDATAV)) ;
byte = BSP_BCC_USART->RXDATA;
#endif
rxByteCount++;
return byte;
}
static void TxByte( uint8_t data )
{
/* Check TX buffer and allow for a pending transfer to complete */
#if defined( BSP_BCC_LEUART )
while (!(BSP_BCC_LEUART->STATUS & LEUART_STATUS_TXBL)) ;
BSP_BCC_LEUART->TXDATA = (uint32_t) data;
#else
while (!(BSP_BCC_USART->STATUS & USART_STATUS_TXBL)) ;
BSP_BCC_USART->TXDATA = (uint32_t) data;
#endif
txByteCount++;
}
/** @endcond */
/** @} (end group BSP_STK) */
/** @} (end group BSP) */
#endif /* BSP_STK */
/**************************************************************************//**
* @file
* @brief Board Controller Communications Protocol (BCP) definitions
* @version 3.20.5
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __BSP_BCP_H
#define __BSP_BCP_H
#include <stdint.h>
#include "bspconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************//**
* @addtogroup BSP_STK API for STK's
* @{
******************************************************************************/
/* BCP Packet Types */
#define BSP_BCP_INVALID 0 /**< Invalid packet received */
#define BSP_BCP_FIRST 1 /**< Smallest numerical value of message type */
#define BSP_BCP_ACK 5 /**< Generic ACK for one way packages */
#define BSP_BCP_ECHO_REQ 10 /**< EFM32 BC alive request */
#define BSP_BCP_ECHO_REPLY 11 /**< BC alive response */
#define BSP_BCP_CURRENT_REQ 14 /**< EFM32 Request AEM current */
#define BSP_BCP_CURRENT_REPLY 16 /**< BC Response AEM current */
#define BSP_BCP_VOLTAGE_REQ 18 /**< EFM32 Request AEM voltage */
#define BSP_BCP_VOLTAGE_REPLY 20 /**< BC Response AEM voltage */
#define BSP_BCP_ENERGYMODE 22 /**< EFM32 Report Energy Mode (for AEM) */
#define BSP_BCP_STDOUT 24 /**< Debug packet (not used) */
#define BSP_BCP_STDERR 26 /**< Debug packet (not used) */
#define BSP_BCP_TEST 32 /**< Reserved type for test */
#define BSP_BCP_TEST_REPLY 33 /**< Reserved type for test (reply) */
#define BSP_BCP_NET_REQUEST 64 /**< Net gateway request packet */
#define BSP_BCP_NET_REPLY 65 /**< Net gateway reply packet */
#define BSP_BCP_LAST 100 /**< Last defined message type */
#define BSP_BCP_MAGIC 0xF1 /**< Magic byte to indicate start of packet */
#if ( ( BSP_BCP_VERSION == 1 ) || DOXY_DOC_ONLY )
#ifdef DOXY_DOC_ONLY
/* Hack for doxygen doc ! */
#define BSP_BCP_PACKET_SIZe 30 /**< Max packet size for version 1 of the protocol. */
#else
#define BSP_BCP_PACKET_SIZE 30 /**< Max packet size for version 1 of the protocol. */
#endif
/** @brief BCP Packet Structure - Board controller communication protocol version 1. */
typedef struct
{
uint8_t magic; /**< Magic - start of packet - must be BSP_BCP_MAGIC */
uint8_t type; /**< Type of packet */
uint8_t payloadLength; /**< Length of data segment >=0 and <=BSP_BCP_PACKET_SIZE */
uint8_t data[BSP_BCP_PACKET_SIZE]; /**< BCP Packet Data payload */
#ifdef DOXY_DOC_ONLY
} BCP_Packet_; /* Hack for doxygen doc ! */
#else
} BCP_Packet;
#endif
#endif
#if ( ( BSP_BCP_VERSION == 2 ) || DOXY_DOC_ONLY )
#define BSP_BCP_PACKET_SIZE 132 /**< Max packet size for version 2 of the protocol. */
/** @brief BCP Packet Structure - Board controller communication protocol version 2. */
typedef struct
{
uint8_t magic; /**< Magic - start of packet - must be BSP_BCP_MAGIC */
uint8_t type; /**< Type - packet type */
uint8_t payloadLength; /**< Length of data segment >=0 and <=BSP_BCP_PACKET_SIZE */
uint8_t reserved; /**< Reserved for future expansion */
uint8_t data[BSP_BCP_PACKET_SIZE]; /**< BCP Packet Data payload */
} BCP_Packet;
/** @brief BCP Packet Header definition */
typedef struct
{
uint8_t magic; /**< Magic - start of packet - must be BSP_BCP_MAGIC */
uint8_t type; /**< Type - packet type */
uint8_t payloadLength; /**< Length of data segment >=0 and <=BSP_BCP_PACKET_SIZE */
uint8_t reserved; /**< Reserved for future expansion */
} BCP_PacketHeader;
#endif
#if ( ( BSP_BCP_VERSION != 1 ) && ( BSP_BCP_VERSION != 2 ) )
#error "BSP BCP Board Controller communications protocol version error."
#endif
#if ( BSP_BCP_PACKET_SIZE >= 255 )
#error "BSP BCP Board Controller communications packets must be less than 255 bytes in size!"
#endif
/** @} (end group BSP_STK) */
#ifdef __cplusplus
}
#endif
#endif /* __BSP_BCP_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/***************************************************************************//**
* @file
* @brief Board support package API for GPIO leds on STK's.
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#include "bsp.h"
#if defined( BSP_DK_LEDS )
/***************************************************************************//**
* @addtogroup BSPCOMMON API common for all kits
* @{
******************************************************************************/
/**************************************************************************//**
* @brief Initialize LED drivers.
* @note LED's are initially turned off.
* @return
* @ref BSP_STATUS_OK
*****************************************************************************/
int BSP_LedsInit(void)
{
BSP_RegisterWrite(BSP_LED_PORT, 0);
return BSP_STATUS_OK;
}
/**************************************************************************//**
* @brief Get status of all LED's.
* @return
* Bitmask with current status for all LED's.
*****************************************************************************/
uint32_t BSP_LedsGet(void)
{
return BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
}
/**************************************************************************//**
* @brief Update all LED's.
* @param[in] leds Bitmask representing new status for all LED's. A 1 turns
* a LED on, a 0 turns a LED off.
* @return
* @ref BSP_STATUS_OK
*****************************************************************************/
int BSP_LedsSet(uint32_t leds)
{
BSP_RegisterWrite(BSP_LED_PORT, leds & BSP_LED_MASK);
return BSP_STATUS_OK;
}
/**************************************************************************//**
* @brief Turn off a single LED.
* @param[in] ledNo The number of the LED (counting from zero) to turn off.
* @return
* @ref BSP_STATUS_OK or @ref BSP_STATUS_ILLEGAL_PARAM if illegal LED number.
*****************************************************************************/
int BSP_LedClear(int ledNo)
{
uint32_t tmp;
if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
{
tmp = BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
tmp &= ~( 1 << ledNo );
BSP_RegisterWrite(BSP_LED_PORT, tmp);
return BSP_STATUS_OK;
}
return BSP_STATUS_ILLEGAL_PARAM;
}
/**************************************************************************//**
* @brief Get current status of a single LED.
* @param[in] ledNo The number of the LED (counting from zero) to check.
* @return
* 1 if LED is on, 0 if LED is off, @ref BSP_STATUS_ILLEGAL_PARAM if illegal
* LED number.
*****************************************************************************/
int BSP_LedGet(int ledNo)
{
if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
{
if ( BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK & (1 << ledNo) )
return 1;
return 0;
}
return BSP_STATUS_ILLEGAL_PARAM;
}
/**************************************************************************//**
* @brief Turn on a single LED.
* @param[in] ledNo The number of the LED (counting from zero) to turn on.
* @return
* @ref BSP_STATUS_OK or @ref BSP_STATUS_ILLEGAL_PARAM if illegal LED number.
*****************************************************************************/
int BSP_LedSet(int ledNo)
{
uint32_t tmp;
if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
{
tmp = BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
tmp |= 1 << ledNo;
BSP_RegisterWrite(BSP_LED_PORT, tmp);
return BSP_STATUS_OK;
}
return BSP_STATUS_ILLEGAL_PARAM;
}
/**************************************************************************//**
* @brief Toggle a single LED.
* @param[in] ledNo The number of the LED (counting from zero) to toggle.
* @return
* @ref BSP_STATUS_OK or @ref BSP_STATUS_ILLEGAL_PARAM if illegal LED number.
*****************************************************************************/
int BSP_LedToggle(int ledNo)
{
uint32_t tmp;
if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
{
tmp = BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
tmp ^= 1 << ledNo;
BSP_RegisterWrite(BSP_LED_PORT, tmp);
return BSP_STATUS_OK;
}
return BSP_STATUS_ILLEGAL_PARAM;
}
/** @} */
#endif /* BSP_DK_LEDS */
/***************************************************************************//**
* @file
* @brief Board support package API for functions on MCU plugin boards.
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#include <stdbool.h>
#include "bsp.h"
#include "em_gpio.h"
#include "em_cmu.h"
/***************************************************************************//**
* @addtogroup BSP
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup BSP_DK API for DK's
* @{
******************************************************************************/
/**************************************************************************//**
* @brief Disable MCU plugin board peripherals.
* @return @ref BSP_STATUS_OK.
*****************************************************************************/
int BSP_McuBoard_DeInit( void )
{
#ifdef BSP_MCUBOARD_USB
/* Disable GPIO port pin mode. */
GPIO_PinModeSet( BSP_USB_STATUSLED_PORT, BSP_USB_STATUSLED_PIN, gpioModeDisabled, 0 );
GPIO_PinModeSet( BSP_USB_OCFLAG_PORT, BSP_USB_OCFLAG_PIN, gpioModeDisabled, 0 );
GPIO_PinModeSet( BSP_USB_VBUSEN_PORT, BSP_USB_VBUSEN_PIN, gpioModeDisabled, 0 );
#endif
return BSP_STATUS_OK;
}
/**************************************************************************//**
* @brief Enable MCU plugin board peripherals.
* @return @ref BSP_STATUS_OK.
*****************************************************************************/
int BSP_McuBoard_Init( void )
{
#ifdef BSP_MCUBOARD_USB
/* Make sure that the CMU clock to the GPIO peripheral is enabled */
CMU_ClockEnable( cmuClock_GPIO, true );
/* USB status LED - configure PE1 as push pull */
GPIO_PinModeSet( BSP_USB_STATUSLED_PORT, BSP_USB_STATUSLED_PIN, gpioModePushPull, 0 );
/* USB PHY overcurrent status input */
GPIO_PinModeSet( BSP_USB_OCFLAG_PORT, BSP_USB_OCFLAG_PIN, gpioModeInput, 0 );
/* USB VBUS switch - configure PF5 as push pull - Default OFF */
GPIO_PinModeSet( BSP_USB_VBUSEN_PORT, BSP_USB_VBUSEN_PIN, gpioModePushPull, 0 );
#endif
return BSP_STATUS_OK;
}
/**************************************************************************//**
* @brief Set state of MCU plugin board USB status LED.
* @param[in] enable Set to true to turn on LED, false to turn off.
* @return @ref BSP_STATUS_OK on plugin boards with USB capability,
* @ref BSP_STATUS_NOT_IMPLEMENTED otherwise.
*****************************************************************************/
int BSP_McuBoard_UsbStatusLedEnable( bool enable )
{
#ifdef BSP_MCUBOARD_USB
if ( enable )
{
GPIO_PinOutSet( BSP_USB_STATUSLED_PORT, BSP_USB_STATUSLED_PIN );
}
else
{
GPIO_PinOutClear( BSP_USB_STATUSLED_PORT, BSP_USB_STATUSLED_PIN );
}
return BSP_STATUS_OK;
#else
(void)enable;
return BSP_STATUS_NOT_IMPLEMENTED;
#endif
}
/**************************************************************************//**
* @brief Get state MCU plugin board VBUS overcurrent flag.
* @return True if overcurrent situation exist, false otherwise.
*****************************************************************************/
bool BSP_McuBoard_UsbVbusOcFlagGet( void )
{
#ifdef BSP_MCUBOARD_USB
bool flag;
if ( !GPIO_PinInGet( BSP_USB_OCFLAG_PORT, BSP_USB_OCFLAG_PIN ) )
{
flag = true;
}
else
{
flag = false;
}
return flag;
#else
return false;
#endif
}
/**************************************************************************//**
* @brief Enable MCU plugin board VBUS power switch.
* @param[in] enable Set to true to turn on VBUS power, false to turn off.
* @return @ref BSP_STATUS_OK on plugin boards with USB capability,
* @ref BSP_STATUS_NOT_IMPLEMENTED otherwise.
*****************************************************************************/
int BSP_McuBoard_UsbVbusPowerEnable( bool enable )
{
#ifdef BSP_MCUBOARD_USB
GPIO_PinModeSet( BSP_USB_VBUSEN_PORT, BSP_USB_VBUSEN_PIN, gpioModePushPull, enable );
return BSP_STATUS_OK;
#else
(void)enable;
return BSP_STATUS_NOT_IMPLEMENTED;
#endif
}
/** @} (end group BSP_DK) */
/** @} (end group BSP) */
/***************************************************************************//**
* @file
* @brief Board support package API implementation STK's.
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#include <string.h>
#include "em_device.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "bsp.h"
#if defined( BSP_STK_USE_EBI )
#include "em_ebi.h"
#endif
#if defined( BSP_STK )
/***************************************************************************//**
* @addtogroup BSP
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup BSP_STK API for STK's
* @{
******************************************************************************/
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
/**************************************************************************//**
* @brief Deinitialize board support package functionality.
* Reverse actions performed by @ref BSP_Init().
*
* @return @ref BSP_STATUS_OK.
*****************************************************************************/
int BSP_Disable(void)
{
BSP_BccDeInit();
BSP_EbiDeInit();
return BSP_STATUS_OK;
}
/** @endcond */
/**************************************************************************//**
* @brief Initialize the EBI interface for accessing the onboard nandflash.
*
* @note This function is not relevant for Gxxx_STK's.
*
* @return
* @ref BSP_STATUS_OK or @ref BSP_STATUS_NOT_IMPLEMENTED
*****************************************************************************/
int BSP_EbiInit(void)
{
#if defined( BSP_STK_USE_EBI )
/* ------------------------------------------ */
/* NAND Flash, Bank0, Base Address 0x80000000 */
/* Micron flash NAND256W3A */
/* ------------------------------------------ */
EBI_Init_TypeDef ebiConfig =
{ ebiModeD8A8, /* 8 bit address, 8 bit data */
ebiActiveLow, /* ARDY polarity */
ebiActiveLow, /* ALE polarity */
ebiActiveLow, /* WE polarity */
ebiActiveLow, /* RE polarity */
ebiActiveLow, /* CS polarity */
ebiActiveLow, /* BL polarity */
false, /* disble BL */
true, /* enable NOIDLE */
false, /* disable ARDY */
true, /* disable ARDY timeout */
EBI_BANK0, /* enable bank 0 */
0, /* no chip select */
0, /* addr setup cycles */
0, /* addr hold cycles */
false, /* disable half cycle ALE strobe */
0, /* read setup cycles */
2, /* read strobe cycles */
1, /* read hold cycles */
false, /* disable page mode */
false, /* disable prefetch */
false, /* disable half cycle REn strobe */
0, /* write setup cycles */
2, /* write strobe cycles */
1, /* write hold cycles */
false, /* enable the write buffer */
false, /* disable half cycle WEn strobe */
ebiALowA24, /* ALB - Low bound, address lines */
ebiAHighA26, /* APEN - High bound, address lines */
ebiLocation1, /* Use Location 1 */
true, /* enable EBI */
};
/* Enable clocks */
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_EBI, true);
/* Enable GPIO's */
/* ALE and CLE */
GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortC, 2, gpioModePushPull, 0);
/* WP, CE and R/B */
GPIO_PinModeSet(gpioPortD, 13, gpioModePushPull, 0); /* active low write-protect */
GPIO_PinModeSet(gpioPortD, 14, gpioModePushPull, 1); /* active low chip-enable */
GPIO_PinModeSet(gpioPortD, 15, gpioModeInput, 0); /* ready/busy */
/* IO pins */
GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
/* WE and RE */
GPIO_PinModeSet(gpioPortF, 8, gpioModePushPull, 1);
GPIO_PinModeSet(gpioPortF, 9, gpioModePushPull, 1);
/* NAND Power Enable */
GPIO_PinModeSet(gpioPortB, 15, gpioModePushPull, 1);
EBI_Init(&ebiConfig);
EBI->NANDCTRL = (EBI_NANDCTRL_BANKSEL_BANK0 | EBI_NANDCTRL_EN);
return BSP_STATUS_OK;
#else
return BSP_STATUS_NOT_IMPLEMENTED;
#endif
}
/**************************************************************************//**
* @brief Deinitialize the EBI interface for accessing the onboard nandflash.
*
* @note This function is not relevant for Gxxx_STK's.
* This function is provided for API completeness, it does not perform
* an actual EBI deinitialization.
*
* @return
* @ref BSP_STATUS_OK or @ref BSP_STATUS_NOT_IMPLEMENTED
*****************************************************************************/
int BSP_EbiDeInit( void )
{
#if defined( BSP_STK_USE_EBI )
return BSP_STATUS_OK;
#else
return BSP_STATUS_NOT_IMPLEMENTED;
#endif
}
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
/**************************************************************************//**
* @brief Initialize board support package functionality.
*
* @param[in] flags Initialization mask, use 0 or @ref BSP_INIT_BCC.
*
* @return
* @ref BSP_STATUS_OK
*****************************************************************************/
int BSP_Init( uint32_t flags )
{
if ( flags & BSP_INIT_BCC )
{
BSP_BccInit();
}
return BSP_STATUS_OK;
}
/** @endcond */
/**************************************************************************//**
* @brief Request AEM (Advanced Energy Monitoring) current from board controller.
*
* @note Assumes that BSP_Init() has been called with @ref BSP_INIT_BCC
* bitmask.
*
* @return
* The current expressed in milliamperes. Returns 0.0 on board controller
* communication error.
*****************************************************************************/
float BSP_CurrentGet( void )
{
BCP_Packet pkt;
float *pcurrent;
pkt.type = BSP_BCP_CURRENT_REQ;
pkt.payloadLength = 0;
/* Send Request/Get reply */
BSP_BccPacketSend( &pkt );
BSP_BccPacketReceive( &pkt );
/* Process reply */
pcurrent = (float *)pkt.data;
if ( pkt.type != BSP_BCP_CURRENT_REPLY )
{
*pcurrent = 0.0f;
}
return *pcurrent;
}
/**************************************************************************//**
* @brief Request AEM (Advanced Energy Monitoring) voltage from board controller.
*
* @note Assumes that BSP_Init() has been called with @ref BSP_INIT_BCC
* bitmask.
*
* @return
* The voltage. Returns 0.0 on board controller communication
* error.
*****************************************************************************/
float BSP_VoltageGet( void )
{
BCP_Packet pkt;
float *pvoltage;
pkt.type = BSP_BCP_VOLTAGE_REQ;
pkt.payloadLength = 0;
/* Send Request/Get reply */
BSP_BccPacketSend( &pkt );
BSP_BccPacketReceive( &pkt );
/* Process reply */
pvoltage = (float *)pkt.data;
if ( pkt.type != BSP_BCP_VOLTAGE_REPLY )
{
*pvoltage = 0.0f;
}
return *pvoltage;
}
/** @} (end group BSP_STK) */
/** @} (end group BSP) */
#endif /* BSP_STK */
/***************************************************************************//**
* @file
* @brief Board support package API for GPIO leds on STK's.
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#include "em_device.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "bsp.h"
#if defined( BSP_GPIO_LEDS )
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
typedef struct
{
GPIO_Port_TypeDef port;
unsigned int pin;
} tLedArray;
static const tLedArray ledArray[ BSP_NO_OF_LEDS ] = BSP_GPIO_LEDARRAY_INIT;
int BSP_LedsInit(void)
{
int i;
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPIO, true);
for ( i=0; i<BSP_NO_OF_LEDS; i++ )
{
GPIO_PinModeSet(ledArray[i].port, ledArray[i].pin, gpioModePushPull, 0);
}
return BSP_STATUS_OK;
}
uint32_t BSP_LedsGet(void)
{
int i;
uint32_t retVal, mask;
for ( i=0, retVal=0, mask=0x1; i<BSP_NO_OF_LEDS; i++, mask <<= 1 )
{
if (GPIO_PinOutGet(ledArray[i].port, ledArray[i].pin))
retVal |= mask;
}
return retVal;
}
int BSP_LedsSet(uint32_t leds)
{
int i;
uint32_t mask;
for ( i=0, mask=0x1; i<BSP_NO_OF_LEDS; i++, mask <<= 1 )
{
if ( leds & mask )
GPIO_PinOutSet(ledArray[i].port, ledArray[i].pin);
else
GPIO_PinOutClear(ledArray[i].port, ledArray[i].pin);
}
return BSP_STATUS_OK;
}
int BSP_LedClear(int ledNo)
{
if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
{
GPIO_PinOutClear(ledArray[ledNo].port, ledArray[ledNo].pin);
return BSP_STATUS_OK;
}
return BSP_STATUS_ILLEGAL_PARAM;
}
int BSP_LedGet(int ledNo)
{
int retVal = BSP_STATUS_ILLEGAL_PARAM;
if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
{
retVal = (int)GPIO_PinOutGet(ledArray[ledNo].port, ledArray[ledNo].pin);
}
return retVal;
}
int BSP_LedSet(int ledNo)
{
if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
{
GPIO_PinOutSet(ledArray[ledNo].port, ledArray[ledNo].pin);
return BSP_STATUS_OK;
}
return BSP_STATUS_ILLEGAL_PARAM;
}
int BSP_LedToggle(int ledNo)
{
if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
{
GPIO_PinOutToggle(ledArray[ledNo].port, ledArray[ledNo].pin);
return BSP_STATUS_OK;
}
return BSP_STATUS_ILLEGAL_PARAM;
}
/** @endcond */
#endif /* BSP_GPIO_LEDS */
/**************************************************************************//**
* @file
* @brief API for enabling SWO and ETM trace.
* @version 3.20.5
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#include <stdbool.h>
#include "em_device.h"
#include "em_gpio.h"
#include "em_cmu.h"
#include "bsp_trace.h"
#include "bsp.h"
#if defined(BSP_ETM_TRACE) && defined( ETM_PRESENT )
/**************************************************************************//**
* @brief Configure EFM32 for ETM trace output.
* @note You need to configure ETM trace on kit config menu as well!
*****************************************************************************/
void BSP_TraceEtmSetup(void)
{
/* Enable peripheral clocks */
CMU->HFCORECLKEN0 |= CMU_HFCORECLKEN0_LE;
CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
/* Wait until AUXHFRCO clock is ready */
while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
/* Enable Port D, pins 3,4,5,6 for ETM Trace Data output */
GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE3_MASK) | GPIO_P_MODEL_MODE3_PUSHPULL;
GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE4_MASK) | GPIO_P_MODEL_MODE4_PUSHPULL;
GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE5_MASK) | GPIO_P_MODEL_MODE5_PUSHPULL;
GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE6_MASK) | GPIO_P_MODEL_MODE6_PUSHPULL;
/* Enable Port D, pin 7 for DBG_TCLK */
GPIO->P[3].MODEL = (GPIO->P[3].MODEL & ~_GPIO_P_MODEL_MODE7_MASK) | GPIO_P_MODEL_MODE7_PUSHPULL;
/* Configure trace output for alternate location */
GPIO->ROUTE = GPIO->ROUTE | GPIO_ROUTE_TCLKPEN | GPIO_ROUTE_TD0PEN | GPIO_ROUTE_TD1PEN
| GPIO_ROUTE_TD2PEN | GPIO_ROUTE_TD3PEN
| GPIO_ROUTE_ETMLOCATION_LOC0;
}
#endif
#if defined( GPIO_ROUTE_SWOPEN )
/**************************************************************************//**
* @brief Configure trace output for energyAware Profiler
* @note Enabling trace will add 80uA current for the EFM32_Gxxx_STK.
* DK's needs to be initialized with SPI-mode:
* @verbatim BSP_Init(BSP_INIT_DK_SPI); @endverbatim
*****************************************************************************/
void BSP_TraceSwoSetup(void)
{
/* Enable GPIO clock */
CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
/* Enable Serial wire output pin */
GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
/* Set correct location */
GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | BSP_TRACE_SWO_LOCATION;
/* Enable output on correct pin. */
TRACE_ENABLE_PINS();
/* Enable debug clock AUXHFRCO */
CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
/* Wait until clock is ready */
while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY)) ;
// Check if trace already enabled, if so assume that an external debugger
// is in control and skip further setup.
if ( !( CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk ) ) {
/* Enable trace in core debug */
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
/* Enable PC and IRQ sampling output */
DWT->CTRL = 0x400113FF;
/* Set TPIU prescaler to 16. */
TPI->ACPR = 0xf;
/* Set protocol to NRZ */
TPI->SPPR = 2;
/* Disable continuous formatting */
TPI->FFCR = 0x100;
/* Unlock ITM and output data */
ITM->LAR = 0xC5ACCE55;
ITM->TCR = 0x10009;
}
}
#endif
#if defined( GPIO_ROUTE_SWOPEN )
/**************************************************************************//**
* @brief Profiler configuration.
* @return true if energyAware Profiler/SWO is enabled, false if not
* @note If first word of the user page is zero, this will not
* enable SWO profiler output.
*****************************************************************************/
bool BSP_TraceProfilerSetup(void)
{
volatile uint32_t *userData = (uint32_t *) USER_PAGE;
/* Check magic "trace" word in user page */
if (*userData == 0x00000000UL)
{
return false;
}
else
{
BSP_TraceSwoSetup();
return true;
}
}
#endif
/**************************************************************************//**
* @file
* @brief SWO Trace API (for eAProfiler)
* @version 3.20.5
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __BSP_TRACE_H
#define __BSP_TRACE_H
#include "em_device.h"
#if (defined(BSP_ETM_TRACE) && defined( ETM_PRESENT )) || defined( GPIO_ROUTE_SWOPEN )
#include <stdint.h>
#include <stdbool.h>
#include "em_msc.h"
#include "traceconfig.h"
/***************************************************************************//**
* @addtogroup BSP
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup BSPCOMMON API common for all kits
* @{
******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
#if defined(BSP_ETM_TRACE) && defined( ETM_PRESENT )
void BSP_TraceEtmSetup(void);
#endif
#if defined( GPIO_ROUTE_SWOPEN )
bool BSP_TraceProfilerSetup(void);
void BSP_TraceSwoSetup(void);
#endif
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
#define USER_PAGE 0x0FE00000UL /* Address to flash memory */
/** @endcond */
/**************************************************************************//**
* @brief Set or clear word in user page which enables or disables SWO
* in BSP_TraceProfilerSetup. If BSP_TraceProfilerEnable(false) has been run,
* no example project will enable SWO trace.
* @param[in] enable
* @note Add "em_msc.c" to build to use this function.
*****************************************************************************/
__STATIC_INLINE void BSP_TraceProfilerEnable(bool enable)
{
uint32_t data;
volatile uint32_t *userpage = (uint32_t *) USER_PAGE;
/* Check that configuration needs to change */
data = *userpage;
if (enable)
{
if (data == 0xFFFFFFFF)
{
return;
}
}
else
{
if (data == 0x00000000)
{
return;
}
}
/* Initialize MSC */
MSC_Init();
/* Write enable or disable trigger word into flash */
if (enable)
{
data = 0xFFFFFFFF;
MSC_ErasePage((uint32_t *) USER_PAGE);
MSC_WriteWord((uint32_t *) USER_PAGE, (void *) &data, 4);
}
else
{
data = 0x00000000;
MSC_ErasePage((uint32_t *) USER_PAGE);
MSC_WriteWord((uint32_t *) USER_PAGE, (void *) &data, 4);
}
}
#ifdef __cplusplus
}
#endif
/** @} (end group BSP) */
/** @} (end group BSP) */
#endif /* (defined(BSP_ETM_TRACE) && defined( ETM_PRESENT )) || defined( GPIO_ROUTE_SWOPEN ) */
#endif /* __BSP_TRACE_H */
This diff is collapsed.
/*
*
* Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
*
* This sample program was written and put in the public domain
* by Carlos E. Vidales. The program is provided "as is"
* without warranty of any kind, either expressed or implied.
* If you choose to use the program within your own products
* you do so at your own risk, and assume the responsibility
* for servicing, repairing or correcting the program should
* it prove defective in any manner.
* You may copy and distribute the program's source code in any
* medium, provided that you also include in each copy an
* appropriate copyright notice and disclaimer of warranty.
* You may also modify this program and distribute copies of
* it provided that you include prominent notices stating
* that you changed the file(s) and the date of any change,
* and that you do not charge any royalties or licenses for
* its use.
*
*
* File Name: calibrate.h
*
*
* Definition of constants and structures, and declaration of functions
* in Calibrate.c
*
*/
#ifndef _CALIBRATE_H_
#define _CALIBRATE_H_
/****************************************************/
/* */
/* Included files */
/* */
/****************************************************/
#include <math.h>
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************/
/* */
/* Definitions */
/* */
/****************************************************/
#ifndef _CALIBRATE_C_
#define EXTERN extern
#else
#define EXTERN
#endif
#ifndef OK
#define OK 0
#define NOT_OK -1
#endif
#define INT32 long
/****************************************************/
/* */
/* Structures */
/* */
/****************************************************/
typedef struct Point {
INT32 x,
y ;
} POINT ;
typedef struct Matrix {
/* This arrangement of values facilitates
* calculations within getDisplayPoint()
*/
INT32 An, /* A = An/Divider */
Bn, /* B = Bn/Divider */
Cn, /* C = Cn/Divider */
Dn, /* D = Dn/Divider */
En, /* E = En/Divider */
Fn, /* F = Fn/Divider */
Divider ;
} MATRIX ;
/****************************************************/
/* */
/* Function declarations */
/* */
/****************************************************/
EXTERN int setCalibrationMatrix( POINT * display,
POINT * screen,
MATRIX * matrix) ;
EXTERN int getDisplayPoint( POINT * display,
POINT * screen,
MATRIX * matrix ) ;
#ifdef __cplusplus
}
#endif
#endif /* _CALIBRATE_H_ */
This diff is collapsed.
/**************************************************************************//**
* @file
* @brief Capacitive sense driver
* @version 3.20.5
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __CAPLESENSE_H_
#define __CAPLESENSE_H_
#include <stdint.h>
#include <stdbool.h>
/***************************************************************************//**
* @addtogroup Drivers
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup CapSense
* @{
******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
uint8_t CAPLESENSE_getSegmentChannel(uint8_t capSegment);
uint32_t CAPLESENSE_getVal(uint8_t channel);
uint32_t CAPLESENSE_getNormalizedVal(uint8_t channel);
int32_t CAPLESENSE_getSliderPosition(void);
void CAPLESENSE_Init(bool sleep);
void CAPLESENSE_setupLESENSE(bool sleep);
void CAPLESENSE_setupCallbacks(void (*scanCb)(void), void (*chCb)(void));
void CAPLESENSE_Sleep(void);
#ifdef __cplusplus
}
#endif
/** @} (end group CapSense) */
/** @} (end group Drivers) */
#endif /* __CAPSENSE_H_ */
This diff is collapsed.
/**************************************************************************//**
* @file
* @brief Capacitive sense driver
* @version 3.20.5
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __CAPSENSE_H_
#define __CAPSENSE_H_
#include <stdint.h>
#include <stdbool.h>
#include "capsenseconfig.h"
/***************************************************************************//**
* @addtogroup Drivers
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup CapSense
* @{
******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
uint32_t CAPSENSE_getVal(uint8_t channel);
uint32_t CAPSENSE_getNormalizedVal(uint8_t channel);
bool CAPSENSE_getPressed(uint8_t channel);
int32_t CAPSENSE_getSliderPosition(void);
void CAPSENSE_Sense(void);
void CAPSENSE_Init(void);
#ifdef __cplusplus
}
#endif
/** @} (end group CapSense) */
/** @} (end group Drivers) */
#endif /* __CAPSENSE_H_ */
This diff is collapsed.
This diff is collapsed.
/**************************************************************************//**
* @file displaybackend.h
* @brief Display device backend interface
* @version 3.20.5
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef _DISPLAY_BACKEND_H_
#define _DISPLAY_BACKEND_H_
#include "display.h"
/***************************************************************************//**
* @addtogroup Drivers
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup Display
* @{
******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
************************** FUNCTION PROTOTYPES **************************
******************************************************************************/
EMSTATUS DISPLAY_DeviceRegister(DISPLAY_Device_t *device);
#ifdef __cplusplus
}
#endif
/** @} (end group Display) */
/** @} (end group Drivers) */
#endif /* _DISPLAY_BACKEND_H_ */
/***************************************************************************//**
* @file displayconfigall.h
* @brief Main configuration file for the DISPLAY driver software stack.
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __DISPLAYCONFIGALL_H
#define __DISPLAYCONFIGALL_H
/*
* First, we list the default INCLUDE_XXX #defines which may be excluded later
* by the kit or application specific configuration files.
*/
#define INCLUDE_PAL_GPIO_PIN_AUTO_TOGGLE
/* Then include the kit specific display configuration files which also includes
the application specific configuration file and further selects which modules
modules to include below. */
#include "displayconfig.h"
#ifdef INCLUDE_DISPLAY_SHARP_LS013B7DH03
#include "displaypalconfig.h"
#include "displayls013b7dh03config.h"
#endif
#ifdef INCLUDE_TEXTDISPLAY_SUPPORT
#include "textdisplayconfig.h"
#include "retargettextdisplayconfig.h"
#endif
#endif /* __DISPLAYCONFIGALL_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**************************************************************************//**
* @file emstatus.h
* @brief EMSTATUS definitions.
* @version 3.20.5
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef _EMSTATUS_H_
#define _EMSTATUS_H_
#include <stdint.h>
#include "em_types.h" /* typedef uint32_t EMSTATUS; */
/** Common EMSTATUS codes: */
#define EMSTATUS_OK (0) /**< Operation successful. */
/** EMSTATUS base codes for display modules. */
#define DISPLAY_EMSTATUS_BASE (0x8011UL<<16) /**< EMSTATUS base code of DISPLAY driver interface. */
#define TEXTDISPLAY_EMSTATUS_BASE (0x8012UL<<16) /**< EMSTATUS base code of TEXTDISPLAY module. */
#define PAL_EMSTATUS_BASE (0x8013UL<<16) /**< EMSTATUS base code of PAL interface. */
#endif /* _EMSTATUS_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment