diff --git a/.gitignore b/.gitignore index d76539fed1..690e4706a5 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ build-coverage .vs .vscode ninja +**/__pycache__ diff --git a/port/max32630-fthr/.gitignore b/port/max32630-fthr/.gitignore index cc3ffef5a0..a1fdf1900d 100644 --- a/port/max32630-fthr/.gitignore +++ b/port/max32630-fthr/.gitignore @@ -15,3 +15,5 @@ tags *.txt *.log core +example/*/* +!example/template/* \ No newline at end of file diff --git a/port/max32630-fthr/Makefile b/port/max32630-fthr/Makefile index 61a73d8d95..710d5f2753 100644 --- a/port/max32630-fthr/Makefile +++ b/port/max32630-fthr/Makefile @@ -6,6 +6,5 @@ examples: clean: scripts/delete_examples.py - @rm -rf example/Makefile - @echo "Deleting CC2564B Init Script in src folder" - @rm -rf src/cc256x* bluetooth_init* + @rm -f example/Makefile + @rm -fR example/bin diff --git a/port/max32630-fthr/board/Include/led.h b/port/max32630-fthr/board/Include/led.h new file mode 100644 index 0000000000..66cac8d07d --- /dev/null +++ b/port/max32630-fthr/board/Include/led.h @@ -0,0 +1,121 @@ + +/** + * @file + * @brief LED driver API. + */ +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2017-02-28 17:26:15 -0600 (Tue, 28 Feb 2017) $ + * $Revision: 26771 $ + * + *************************************************************************** */ + +#ifndef _LED_H_ +#define _LED_H_ + +#include "mxc_assert.h" +#include "board.h" +#include "gpio.h" + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @ingroup bsp + * @defgroup led_bsp LED Board Support API. + * @{ + */ +/* **** Definitions **** */ +#ifndef LED_OFF +#define LED_OFF 1 /**< Define to turn off the LED. */ +#endif + +#ifndef LED_ON +#define LED_ON 0 /**< Define to turn on the LED. */ +#endif + +/* **** Global Variables **** */ +extern const gpio_cfg_t led_pin[]; +extern const unsigned int num_leds; + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize all LED pins. + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int LED_Init(void); + +/** + * @brief Turn the specified LED on. + * @param idx LED index + */ +__STATIC_INLINE void LED_On(unsigned int idx) +{ + MXC_ASSERT(idx < num_leds); +#if (LED_ON == 0) + GPIO_OutClr(&led_pin[idx]); +#else + GPIO_OutSet(&led_pin[idx]); +#endif +} + +/** + * @brief Turn the specified LED off. + * @param idx LED index + */ +__STATIC_INLINE void LED_Off(unsigned int idx) +{ + MXC_ASSERT(idx < num_leds); +#if (LED_ON == 0) + GPIO_OutSet(&led_pin[idx]); +#else + GPIO_OutClr(&led_pin[idx]); +#endif +} + +/** + * @brief Toggle the state of the specified LED. + * @param idx LED index + */ +__STATIC_INLINE void LED_Toggle(unsigned int idx) +{ + MXC_ASSERT(idx < num_leds); + GPIO_OutToggle(&led_pin[idx]); +} + +#ifdef __cplusplus +} +#endif +/**@}*/ +#endif /* _LED_H_ */ diff --git a/port/max32630-fthr/board/Include/max14690.h b/port/max32630-fthr/board/Include/max14690.h new file mode 100644 index 0000000000..9fa779436b --- /dev/null +++ b/port/max32630-fthr/board/Include/max14690.h @@ -0,0 +1,230 @@ +/** + * @file + * @brief MAX14690 PMIC driver API. + */ +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-10-07 15:24:25 -0500 (Fri, 07 Oct 2016) $ + * $Revision: 24635 $ + * + *************************************************************************** */ + +#ifndef _MAX14690_H_ +#define _MAX14690_H_ + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @ingroup bsp + * @defgroup max14690_bsp MAX14690 Board Support API. + * @{ + */ +/* **** Definitions **** */ + +/** + * Enumeration type that defines the location of the register addresses for the MAX14690. + */ +typedef enum { + MAX14690_REG_CHIP_ID, /**< CHIP_ID Register */ + MAX14690_REG_CHIP_REV, /**< CHIP_REV Register */ + MAX14690_REG_STATUS_A, /**< STATUS_A Register */ + MAX14690_REG_STATUS_B, /**< STATUS_B Register */ + MAX14690_REG_STATUS_C, /**< STATUS_C Register */ + MAX14690_REG_INT_A, /**< INT_A Register */ + MAX14690_REG_INT_B, /**< INT_B Register */ + MAX14690_REG_INT_MASK_A, /**< INT_MASK_A Register */ + MAX14690_REG_INT_MASK_B, /**< INT_MASK_B Register */ + MAX14690_REG_ILIM_CNTL, /**< ILIM_CNTL Register */ + MAX14690_REG_CHG_CNTL_A, /**< CHG_CNTL_A Register */ + MAX14690_REG_CHG_CNTL_B, /**< CHG_CNTL_B Register */ + MAX14690_REG_CHG_TMR, /**< CHG_TMR Register */ + MAX14690_REG_BUCK1_CFG, /**< BUCK1_CFG Register */ + MAX14690_REG_BUCK1_VSET, /**< BUCK1_VSET Register */ + MAX14690_REG_BUCK2_CFG, /**< BUCK2_CFG Register */ + MAX14690_REG_BUCK2_VSET, /**< BUCK2_VSET Register */ + MAX14690_REG_RSVD_11, /**< RSVD_11 Register */ + MAX14690_REG_LDO1_CFG, /**< LDO1_CFG Register */ + MAX14690_REG_LDO1_VSET, /**< LDO1_VSET Register */ + MAX14690_REG_LDO2_CFG, /**< LDO2_CFG Register */ + MAX14690_REG_LDO2_VSET, /**< LDO2_VSET Register */ + MAX14690_REG_LDO3_CFG, /**< LDO3_CFG Register */ + MAX14690_REG_LDO3_VSET, /**< LDO3_VSET Register */ + MAX14690_REG_THRM_CFG, /**< THRM_CFG Register */ + MAX14690_REG_MON_CFG, /**< MON_CFG Register */ + MAX14690_REG_BOOT_CFG, /**< BOOT_CFG Register */ + MAX14690_REG_PIN_STAT, /**< PIN_STAT Register */ + MAX14690_REG_BUCK_EXTRA, /**< BUCK_EXTRA Register */ + MAX14690_REG_PWR_CFG, /**< PWR_CFG Register */ + MAX14690_REG_RSVD_1E, /**< RSVD_1E Register */ + MAX14690_REG_PWR_OFF, /**< PWR_OFF Register */ +} max14690_reg_map_t; + +/** + * Enumeration type for setting the LDO mode on the MAX14690. + */ +typedef enum { + MAX14690_LDO_DISABLED, /**< LDO mode, disabled, no active discharge. */ + MAX14690_SW_DISABLED, /**< Switch mode, disabled, no active discharge. */ + MAX14690_LDO_ENABLED, /**< LDO mode, enabled, no active discharge. */ + MAX14690_SW_ENABLED, /**< Switch mode, enabled, no active discharge. */ + MAX14690_LDO_MPC0, /**< LDO mode, MPC0 enabled, no active discharge. */ + MAX14690_SW_MPC0, /**< Switch mode, MPC0 enabled, no active discharge. */ + MAX14690_LDO_MPC1, /**< LDO mode, MPC1 enabled, no active discharge. */ + MAX14690_SW_MPC1, /**< Switch mode, MPC1 enabled, no active discharge. */ + MAX14690_LDO_DISABLED_ACT_DIS, /**< LDO mode, disabled, active discharge . */ + MAX14690_SW_DISABLED_ACT_DIS, /**< Switch mode, disabled, active discharge. */ + MAX14690_LDO_ENABLED_ACT_DIS, /**< LDO mode, enabled, active discharge. */ + MAX14690_SW_ENABLED_ACT_DIS, /**< Switch mode, enabled, active discharge. */ + MAX14690_LDO_MPC0_ACT_DIS, /**< LDO mode, MPC0 enabled, active discharge. */ + MAX14690_SW_MPC0_ACT_DIS, /**< Switch mode, MPC0 enabled, active discharge. */ + MAX14690_LDO_MPC1_ACT_DIS, /**< LDO mode, MPC1 enabled, active discharge. */ + MAX14690_SW_MPC1_ACT_DIS, /**< Switch mode, MPC1 enabled, active discharge. */ +} max14690_ldo_mode_t; + +/** + * Enumeration type to select the multiplexer channel behavior. + */ + +typedef enum { + MAX14690_MUX_SEL_PULLDOWN, /**< Mux disabled with pulldown. */ + MAX14690_MUX_SEL_BAT, /**< Mux select BAT. */ + MAX14690_MUX_SEL_SYS, /**< Mux select SYS. */ + MAX14690_MUX_SEL_BUCK1, /**< Mux select BUCK1. */ + MAX14690_MUX_SEL_BUCK2, /**< Mux select BUCK2. */ + MAX14690_MUX_SEL_LDO1, /**< Mux select LDO1. */ + MAX14690_MUX_SEL_LDO2, /**< Mux select LDO2. */ + MAX14690_MUX_SEL_LDO3, /**< Mux select LDO3. */ + MAX14690_MUX_SEL_HIZ, /**< Mux disabled, high impedance. */ +} max14690_mux_ch_t; + +/** + * Enumeration type to set the multiplexer voltage divider. + */ +typedef enum { + MAX14690_MUX_DIV_4, /**< Mux divides voltage by 4. */ + MAX14690_MUX_DIV_3, /**< Mux divides voltage by 3. */ + MAX14690_MUX_DIV_2, /**< Mux divides voltage by 2. */ + MAX14690_MUX_DIV_1, /**< Mux divides voltage by 1. */ +} max14690_mux_div_t; + +/** + * Structure type to configure the LDOs on the MAX14690. + */ +typedef struct { + max14690_ldo_mode_t ldo2mode; /**< LDO2 configuration mode. */ + uint32_t ldo2mv; /**< LDO2 voltage in mV. */ + max14690_ldo_mode_t ldo3mode; /**< LDO3 configuration mode. */ + uint32_t ldo3mv; /**< LDO3 voltage in mV. */ +} max14690_cfg_t; + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize the MAX14690. + * @param max14690cfg Pointer to a structure containing LDO configuration + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_Init(const max14690_cfg_t *max14690cfg); + +/** + * @brief Initialize the MAX14690 interrupt. + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_InterruptInit(void); + +/** + * @brief Set LDO2 mode. + * @param mode sets the operating mode for LDO2. + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_LDO2SetMode(max14690_ldo_mode_t mode); + +/** + * @brief Set LDO2 voltage. + * @param millivolts sets the operating voltage for LDO2 (in mV). + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_LDO2SetV(uint32_t millivolts); + +/** + * @brief Set LDO3 mode. + * @param mode sets the operating mode for LDO3. + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_LDO3SetMode(max14690_ldo_mode_t mode); + +/** + * @brief Set LDO3 voltage. + * @param millivolts sets the operating voltage for LDO3 (in mV). + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_LDO3SetV(uint32_t millivolts); + +/** + * @brief Set Multiplexer. + * @param ch sets the channel for the muliplexer. + * @param div sets the divider value for the multiplexer. + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_MuxSet(max14690_mux_ch_t ch, max14690_mux_div_t div); + +/** + * @brief Enables LDO2. + * @deprecated Use MAX14690_LDO2SetMode(max14690_ldo_mode_t mode) + * @param enable 1 to enable, 0 to disable LDO2. + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_EnableLDO2(uint8_t enable); + +/* + * @brief Enables LDO3. + * @deprecated Use MAX14690_LDO3SetMode(max14690_ldo_mode_t mode) + * @param enable 1 to enable, 0 to disable LDO3. + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int MAX14690_EnableLDO3(uint8_t enable); +/**@}*/ +#ifdef __cplusplus +} +#endif + +#endif /* _MAX14690_H_ */ diff --git a/port/max32630-fthr/board/max14690n.h b/port/max32630-fthr/board/Include/max14690n.h similarity index 100% rename from port/max32630-fthr/board/max14690n.h rename to port/max32630-fthr/board/Include/max14690n.h diff --git a/port/max32630-fthr/board/Include/mx25.h b/port/max32630-fthr/board/Include/mx25.h new file mode 100644 index 0000000000..4e891991ae --- /dev/null +++ b/port/max32630-fthr/board/Include/mx25.h @@ -0,0 +1,186 @@ +/** + * @file + * @brief BSP driver to communicate via SPI/QPI with an MX25 Serial Flash Memory. + */ + /* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-10-27 15:56:53 -0500 (Thu, 27 Oct 2016) $ + * $Revision: 24842 $ + * + **************************************************************************** */ + +/* Define to prevent redundant inclusion */ +#ifndef _MX25_H_ +#define _MX25_H_ + +/* **** Includes **** */ +#include "mxc_config.h" +#include "mxc_sys.h" +#include "spim.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup bsp + * @defgroup mx25_driver MX25 SPI Multi-I/O Flash Memory Driver + * @{ + */ +/* **** Definitions **** */ +#define MX25_READ_DUMMY 8 /**< Dummy byte sent on a standard read command per the MX25 datasheet. */ +#define MX25_QREAD_DUMMY 6 /**< Dummy data sent on a fast-read (Quad) read command per the MX25 datasheet. */ + +#define MX25_WIP_MASK 0x01 /**< Status Register */ +#define MX25_WEL_MASK 0x02 /**< Write Enable Latch mask */ +#define MX25_QE_MASK 0x40 /**< Quad-SPI enable mask */ + +/** + * @ingroup mx25_driver + * @defgroup MX25_Commands MX25 SPI Command Definitions + * @{ + */ +#define MX25_CMD_RST_EN 0x66 /**< Reset Enable */ +#define MX25_CMD_RST_MEM 0x99 /**< Reset Memory */ +#define MX25_CMD_ID 0x9F /**< ID */ +#define MX25_CMD_WRITE_EN 0x06 /**< Write Enable */ +#define MX25_CMD_WRITE_DIS 0x04 /**< Write Disable */ + +#define MX25_CMD_READ 0x0B /**< Read */ +#define MX25_CMD_QREAD 0xEB /**< Quad SPI Read */ +#define MX25_CMD_HPM 0xA3 /**< Hardware Protection Mode */ + +#define MX25_CMD_READ_SR 0x05 /**< Read Status Register */ +#define MX25_CMD_WRITE_SR 0x01 /**< Write Status Register */ + +#define MX25_CMD_PPROG 0x02 /**< Page Program */ +#define MX25_CMD_QUAD_PROG 0X38 /**< Quad (4 x I/O) Page Program */ + +#define MX25_CMD_4K_ERASE 0x20 /**< Page Erase */ +#define MX25_CMD_32K_ERASE 0x52 /**< Sector Type 2 (32KB) Erase */ +#define MX25_CMD_64K_ERASE 0xD8 /**< Sector Type 3 (64KB) Erase */ +#define MX25_CMD_BULK_ERASE 0xC7 /**< Bulk Erase */ +/**@} end of group mx25_commands */ +/** + * Enumeration type to select the size for an Erase command. + */ +typedef enum { + MX25_ERASE_4K, /**< 4KB Sector Erase */ + MX25_ERASE_32K, /**< 32KB Block Erase */ + MX25_ERASE_64K, /**< 64KB Block Erase */ +} +mx25_erase_t; + +/* *** Globals **** */ + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize SPI configuration and reset n25q + * @param _spim Pointer to the SPI Master peripheral registers for the SPI Master port to use. + * @param ssel Which ssel pin to use. + */ +void MX25_init(mxc_spim_regs_t *_spim, uint8_t ssel); + +/** + * @brief Reset the MX25 flash memory. + */ +void MX25_reset(void); + +/** + * @brief Read manufacturer ID. + * @return ID of the device. + */ +uint32_t MX25_ID(void); + +/** + * @brief Enable/Disable the Quad Enable(QE) bit in the status register. + * @param enable @arg @b 1 enables Quad Mode. @arg @b 0 disables Quad Mode. + * @retval 0 Success + * @retval Non-zero Error condition + */ +int MX25_quad(int enable); + +/** + * @brief Read data out by using 4-wire SPI mode. + * @param address Start address to read from + * @param rx_buf Pointer to the buffer of receiving data + * @param rx_len Size of the data to read + * @param width spim_width_t for how many data lines to use + */ +void MX25_read(uint32_t address, uint8_t *rx_buf, uint32_t rx_len, + spim_width_t width); + +/** + * @brief Program the memory to @p tx_buf and length @p tx_len, applies to both SPI and QPI modes. + * @details + * - SPI mode: All operations are in 4-wire SPI mode. + * - QPI mode: All operations are in quad SPI mode. + * @param address Start address to program. + * @param tx_buf Pointer to the buffer of data to write. + * @param tx_len Size of the data to write. + * @param width #spim_width_t for how many data lines to use. + */ +void MX25_program_page(uint32_t address, const uint8_t *tx_buf, uint32_t tx_len, + spim_width_t width); + +/** + * @brief Bulk erase the MX25 flash memory. + * @warning Bulk erase typically takes between 100 to 150 seconds. + */ +void MX25_bulk_erase(void); + +/** + * @brief Erase memory segments + * @param address Start address to begin erasing. + * @param size Size to erase, see #mx25_erase_t. + */ +void MX25_erase(uint32_t address, mx25_erase_t size); + +/** + * @brief Read status register. + * @param buf Pointer to store the value of the status register. + */ +void MX25_read_SR(uint8_t* buf); + +/** + * @brief Write status register + * @param value Value to write to the status register. + */ +void MX25_write_SR(uint8_t value); + +/**@} end of group mx25_driver */ +#ifdef __cplusplus +} +#endif + +#endif /* _MX25_H_ */ diff --git a/port/max32630-fthr/board/Include/nhd12832.h b/port/max32630-fthr/board/Include/nhd12832.h new file mode 100644 index 0000000000..5217c3f827 --- /dev/null +++ b/port/max32630-fthr/board/Include/nhd12832.h @@ -0,0 +1,351 @@ +/** + * @file + * @brief Header file for NHD12832 NHD12832 driver + */ +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2017-02-16 15:06:27 -0600 (Thu, 16 Feb 2017) $ + * $Revision: 26490 $ + * + *************************************************************************** */ + +#ifndef _NHD12832_H +#define _NHD12832_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup bsp + * @defgroup nhd12832_bsp NHD12832 Display Driver BSP + * @{ + */ +/* **** Definitions **** */ +/** + * Width of NHD12832 display in pixels, per page. + */ +#define NHD12832_WIDTH 128 +/** + * Height of NHD12832 display in pixels, per page. + */ + #define NHD12832_HEIGHT 32 + +/** + * Structure type for to map a bitmap to the NHD12832 display. + */ +typedef struct { + uint8_t width; /**< Bit map width, must be less than or equal to NHDD12832_WIDTH. */ + uint8_t height; /**< Bit map height, must be less than or equal to NHDD12832_HEIGHT. */ + uint16_t delay; /**< Unused */ + uint32_t bmp[NHD12832_WIDTH * (NHD12832_HEIGHT + 31)/32 ]; /**< storage array for bitmap. */ +} nhd12832_bitmap_t; + +/* **** Globals **** */ + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize the NHD12832 display. + * + * @retval #E_NO_ERROR NHD12832 intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int NHD12832_Init(void); + +/** + * @brief Loads the @p image to the NHD12832 memory. + * + * @param image Pointer to the bitmap image to display. + * + * @retval #E_NO_ERROR Image loaded successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int NHD12832_LoadImage(nhd12832_bitmap_t *image); + +/** + * @brief Displays the image loaded by NHD12832_LoadImage(nhd12832_bitmap_t *image). + */ +void NHD12832_PrintScreen(void); + +/** + * @brief Enables or Disables the Display. + * + * @param[in] en @arg 1 to Enable the Display. @arg 0 to Disable the Display. + */ +void NHD12832_TurnOnDisplay(uint8_t en); + +/** + * @brief Set the clock for the NHD12832 display. + * + * @param[in] clk_div The display clock divider to set. + * @param[in] freq The display oscillator frequency. + */ +void NHD12832_SetDisplayClock(uint8_t clk_div, uint8_t freq); + +/** + * @brief Set the multiplex ration (duty cycle) of the display. + * + * @param[in] ratio The ratio to set, the default is 1/64 duty, @p ratio = 0x3F. + */ +void NHD12832_SetMultiplexRatio(uint8_t ratio); + +/** + * @brief Set the display offset. + * + * @param[in] offset The offset desired. + */ +void NHD12832_SetDisplayOffset(uint8_t offset); + +/** + * @brief Set the display start line number. + * + * @param[in] pos The starting line number. + */ +void NHD12832_SetStartLine(uint8_t pos); + +/** + * @brief Turn on the internal DC regulator for the display. + * + * @param[in] en @arg 1 to enable. @arg 0 to disable. + */ +void NHD12832_TurnOnInternalDC(uint8_t en); + +/** + * @brief Sets the addressing mode of the display. + * + * @param[in] mode The mode @arg 0x00: Horizontal addressing mode. @arg 0x01: Vertical addressing mode. @arg 0x02: Page addressing mode (default). + */ +void NHD12832_SetAddressingMode(uint8_t mode); + +/** + * @brief Sets the segment mapping of the display. + * + * @param[in] d @arg 0: Column address 0 mapped to SEG0. @arg 1: Column address 0 mapped to SEG131. + */ +void NHD12832_SetSegRemap(uint8_t d); + +/** + * @brief Set the remapping of the COM. + * + * @param[in] d @arg 0: Scan from COM0 to COM63. @arg 8: scan from COM63 to COM0. + */ +void NHD12832_SetCommonRemap(uint8_t d); + +/** + * @brief Left Right remapping. + * @note Currently only sets the remapping to it's default state (0x12) + * + * @param[in] en enable or disable. + */ +void NHD12832_TurnOnLeftRightRemap(uint8_t en); + +/** + * @brief Set the pulse width of the banks. + * + * @param[in] a Width of pulse for bank a. + * @param[in] b Width of pulse for bank b. + * @param[in] c Width of pulse for bank c. + * @param[in] d Width of pulse for bank d. + */ +void NHD12832_SetBanksPulseWidth(uint8_t a, uint8_t b, uint8_t c, uint8_t d); + +/** + * @brief Set the contrast of the display. + * + * @param[in] val The desired contrast setting. + */ +void NHD12832_SetContrast(uint8_t val); + +/** + * @brief Sets the Area Brightness of the Display. + * + * @param[in] val The desired area brightness setting. + */ +void NHD12832_SetAreaBrightness(uint8_t val); + +/** + * @brief Sets the precharge period. + * @details The default precharge period is 2 display clocks for phase 1 and + * 2 display clocks for phase 2. + * + * @param[in] phase1 Phase 1 period in 1 to 15 display clock cycles. + * @param[in] phase2 Phase 2 period in 1 to 15 display clock cycles. + */ +void NHD12832_SetPrechargePeriod(uint8_t phase1, uint8_t phase2); + +/** + * @brief Enable or disable Area Color Mode. + * + * @param[in] en @arg 1 to enable area color mode. @arg 0 to disable area color mode. + */ +void NHD12832_TurnOnAreaColorMode(uint8_t en); + +/** + * @brief Sets the desired voltage for the Vcomh. + * @details The default setting for the display is val = 0x34 resulting in + * \f$ V_{COMH} = 0.77 * V_{CC} \f$. + * + * @note See NHD12832 data sheet for details on setting the Vcomh. + * + * @param[in] val The desired setting. + */ +void NHD12832_SetVcomh(uint8_t val); + +/** + * @brief Turns on or off the entire display. + * + * @param[in] en @arg 1 to turn on entire display. @arg 0 to set to normal display. + */ +void NHD12832_TurnOnEntireDisplay(uint8_t en); + +/** + * @brief Turns on or off the inverse display. + * + * @param[in] en @arg 1 to turn on inverse display. @arg 0 to set to normal display. + */ +void NHD12832_TurnOnInverseDisplay(uint8_t en); + +/** + * @brief Sets the display starting column. + * + * @param[in] pos The column desired. + */ +void NHD12832_SetStartColumn(uint8_t pos); + +/** + * @brief Sets the start page in page addressing mode. + * + * @param[in] addr The page number. + */ +void NHD12832_SetStartPage(uint8_t addr); + +/** + * @brief Sets the column address start and end. + * @details The display defaults to a @p start_addr of 0x00 and a @p end_addr of 0x83. + * @param[in] start_addr The start address + * @param[in] end_addr The end address + */ +void NHD12832_SetColumnAddr(uint8_t start_addr, uint8_t end_addr); + +/** + * @brief Sets the page address in page address mode. + * @details The display defaults to page @p start_addr of 0 and a page @p end_addr of 7. + * + * @param[in] start_addr The page start address. + * @param[in] end_addr The page end address. + */ +void NHD12832_SetPageAddr(uint8_t start_addr, uint8_t end_addr); + +/** + * @brief Sets the dim mode for the display. + * @details The displays defaults to a @p contrast of 0x80 and a @p brightness of 0x80. + * + * @param[in] contrast The contrast control desired. + * @param[in] brightness The brightness for the area color banks. + */ +void NHD12832_SetDimMode(uint8_t contrast, uint8_t brightness); + +/** + * @brief Enables or disables Read Modify Write mode for the display. + * + * @param[in] en @arg 1 to enable Read-Modify-Write mode. @arg 0 to disable Read-Modify-Write mode. + */ +void NHD12832_SetReadModifyWriteMode(uint8_t en); + +/** + * @brief Sends a NOP command to the display. + */ +void NHD12832_SetNOP(void); + +/** + * @brief Fill the display RAM with the value @p data. + * + * @param[in] data The data to write to the display RAM. + */ +void NHD12832_FillRAM(uint8_t data); + +/** + * @brief Fill a block of display RAM with the @p data value. + * + * @param[in] data The data to write to the display RAM. + * @param[in] start_page The start page. + * @param[in] end_page The end page. + * @param[in] start_column The start column. + * @param[in] total_column The total number of columns to write. + */ +void NHD12832_FillBlock(uint8_t data, uint8_t start_page, uint8_t end_page, uint8_t start_column, uint8_t total_column); + +/** + * @brief Show a checker board pattern on the display. + */ +void NHD12832_ShowChecerkBoard(void); + +/** + * @brief Shows the pattern requested on the display. + * + * @param data A pointer to the pattern to show. + * @param[in] start_page The start page + * @param[in] end_page The end page + * @param[in] start_column The start column + * @param[in] total_column The total number of columns + */ +void NHD12832_ShowPattern(uint8_t *data, uint8_t start_page, uint8_t end_page, uint8_t start_column, uint8_t total_column); + +/** + * @brief Show the 5 x 7 font on the display. + * + * @param[in] ascii The ascii font character to display. + * @param[in] start_page The start page + * @param[in] start_column The start column + */ +void NHD12832_ShowFont5x7(uint8_t ascii, uint8_t start_page, uint8_t start_column); + +/** + * @brief Show the string @p str on the display. + * + * @param str The string to display. + * @param[in] start_page The start page. + * @param[in] start_column The start column. + */ +void NHD12832_ShowString(uint8_t *str, uint8_t start_page, uint8_t start_column); + +/** + * @brief Clear the display. + * + * @param[in] start_page The start page + * @param[in] start_column The start column + */ +void NHD12832_Clear(uint8_t start_page, uint8_t start_column); + +/**@}*/ +#endif diff --git a/port/max32630-fthr/board/Include/pb.h b/port/max32630-fthr/board/Include/pb.h new file mode 100644 index 0000000000..1442427e9f --- /dev/null +++ b/port/max32630-fthr/board/Include/pb.h @@ -0,0 +1,144 @@ +/** + * @file + * @brief Pushbutton driver header file. + */ +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2017-02-28 17:26:15 -0600 (Tue, 28 Feb 2017) $ + * $Revision: 26771 $ + * + *************************************************************************** */ + +#ifndef _PB_H_ +#define _PB_H_ + +#include "gpio.h" + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @ingroup bsp + * @defgroup pushbutton_evkit Push button driver board support + * @{ + */ +/* **** Global Variables **** */ +extern const gpio_cfg_t pb_pin[]; +extern const unsigned int num_pbs; + +/* **** Function Prototypes **** */ + +/** + * @brief Initialize all push buttons. + * @retval #E_NO_ERROR Push buttons intialized successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + * + */ +int PB_Init(void); + +/** + * Type alias @c pb_callback for the push button callback. + * @details The function is of type: + * @code + * void pb_callback(void * pb) + * @endcode + * To recieve notification of a push button event, define a callback + * function and pass it as a pointer to the PB_RegisterCallback(unsigned int pb, pb_callback callback) function. + * @param pb Pointer to the push button index that triggered the + * callback. + */ +typedef void (*pb_callback)(void *pb); + +/** + * @brief Register or Unregister a callback handler for events on the @p pb push button. + * @details + * - Calling this function with a pointer to a function @p callback, configures the pushbutton @p pb and enables the + * interrupt to handle the push button events. + * - Calling this function with a NULL pointer will disable the interrupt and unregister the + * callback function. + * @p pb must be a value between 0 and #num_pbs. + * + * @param pb push button index to receive event callbacks. + * @param callback Callback function pointer of type @c pb_callback + * @retval #E_NO_ERROR if configured and callback registered successfully. + * @retval "Error Code" @ref MXC_Error_Codes "Error Code" if unsuccessful. + */ +int PB_RegisterCallback(unsigned int pb, pb_callback callback); + +/** + * @brief Enable a callback interrupt. + * @note PB_RegisterCallback must be called prior to enabling the callback interrupt. + * @param pb push button index value between 0 and #num_pbs. + */ +__STATIC_INLINE void PB_IntEnable(unsigned int pb) +{ + MXC_ASSERT(pb < num_pbs); + GPIO_IntEnable(&pb_pin[pb]); +} + +/** + * @brief Disable a callback interrupt. + * @param pb push button index + */ +__STATIC_INLINE void PB_IntDisable(unsigned int pb) +{ + MXC_ASSERT(pb < num_pbs); + GPIO_IntDisable(&pb_pin[pb]); +} + +/** + * @brief Clear a callback interrupt. + * @param pb push button index value between 0 and #num_pbs. + */ +__STATIC_INLINE void PB_IntClear(unsigned int pb) +{ + MXC_ASSERT(pb < num_pbs); + GPIO_IntClr(&pb_pin[pb]); +} + +/** + * @brief Get the current state of the push button. + * @param pb push button index value between 0 and #num_pbs. + * @retval TRUE The button is pressed. + * @retval FALSE The button is not pressed. + */ +__STATIC_INLINE int PB_Get(unsigned int pb) +{ + MXC_ASSERT(pb < num_pbs); + return !GPIO_InGet(&pb_pin[pb]); +} +/**@}*/ +#ifdef __cplusplus +} +#endif + +#endif /* _PB_H_ */ diff --git a/port/max32630-fthr/board/Source/led.c b/port/max32630-fthr/board/Source/led.c new file mode 100644 index 0000000000..e3af48af7e --- /dev/null +++ b/port/max32630-fthr/board/Source/led.c @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2017-02-28 17:26:15 -0600 (Tue, 28 Feb 2017) $ + * $Revision: 26771 $ + * + ******************************************************************************/ + +#include "mxc_config.h" +#include "led.h" + +/******************************************************************************/ +int LED_Init(void) +{ + int retval = E_NO_ERROR; + unsigned int i; + + /* setup GPIO for the LED */ + for (i = 0; i < num_leds; i++) { + LED_Off(i); // Set the output value + if (GPIO_Config(&led_pin[i]) != E_NO_ERROR) { + retval = E_UNKNOWN; + } + } + + return retval; +} diff --git a/port/max32630-fthr/board/Source/max14690.c b/port/max32630-fthr/board/Source/max14690.c new file mode 100644 index 0000000000..8942e5803c --- /dev/null +++ b/port/max32630-fthr/board/Source/max14690.c @@ -0,0 +1,275 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-08-15 16:31:22 -0500 (Mon, 15 Aug 2016) $ + * $Revision: 24076 $ + * + ******************************************************************************/ + +/***** Includes *****/ +#include +#include "mxc_config.h" +#include "mxc_sys.h" +#include "max14690.h" +#include "board.h" +#include "i2cm.h" +#include "lp.h" + +/***** Definitions *****/ +#define MAX14690_I2C_ADDR (0x50 >> 1) + +#define MAX14690_USB_OK 0x08 + +#define MAX14690_LDO_MIN_MV 800 +#define MAX14690_LDO_MAX_MV 3600 +#define MAX14690_LDO_STEP_MV 100 + +/***** Function Prototypes *****/ +static void VBUS_Interrupt(void *unused); + + +/******************************************************************************/ +int MAX14690_Init(const max14690_cfg_t *max14690cfg) +{ + uint8_t addr; + uint8_t data[2]; + + /* Setup the I2CM Peripheral to talk to the MAX14690 */ + I2CM_Init(MAX14690_I2CM, &max14690_sys_cfg, I2CM_SPEED_100KHZ); + + /* Attempt to read the ID from the device */ + addr = MAX14690_REG_CHIP_ID; + if (I2CM_Read(MAX14690_I2CM, MAX14690_I2C_ADDR, &addr, 1, data, 2) != 2) { + return E_COMM_ERR; + } + + /* Configure the initial state of LDO2 */ + if (MAX14690_LDO2SetV(max14690cfg->ldo2mv) != E_NO_ERROR) { + return E_COMM_ERR; + } + if (MAX14690_LDO2SetMode(max14690cfg->ldo2mode) != E_NO_ERROR) { + return E_COMM_ERR; + } + /* Configure the initial state of LDO3 */ + if (MAX14690_LDO3SetV(max14690cfg->ldo3mv) != E_NO_ERROR) { + return E_COMM_ERR; + } + if (MAX14690_LDO2SetMode(max14690cfg->ldo2mode) != E_NO_ERROR) { + return E_COMM_ERR; + } + return E_NO_ERROR; +} + +/******************************************************************************/ +int MAX14690_InterruptInit(void) +{ + uint8_t data[2]; + + /* Configure the initial state of LDO2 */ + VBUS_Interrupt(NULL); + + /* Configure GPIO for interrupt pin from PMIC */ + if (GPIO_Config(&max14690_int) != E_NO_ERROR) { + return E_UNKNOWN; + } + + /* Configure and enable interrupt */ + GPIO_RegisterCallback(&max14690_int, VBUS_Interrupt, NULL); + GPIO_IntConfig(&max14690_int, GPIO_INT_FALLING_EDGE); + GPIO_IntEnable(&max14690_int); + NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(max14690_int.port)); + + /* Configure interrupt wakeup */ + if (LP_ConfigGPIOWakeUpDetect(&max14690_int, 0, LP_WEAK_PULL_UP) != E_NO_ERROR) { + return E_UNKNOWN; + } + + /* Enable the VBUS interrupt */ + data[0] = MAX14690_REG_INT_MASK_A; /* IntMaskA */ + data[1] = MAX14690_USB_OK; /* UsbOk */ + if (I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2) != 2) { + return -1; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int MAX14690_LDO2SetMode(max14690_ldo_mode_t mode) +{ + int retval; + uint8_t data[2] = {MAX14690_REG_LDO2_CFG, mode}; + + retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2); + if(retval != 2) { + return retval; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int MAX14690_LDO2SetV(uint32_t millivolts) +{ + int retval; + uint8_t data[2] = {MAX14690_REG_LDO2_VSET, 0}; + + if ((MAX14690_LDO_MIN_MV <= millivolts)&&(millivolts <= MAX14690_LDO_MAX_MV)){ + data[1] = (millivolts - MAX14690_LDO_MIN_MV) / MAX14690_LDO_STEP_MV; + } else { + return E_INVALID; + } + + retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2); + if(retval != 2) { + return retval; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int MAX14690_LDO3SetMode(max14690_ldo_mode_t mode) +{ + int retval; + uint8_t data[2] = {MAX14690_REG_LDO3_CFG, mode}; + + retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2); + if(retval != 2) { + return retval; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int MAX14690_LDO3SetV(uint32_t millivolts) +{ + int retval; + uint8_t data[2] = {MAX14690_REG_LDO3_VSET, 0}; + + if ((MAX14690_LDO_MIN_MV <= millivolts)&&(millivolts <= MAX14690_LDO_MAX_MV)){ + data[1] = (millivolts - MAX14690_LDO_MIN_MV) / MAX14690_LDO_STEP_MV; + } else { + return E_INVALID; + } + + retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2); + if(retval != 2) { + return retval; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int MAX14690_MuxSet(max14690_mux_ch_t ch, max14690_mux_div_t div) +{ + int retval; + uint8_t data[2] = {MAX14690_REG_MON_CFG, 0}; + + data[1] = (div << 4) + ch; + + retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2); + if(retval != 2) { + return retval; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +static void VBUS_Interrupt(void *unused) +{ + uint8_t addr = MAX14690_REG_STATUS_A; /* StatusA */ + uint8_t data[5]; + + if (I2CM_Read(MAX14690_I2CM, MAX14690_I2C_ADDR, &addr, 1, data, 5) == 5) { + if (data[1] & MAX14690_USB_OK) { /* UsbOk */ + /* VBUS is present. Enable LDO2 */ + MAX14690_LDO2SetMode(MAX14690_LDO_ENABLED); + } else { + /* VBUS is not present. Disable LDO2 */ + MAX14690_LDO2SetMode(MAX14690_LDO_DISABLED); + } + } +} + +/******************************************************************************/ +int MAX14690_EnableLDO2(uint8_t enable) +{ + int retval; + uint8_t data[2] = {MAX14690_REG_LDO2_CFG, 0}; + + retval = I2CM_Read(MAX14690_I2CM, MAX14690_I2C_ADDR, &data[0], 1, &data[1], 1); + if(retval != 1) { + return retval; + } + + if(enable) { + data[1] |= MAX14690_LDO_ENABLED; + } else { + data[1] &= ~MAX14690_LDO_ENABLED; + } + + retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2); + if(retval != 2) { + return retval; + } + + return E_NO_ERROR; +} + +/******************************************************************************/ +int MAX14690_EnableLDO3(uint8_t enable) +{ + int retval; + uint8_t data[2] = {MAX14690_REG_LDO3_CFG, 0}; + + retval = I2CM_Read(MAX14690_I2CM, MAX14690_I2C_ADDR, &data[0], 1, &data[1], 1); + if(retval != 1) { + return retval; + } + + if(enable) { + data[1] |= MAX14690_LDO_ENABLED; + } else { + data[1] &= ~MAX14690_LDO_ENABLED; + } + + retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2); + if(retval != 2) { + return retval; + } + + return E_NO_ERROR; +} + diff --git a/port/max32630-fthr/board/max14690n.c b/port/max32630-fthr/board/Source/max14690n.c similarity index 100% rename from port/max32630-fthr/board/max14690n.c rename to port/max32630-fthr/board/Source/max14690n.c diff --git a/port/max32630-fthr/board/Source/mx25.c b/port/max32630-fthr/board/Source/mx25.c new file mode 100644 index 0000000000..7b20115864 --- /dev/null +++ b/port/max32630-fthr/board/Source/mx25.c @@ -0,0 +1,428 @@ +/** + * @file + * @brief BSP Driver for the Micron MX25 Serial Multi-I/O Flash Memory. + */ +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-10-07 15:24:25 -0500 (Fri, 07 Oct 2016) $ + * $Revision: 24635 $ + * + **************************************************************************** */ + +/* **** Includes **** */ +#include +#include "mxc_config.h" +#include "mx25.h" +#include "spim.h" +#include "spim_regs.h" + + /** + * @ingroup mx25 + * @{ + */ + +/* **** Definitions **** */ + +/* **** Globals **** */ +static mxc_spim_regs_t *spim; +static spim_req_t req; + +/* **** Static Functions **** */ + +/* ************************************************************************* */ +static int flash_busy() +{ + uint8_t buf; + + MX25_read_SR(&buf); + + if(buf & MX25_WIP_MASK) { + return 1; + } else + return 0; +} + +/* ************************************************************************* */ +static int write_enable() +{ + uint8_t cmd = MX25_CMD_WRITE_EN; + uint8_t buf; + + // Send the command + req.len = 1; + req.tx_data = &cmd; + req.rx_data = NULL; + req.deass = 1; + SPIM_Trans(spim, &req); + + MX25_read_SR(&buf); + + if(buf & MX25_WEL_MASK) + return 0; + return -1; +} + +/* ************************************************************************* */ +static void inline read_reg(uint8_t cmd, uint8_t* buf) +{ + // Send the command + req.len = 1; + req.tx_data = &cmd; + req.rx_data = NULL; + req.deass = 0; + SPIM_Trans(spim, &req); + + // Read the data + req.len = 1; + req.tx_data = NULL; + req.rx_data = buf; + req.deass = 1; + SPIM_Trans(spim, &req); +} + +/* ************************************************************************* */ +static void inline write_reg(uint8_t* buf, unsigned len) +{ + if(write_enable() != 0) + return; + + // Send the command and data + req.len = len; + req.tx_data = buf; + req.rx_data = NULL; + req.deass = 1; + SPIM_Trans(spim, &req); +} + +/* **** Functions **** */ + +/* ************************************************************************* */ +void MX25_init(mxc_spim_regs_t* _spim, uint8_t ssel) +{ + // Save the SPIM that the driver will use + spim = _spim; + + req.ssel = ssel; +} + +/* ************************************************************************* */ +void MX25_reset(void) +{ + // Send the Reset command + uint8_t cmd; + req.len = 1; + req.tx_data = &cmd; + req.rx_data = NULL; + req.deass = 1; + + cmd = MX25_CMD_RST_EN; + SPIM_Trans(spim, &req); + cmd = MX25_CMD_RST_MEM; + SPIM_Trans(spim, &req); + + while(flash_busy()) {} +} + +/* ************************************************************************* */ +uint32_t MX25_ID(void) +{ + uint8_t cmd = MX25_CMD_ID; + uint8_t id[3]; + + // Send the command + req.len = 1; + req.tx_data = &cmd; + req.rx_data = NULL; + req.deass = 0; + SPIM_Trans(spim, &req); + + // Read the data + req.len = 3; + req.tx_data = NULL; + req.rx_data = id; + req.deass = 1; + SPIM_Trans(spim, &req); + + + return ((uint32_t)(id[2] | (id[1] << 8) | (id[0] << 16))); +} + +/* ************************************************************************* */ +int MX25_quad(int enable) +{ + // Enable QSPI mode + uint8_t pre_buf; + uint8_t post_buf; + + MX25_read_SR(&pre_buf); + + if(enable) { + pre_buf |= MX25_QE_MASK; + } else { + pre_buf &= ~MX25_QE_MASK; + } + + if(write_enable() != 0) + return -1; + + MX25_write_SR(pre_buf); + + while(flash_busy()) {} + + MX25_read_SR(&post_buf); + + if(enable) { + if(!(post_buf & MX25_QE_MASK)) { + return -1; + } + } else { + if(post_buf & MX25_QE_MASK) { + return -1; + } + } + + return 0; +} + +/* ************************************************************************* */ +void MX25_read(uint32_t address, uint8_t *rx_buf, uint32_t rx_len, + spim_width_t width) +{ + uint8_t cmd[4]; + + if(flash_busy()) + return; + + cmd[1] = (address >> 16) & 0xFF; + cmd[2] = (address >> 8) & 0xFF; + cmd[3] = address & 0xFF; + + // Send the command + req.len = 1; + req.tx_data = cmd; + req.rx_data = NULL; + req.deass = 0; + + // Send the command and dummy bits + if(width == SPIM_WIDTH_1) { + cmd[0] = MX25_CMD_READ; + SPIM_Trans(spim, &req); + + // Send the address + req.len = 3; + req.tx_data = &cmd[1]; + req.width = width; + SPIM_Trans(spim, &req); + + // Send dummy bits + SPIM_Clocks(spim, MX25_READ_DUMMY, req.ssel, 0); + + } else { + cmd[0] = MX25_CMD_QREAD; + SPIM_Trans(spim, &req); + + // Send the address + req.len = 3; + req.tx_data = &cmd[1]; + req.width = width; + SPIM_Trans(spim, &req); + + // Send dummy bits + SPIM_Clocks(spim, MX25_QREAD_DUMMY, req.ssel, 0); + + } + + // Receive the data + req.len = rx_len; + req.tx_data = NULL; + req.rx_data = rx_buf; + req.deass = 1; + + SPIM_Trans(spim, &req); + + // Restore the width + req.width = SPIM_WIDTH_1; + + while(flash_busy()) {} +} + +/* ************************************************************************* */ +void MX25_program_page(uint32_t address, const uint8_t *tx_buf, uint32_t tx_len, + spim_width_t width) +{ + + int tx_cnt = 0; + uint8_t cmd[4]; + + if(flash_busy()) + return; + + while(tx_len > 0) { + + if(write_enable()) + return; + + cmd[1] = (address >> 16) & 0xFF; + cmd[2] = (address >> 8) & 0xFF; + cmd[3] = address & 0xFF; + + // Send the command + req.len = 1; + req.tx_data = cmd; + req.rx_data = NULL; + req.deass = 0; + + // Send the command and dummy bits + if(width == SPIM_WIDTH_1) { + cmd[0] = MX25_CMD_PPROG; + SPIM_Trans(spim, &req); + + // Send the address + req.len = 3; + req.tx_data = &cmd[1]; + req.width = width; + SPIM_Trans(spim, &req); + + } else { + cmd[0] = MX25_CMD_QUAD_PROG; + SPIM_Trans(spim, &req); + + // Send the address + req.len = 3; + req.tx_data = &cmd[1]; + req.width = width; + SPIM_Trans(spim, &req); + } + + // Send the data + if(tx_len >= 256) { + req.len = 256; + } else { + req.len = tx_len; + } + req.tx_data = &tx_buf[tx_cnt*256]; + req.rx_data = NULL; + req.deass = 1; + SPIM_Trans(spim, &req); + + // Restore the width + req.width = SPIM_WIDTH_1; + + if(tx_len >= 256) { + tx_len -= 256; + } else { + tx_len = 0; + } + address += 256; + tx_cnt++; + + while(flash_busy()); + } +} + +/* ************************************************************************* */ +void MX25_bulk_erase(void) +{ + uint8_t cmd; + + if(flash_busy()) + return; + + if(write_enable()) + return; + + cmd = MX25_CMD_BULK_ERASE; + + // Send the command + req.len = 1; + req.tx_data = &cmd; + req.rx_data = NULL; + req.deass = 1; + SPIM_Trans(spim, &req); + + while(flash_busy()) {} +} + +/* ************************************************************************* */ +void MX25_erase(uint32_t address, mx25_erase_t size) +{ + uint8_t cmd[4]; + + if(flash_busy()) + return; + + if(write_enable()) + return; + + switch(size) { + case MX25_ERASE_4K: + default: + cmd[0] = MX25_CMD_4K_ERASE; + break; + case MX25_ERASE_32K: + cmd[0] = MX25_CMD_32K_ERASE; + break; + case MX25_ERASE_64K: + cmd[0] = MX25_CMD_64K_ERASE; + break; + } + + cmd[1] = (address >> 16) & 0xFF; + cmd[2] = (address >> 8) & 0xFF; + cmd[3] = address & 0xFF; + + // Send the command and the address + req.len = 4; + req.tx_data = cmd; + req.rx_data = NULL; + req.deass = 1; + SPIM_Trans(spim, &req); + + while(flash_busy()) {} +} + +/* ************************************************************************* */ +void MX25_read_SR(uint8_t* buf) +{ + uint8_t cmd = MX25_CMD_READ_SR; + + read_reg(cmd, buf); +} + +/* ************************************************************************* */ +void MX25_write_SR(uint8_t value) +{ + uint8_t cmd[2] = {MX25_CMD_WRITE_SR, value}; + + write_reg(cmd, 2); +} +/**@} end of ingroup mx25 */ diff --git a/port/max32630-fthr/board/Source/mx25_max3263x.ld b/port/max32630-fthr/board/Source/mx25_max3263x.ld new file mode 100644 index 0000000000..7d505d46c8 --- /dev/null +++ b/port/max32630-fthr/board/Source/mx25_max3263x.ld @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-03-11 11:46:02 -0600 (Fri, 11 Mar 2016) $ + * $Revision: 21838 $ + * + ******************************************************************************/ + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00200000 /* start from 0x0, fullsize flash, 2M */ + SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000 /* full-size SRAM, 512K */ + XIP (rx) : ORIGIN = 0x10000000, LENGTH = 0x08000000 /* 128 Mb SPIX */ +} + +SECTIONS +{ + .rom : + { + KEEP(*(.rom_vector)) + *(.rom_handlers*) + } > FLASH + + .text : + { + _text = .; + KEEP(*(.isr_vector)) + *(.text*) /* program code */ + *(.rodata*) /* read-only data: "const" variable */ + } > XIP + + /* it's used for C++ exception handling */ + /* we need to keep this to avoid overlapping */ + .ARM.exidx : + { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > XIP + + _etext = ALIGN(., 4); + + .data : AT(_etext) + { + _data = .; + *(.data*) /*read-write initialized data: initialized global variable*/ + _edata = ALIGN(., 4); + } > SRAM + + .bss : + { + . = ALIGN(4); + _bss = .; + *(.bss*) /*read-write zero initialized data: uninitialzed global variable*/ + *(COMMON) + _ebss = ALIGN(., 4); + } > SRAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(SRAM) + LENGTH(SRAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > SRAM + + .heap (COPY): + { + . = ALIGN(4); + *(.heap*) + __HeapLimit = ABSOLUTE(__StackLimit); + } > SRAM + + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack") +} diff --git a/port/max32630-fthr/board/Source/mx25_stub.c b/port/max32630-fthr/board/Source/mx25_stub.c new file mode 100644 index 0000000000..aa79b4c9e3 --- /dev/null +++ b/port/max32630-fthr/board/Source/mx25_stub.c @@ -0,0 +1,207 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-06-22 17:24:26 -0500 (Wed, 22 Jun 2016) $ + * $Revision: 23483 $ + * + ******************************************************************************/ + +#include "mxc_config.h" +#include "icc_regs.h" +#include "spix.h" +#include "mxc_sys.h" +#include "spim.h" +#include "mx25.h" + +#if defined ( __GNUC__ ) +#undef IAR_PRAGMAS //Make sure this is not defined for GCC +#endif + +/* The stack address is defined by the linker + * It is typed as a function here to avoid compiler warnings + */ +extern void __StackTop(void); +extern void Reset_Handler(void); +extern void DefaultIRQ_Handler(void); +extern void DebugMon_Handler(void); +extern void MemManage_Handler(void); +extern void BusFault_Handler(void); +extern void UsageFault_Handler(void); +extern void SVC_Handler(void); +extern void DebugMon_Handler(void); +extern void PendSV_Handler(void); +extern void SysTick_Handler(void); + +void Reset_Handler_ROM(void); +void NMI_Handler_ROM(void); +void HardFault_Handler_ROM(void); + +/* Create a vector table to locate at zero in the ROM for handling reset and startup */ +#if IAR_PRAGMAS +// IAR memory section declaration for the IVT location. +#pragma section=".rom_vector" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".rom_vector"))) +#endif +void (* const rom_vector[])(void) = { + __StackTop, /* Top of Stack */ + Reset_Handler_ROM, /* Reset Handler */ + NMI_Handler_ROM, /* NMI Handler */ + HardFault_Handler_ROM, /* Hard Fault Handler */ + MemManage_Handler, /* MPU Fault Handler */ + BusFault_Handler, /* Bus Fault Handler */ + UsageFault_Handler, /* Usage Fault Handler */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + SVC_Handler, /* SVCall Handler */ + DebugMon_Handler, /* Debug Monitor Handler */ + 0, /* Reserved */ + PendSV_Handler, /* PendSV Handler */ + SysTick_Handler, /* SysTick Handler */ +}; + +/* This is needed to handle the NMI at POR */ +#if IAR_PRAGMAS +// IAR memory section declaration for the IVT location. +#pragma section=".rom_handlers" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".rom_handlers"))) +#endif + +void NMI_Handler_ROM(void) +{ + __NOP(); +} + +/* This is needed to handle the fault after initial programming */ +#if IAR_PRAGMAS +// IAR memory section declaration for the IVT location. +#pragma section=".rom_handlers" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".rom_handlers"))) +#endif + +void HardFault_Handler_ROM(void) +{ + NVIC_SystemReset(); +} + +/* This is needed to handle the fault after initial programming */ +#if IAR_PRAGMAS +// IAR memory section declaration for the IVT location. +#pragma section=".rom_handlers" +#endif +#if defined ( __GNUC__ ) +__attribute__ ((section(".rom_handlers"))) +#endif + +void Reset_Handler_ROM(void) +{ + mxc_spim_fifo_regs_t *fifo; + + // Disable instruction cache + MXC_ICC->invdt_all = 1; + MXC_ICC->ctrl_stat &= ~MXC_F_ICC_CTRL_STAT_ENABLE; + MXC_ICC->invdt_all = 1; + + // Initialize SPIM1 to initialize MX25 + MXC_IOMAN->spim1_req = 0x10110; + MXC_CLKMAN->sys_clk_ctrl_12_spi1 = 0x1; + + MXC_SPIM1->gen_ctrl = (MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN | MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN | + MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN); + + // Get the TX and RX FIFO for this SPIM + fifo = MXC_SPIM_GET_SPIM_FIFO(1); + + // Initialize the SPIM to work with the MX25 + MXC_SPIM1->mstr_cfg = 0x4400; + + // Reset the MX25 + fifo->trans_16[0] = (0x1 | (0x1 << 2) | (0x1 << 4) | (0x1 << 13)); + fifo->trans_16[0] = (0xF000 | MX25_CMD_RST_EN); + + fifo->trans_16[0] = (0x1 | (0x1 << 2) | (0x1 << 4) | (0x1 << 13)); + fifo->trans_16[0] = (0xF000 | MX25_CMD_RST_MEM); + + // Write enable + fifo->trans_16[0] = (0x1 | (0x1 << 2) | (0x1 << 4) | (0x1 << 13)); + fifo->trans_16[0] = (0xF000 | MX25_CMD_WRITE_EN); + + // Enable quad mode + fifo->trans_16[0] = (0x1 | (0x1 << 2) | (0x2 << 4) | (0x1 << 13)); + fifo->trans_16[0] = ((MX25_QE_MASK << 8) | (MX25_CMD_WRITE_SR << 0)); + + // Wait for the busy flag to clear + uint8_t busy = MX25_WIP_MASK; + while((busy & MX25_WIP_MASK) || !(busy & MX25_QE_MASK)) { + + // Read SR + fifo->trans_16[0] = (0x1 | (0x1 << 2) | (0x1 << 4)); + fifo->trans_16[0] = (0xF000 | MX25_CMD_READ_SR); + + fifo->trans_16[0] = (0x2 | (0x1 << 2) | (0x1 << 4) | (0x1 << 13)); + + while(!(MXC_SPIM1->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED)) {} + busy = fifo->rslts_8[0]; + } + + // Disable the SPIM clock and I/O + MXC_IOMAN->spim1_req = 0x0; + MXC_CLKMAN->sys_clk_ctrl_12_spi1 = 0x0; + + // Enable SPIX I/O + MXC_IOMAN->spix_req = 0x11110; + + // Enable SPIX clock + MXC_CLKMAN->sys_clk_ctrl_2_spix = 1; + + // Setup SPIX + MXC_SPIX->master_cfg = 0x1104; + MXC_SPIX->fetch_ctrl = (MX25_CMD_QREAD | (0x2 << MXC_F_SPIX_FETCH_CTRL_DATA_WIDTH_POS) | + (0x2 << MXC_F_SPIX_FETCH_CTRL_ADDR_WIDTH_POS)); + + MXC_SPIX->mode_ctrl = (MX25_QREAD_DUMMY); + MXC_SPIX->sck_fb_ctrl = (MXC_F_SPIX_SCK_FB_CTRL_ENABLE_SCK_FB_MODE | + MXC_F_SPIX_SCK_FB_CTRL_INVERT_SCK_FB_CLK); + +#if (MXC_SPIX_REV == 0) + // 8 bits for command, 6 for address, MX25_QREAD_DUMMY for the dummy bits + MXC_SPIX->sck_fb_ctrl |= ((14 + MX25_QREAD_DUMMY) << MXC_F_SPIX_SCK_FB_CTRL_IGNORE_CLKS_POS); +#endif + // Jump to the Rest Handler + Reset_Handler(); +} diff --git a/port/max32630-fthr/board/Source/nhd12832.c b/port/max32630-fthr/board/Source/nhd12832.c new file mode 100644 index 0000000000..d5c63e99f7 --- /dev/null +++ b/port/max32630-fthr/board/Source/nhd12832.c @@ -0,0 +1,710 @@ +/** + * @file + * @brief Source for NHD12832 driver + */ +/* **************************************************************************** + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-10-07 15:24:25 -0500 (Fri, 07 Oct 2016) $ + * $Revision: 24635 $ + * + *************************************************************************** */ + + + +/***** Includes *****/ +#include +#include +#include "mxc_config.h" +#include "mxc_sys.h" +#include "board.h" +#include "gpio.h" +#include "spim.h" +#include "nhd12832.h" +/** + * @ingroup nhd12832_bsp + * @{ + */ + +/* **** Definitions **** */ +#define DEFAULT_BRIGHTNESS 0xBF /**< Default brightness setting. */ + +// NHD12832 Command Address +#define NHD12832_SET_ADDRESSING_MODE 0x20 /**< Set addressing mode. */ +#define NHD12832_SET_COLUMN_ADDR 0x21 /**< Set the column address. */ +#define NHD12832_SET_PAGE_ADDR 0x22 /**< Set the page address. */ +#define NHD12832_SET_DISPLAY_START_LINE 0x40 /**< Set the display start line number. */ +#define NHD12832_SET_CONTRAST 0x81 /**< Set contrast control for bank 0. */ +#define NHD12832_SET_BRIGHTNESS 0x82 /**< Set brightness for area color banks. */ +#define NHD12832_SET_BANKS_PULSE_WIDTH 0x91 /**< Define look up table of area color A-D pulse width. */ +#define NHD12832_SET_AREA_COLOR_PAGE0 0x92 /**< define area color for bank 1-16 (page 0). */ +#define NHD12832_SET_AREA_COLOR_PAGE1 0x93 /**< define area color for bank 17-32 (page 1). */ +#define NHD12832_SET_SEG_REMAP 0xA0 /**< Set segment re-map. */ +#define NHD12832_SET_ENTIRE_DISPLAY 0xA5 /**< Turn on/off entire display. */ +#define NHD12832_SET_INVERSE_DISPLAY 0xA7 /**< Turn on/off inverse display. */ +#define NHD12832_SET_MULTI_RATIO 0xA8 /**< Set multiple ratio. */ +#define NHD12832_SET_DIM_MODE_CFG 0xAB /**< Set dim mode configuration. */ +#define NHD12832_SET_DIM_MODE 0xAC /**< Set display on in dim mode. */ +#define NHD12832_SET_INTERNAL_DC 0xAD /**< Set master config internal DC. */ +#define NHD12832_SET_DISPLAY_OFF 0xAF /**< Set entire display on/off. */ +#define NHD12832_SET_START_PAGE 0xB0 /**< Set page start address for page addressing mode. */ +#define NHD12832_SET_COM_REMAP 0xC0 /**< Set COM output scan direction. */ +#define NHD12832_SET_DISPLAY_OFFSET 0xD3 /**< Set display offset. */ +#define NHD12832_SET_CLK_DIV_FREQ 0xD5 /**< Set display clock divide ratio/ oscillator frequency. */ +#define NHD12832_SET_AREA_COLOR_MODE 0xD8 /**< Turn on/off area color mode and low power display mode. */ +#define NHD12832_SET_VCOMH 0xD8 /**< Set VCOMH deselect level. */ +#define NHD12832_SET_PRE_CHARGE_PERIOD 0xD9 /**< Set pre-charge period. */ +#define NHD12832_SET_COM_CFG 0xDA /**< Set COM poins hardware configuration. */ +#define NHD12832_SET_READ_MOD_WRITE_EN 0xE0 /**< Set read-modify-write mode. */ +#define NHD12832_NOP 0xE3 /**< Command for no-operation. */ + +#define NUM_COM_PINS 32 /**< NUMBER OF COM PINS */ +#define NUM_PAGES (NUM_COM_PINS/8) /**< NUMBER OF PAGES. */ +#define MIN_PAGE 0 /**< Minimum value for a page number. */ +#define MAX_PAGE NUM_PAGES - 1 /**< Maximum value for a page number. */ + +static const uint8_t stdfont5x7[] = { + 0x0, 0x0, // size of zero indicates fixed width font, actual length is width * height + 0x05, // width + 0x07, // height + 0x20, // first char + 0x60, // char count + + // Fixed width; char width table not used !!!! + + // font data starts here; offset = 6 + 0x00, 0x00, 0x00, 0x00, 0x00,// (space) + 0x00, 0x00, 0x5F, 0x00, 0x00,// ! + 0x00, 0x07, 0x00, 0x07, 0x00,// " + 0x14, 0x7F, 0x14, 0x7F, 0x14,// # + 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $ + 0x23, 0x13, 0x08, 0x64, 0x62,// % + 0x36, 0x49, 0x55, 0x22, 0x50,// & + 0x00, 0x05, 0x03, 0x00, 0x00,// ' + 0x00, 0x1C, 0x22, 0x41, 0x00,// ( + 0x00, 0x41, 0x22, 0x1C, 0x00,// ) + 0x08, 0x2A, 0x1C, 0x2A, 0x08,// * + 0x08, 0x08, 0x3E, 0x08, 0x08,// + + 0x00, 0x50, 0x30, 0x00, 0x00,// , + 0x08, 0x08, 0x08, 0x08, 0x08,// - + 0x00, 0x60, 0x60, 0x00, 0x00,// . + 0x20, 0x10, 0x08, 0x04, 0x02,// / + 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 + 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 + 0x42, 0x61, 0x51, 0x49, 0x46,// 2 + 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 + 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 + 0x27, 0x45, 0x45, 0x45, 0x39,// 5 + 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 + 0x01, 0x71, 0x09, 0x05, 0x03,// 7 + 0x36, 0x49, 0x49, 0x49, 0x36,// 8 + 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 + 0x00, 0x36, 0x36, 0x00, 0x00,// : + 0x00, 0x56, 0x36, 0x00, 0x00,// ; + 0x00, 0x08, 0x14, 0x22, 0x41,// < + 0x14, 0x14, 0x14, 0x14, 0x14,// = + 0x41, 0x22, 0x14, 0x08, 0x00,// > + 0x02, 0x01, 0x51, 0x09, 0x06,// ? + 0x32, 0x49, 0x79, 0x41, 0x3E,// @ + 0x7E, 0x11, 0x11, 0x11, 0x7E,// A + 0x7F, 0x49, 0x49, 0x49, 0x36,// B + 0x3E, 0x41, 0x41, 0x41, 0x22,// C + 0x7F, 0x41, 0x41, 0x22, 0x1C,// D + 0x7F, 0x49, 0x49, 0x49, 0x41,// E + 0x7F, 0x09, 0x09, 0x01, 0x01,// F + 0x3E, 0x41, 0x41, 0x51, 0x32,// G + 0x7F, 0x08, 0x08, 0x08, 0x7F,// H + 0x00, 0x41, 0x7F, 0x41, 0x00,// I + 0x20, 0x40, 0x41, 0x3F, 0x01,// J + 0x7F, 0x08, 0x14, 0x22, 0x41,// K + 0x7F, 0x40, 0x40, 0x40, 0x40,// L + 0x7F, 0x02, 0x04, 0x02, 0x7F,// M + 0x7F, 0x04, 0x08, 0x10, 0x7F,// N + 0x3E, 0x41, 0x41, 0x41, 0x3E,// O + 0x7F, 0x09, 0x09, 0x09, 0x06,// P + 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q + 0x7F, 0x09, 0x19, 0x29, 0x46,// R + 0x46, 0x49, 0x49, 0x49, 0x31,// S + 0x01, 0x01, 0x7F, 0x01, 0x01,// T + 0x3F, 0x40, 0x40, 0x40, 0x3F,// U + 0x1F, 0x20, 0x40, 0x20, 0x1F,// V + 0x7F, 0x20, 0x18, 0x20, 0x7F,// W + 0x63, 0x14, 0x08, 0x14, 0x63,// X + 0x03, 0x04, 0x78, 0x04, 0x03,// Y + 0x61, 0x51, 0x49, 0x45, 0x43,// Z + 0x00, 0x00, 0x7F, 0x41, 0x41,// [ + 0x02, 0x04, 0x08, 0x10, 0x20,// "\" + 0x41, 0x41, 0x7F, 0x00, 0x00,// ] + 0x04, 0x02, 0x01, 0x02, 0x04,// ^ + 0x40, 0x40, 0x40, 0x40, 0x40,// _ + 0x00, 0x01, 0x02, 0x04, 0x00,// ` + 0x20, 0x54, 0x54, 0x54, 0x78,// a + 0x7F, 0x48, 0x44, 0x44, 0x38,// b + 0x38, 0x44, 0x44, 0x44, 0x20,// c + 0x38, 0x44, 0x44, 0x48, 0x7F,// d + 0x38, 0x54, 0x54, 0x54, 0x18,// e + 0x08, 0x7E, 0x09, 0x01, 0x02,// f + 0x08, 0x14, 0x54, 0x54, 0x3C,// g + 0x7F, 0x08, 0x04, 0x04, 0x78,// h + 0x00, 0x44, 0x7D, 0x40, 0x00,// i + 0x20, 0x40, 0x44, 0x3D, 0x00,// j + 0x00, 0x7F, 0x10, 0x28, 0x44,// k + 0x00, 0x41, 0x7F, 0x40, 0x00,// l + 0x7C, 0x04, 0x18, 0x04, 0x78,// m + 0x7C, 0x08, 0x04, 0x04, 0x78,// n + 0x38, 0x44, 0x44, 0x44, 0x38,// o + 0x7C, 0x14, 0x14, 0x14, 0x08,// p + 0x08, 0x14, 0x14, 0x18, 0x7C,// q + 0x7C, 0x08, 0x04, 0x04, 0x08,// r + 0x48, 0x54, 0x54, 0x54, 0x20,// s + 0x04, 0x3F, 0x44, 0x40, 0x20,// t + 0x3C, 0x40, 0x40, 0x20, 0x7C,// u + 0x1C, 0x20, 0x40, 0x20, 0x1C,// v + 0x3C, 0x40, 0x30, 0x40, 0x3C,// w + 0x44, 0x28, 0x10, 0x28, 0x44,// x + 0x0C, 0x50, 0x50, 0x50, 0x3C,// y + 0x44, 0x64, 0x54, 0x4C, 0x44,// z + 0x00, 0x08, 0x36, 0x41, 0x00,// { + 0x00, 0x00, 0x7F, 0x00, 0x00,// | + 0x00, 0x41, 0x36, 0x08, 0x00,// } + 0x08, 0x08, 0x2A, 0x1C, 0x08,// -> + 0x08, 0x1C, 0x2A, 0x08, 0x08, // <- +}; + +/***** Globals *****/ +static uint32_t nhd12832_img_buf[NHD12832_WIDTH *(NUM_PAGES/4)]; + +/***** Functions *****/ + +/* ************************************************************************* */ +static int NHD12832_SendCmd(const uint8_t *cmd, uint32_t size) +{ + GPIO_OutClr(&nhd12832_dc); + + spim_req_t req; + req.ssel = NHD12832_SSEL; + req.deass = 1; + req.tx_data = cmd; + req.rx_data = NULL; + req.width = SPIM_WIDTH_1; + req.len = size; + + if (SPIM_Trans(NHD12832_SPI, &req) != size) { + return E_COMM_ERR; + } + + // Wait for transaction to complete + while(SPIM_Busy(NHD12832_SPI) != E_NO_ERROR) {} + + return E_NO_ERROR; +} + +/* ************************************************************************* */ +static int NHD12832_SendData(const uint8_t *data, uint32_t size) +{ + GPIO_OutSet(&nhd12832_dc); + + spim_req_t req; + req.ssel = NHD12832_SSEL; + req.deass = 1; + req.tx_data = data; + req.rx_data = NULL; + req.width = SPIM_WIDTH_1; + req.len = size; + + if (SPIM_Trans(NHD12832_SPI, &req) != size) { + return E_COMM_ERR; + } + + // Wait for transaction to complete + while(SPIM_Busy(NHD12832_SPI) != E_NO_ERROR) {} + + return E_NO_ERROR; +} + + +int NHD12832_LoadImage(nhd12832_bitmap_t *image) +{ + uint32_t size = image->width * NUM_PAGES; + + if(size > (NHD12832_WIDTH * NUM_PAGES)) + return -1; + memcpy(nhd12832_img_buf, image->bmp, size); + return 0; +} + +/* ************************************************************************* */ +void NHD12832_PrintScreen(void) +{ + NHD12832_SetAddressingMode(1); + NHD12832_SetPageAddr(MIN_PAGE, MAX_PAGE); + NHD12832_SetColumnAddr(0, (NHD12832_WIDTH - 1)); + NHD12832_SendData((uint8_t *)nhd12832_img_buf, (NHD12832_WIDTH * NUM_PAGES)); +} + +/* ************************************************************************* */ +void NHD12832_TurnOnDisplay(uint8_t en) +{ + uint8_t cmd = NHD12832_SET_DISPLAY_OFF; + + if (en) { + cmd |= en; + } + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_SetDisplayClock(uint8_t clk_div, uint8_t freq) +{ + uint8_t cmd[2] = {NHD12832_SET_CLK_DIV_FREQ, 0xA6}; + + /* + * default: 0xA6; + * D[3:0] => display clock divider; + * D[7:4] => oscillator frequency + */ + cmd[1] = (freq << 4) | (clk_div && 0xf); + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetMultiplexRatio(uint8_t ratio) +{ + uint8_t cmd[2] = {NHD12832_SET_MULTI_RATIO, ratio}; // default: 0x3F(1/64 duty) + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetDisplayOffset(uint8_t offset) +{ + uint8_t cmd[2] = {NHD12832_SET_DISPLAY_OFFSET, offset}; + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetStartLine(uint8_t pos) +{ + uint8_t cmd = (NHD12832_SET_DISPLAY_START_LINE | pos); + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_TurnOnInternalDC(uint8_t en) +{ + uint8_t cmd[2] = {NHD12832_SET_INTERNAL_DC, 0x8E}; // Set external Vcc supply (default) + + if(en) { // Set internal DC/DC voltage converter + cmd[1] |= en; + } + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetAddressingMode(uint8_t mode) +{ + /* + * 0x00: horizontal addressing mode; + * 0x01: vertical addressing mode; + * 0x02: page addressing mode (default) + */ + uint8_t cmd[2] = {NHD12832_SET_ADDRESSING_MODE, mode}; + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetSegRemap(uint8_t d) +{ + /* + * 0: Column address 0 mapped to SEG0 + * 1: Column address 0 mapped to SEG131 + */ + uint8_t cmd = (NHD12832_SET_SEG_REMAP | (d & 1)); + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_SetCommonRemap(uint8_t d) +{ + /* + * 0: scan from COM0 to COM63 + * 8: scan from COM63 to COM0 + */ + uint8_t cmd = (NHD12832_SET_COM_REMAP | (d & 8)); + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_TurnOnLeftRightRemap(uint8_t en) +{ + // 0x12: disable COM left/right re-map (default) + uint8_t cmd[2] = {NHD12832_SET_COM_CFG, 0x12}; + if(en) { + cmd[1] = 0x2; + } + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetBanksPulseWidth(uint8_t a, uint8_t b, uint8_t c, uint8_t d) +{ + uint8_t cmd[5] = {NHD12832_SET_BANKS_PULSE_WIDTH, a, b, c, d}; + NHD12832_SendCmd(cmd, 5); +} + +/* ************************************************************************* */ +void NHD12832_SetContrast(uint8_t val) +{ + uint8_t cmd[2] = {NHD12832_SET_CONTRAST, val}; + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetAreaBrightness(uint8_t val) +{ + uint8_t cmd[2] = {NHD12832_SET_BRIGHTNESS, val}; + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetPrechargePeriod(uint8_t phase1, uint8_t phase2) +{ + /* + * default: 0x22(2 display clocks at phase 2; 2 display clocks at phase 1) + * D[3:0] => phase 1 period in 1-15 display clocks + * D[7:4] => phase 2 period in 1-15 display clocks + */ + uint8_t cmd[2] = {0xD9, 0x22}; + cmd[1] = (phase2 << 4) | phase1; + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_TurnOnAreaColorMode(uint8_t en) +{ + uint8_t cmd[2] = {NHD12832_SET_AREA_COLOR_MODE, 0}; // 0: monochrome mode and normal power display mode (default) + + if(en) { + cmd[1] = 0x5; + } + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetVcomh(uint8_t val) +{ + // default: 0x34 (0.77*Vcc) + uint8_t cmd[2] = {0xD8, val}; + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_TurnOnEntireDisplay(uint8_t en) +{ + // 0x0: normal displ + // 0x1: entire display + uint8_t cmd = NHD12832_SET_ENTIRE_DISPLAY; + if(!en) { + cmd &= ~1; + } + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_TurnOnInverseDisplay(uint8_t en) +{ + // 0x0: normal displa + // 0x1: inverse dispaly + uint8_t cmd = NHD12832_SET_INVERSE_DISPLAY; + if(!en) { + cmd &= ~1; + } + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_SetStartColumn(uint8_t pos) +{ + // 0x00: set lower column start address for page addressing mode (default) + // 0x10: set higher column start address for page addressing mode (default) + uint8_t cmd[2] = {(0x00 + (pos%16)), (0x10 + (pos/16))}; + NHD12832_SendCmd(cmd, 2); +} + +/* ************************************************************************* */ +void NHD12832_SetStartPage(uint8_t addr) +{ + // Set page start address for page addressing mode + uint8_t cmd = (NHD12832_SET_START_PAGE | addr); + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_SetColumnAddr(uint8_t start_addr, uint8_t end_addr) +{ + // start_addr: set column start address (default: 0) + // end_addr: set column end address (default: 0x83) + uint8_t cmd[3] = {NHD12832_SET_COLUMN_ADDR, start_addr, end_addr}; + NHD12832_SendCmd(cmd, 3); +} + +/* ************************************************************************* */ +void NHD12832_SetPageAddr(uint8_t start_addr, uint8_t end_addr) +{ + // start_addr: set page start address (default: 0) + // end_addr: set page end address (default: 7) + uint8_t cmd[3] = {NHD12832_SET_PAGE_ADDR, start_addr, end_addr}; + NHD12832_SendCmd(cmd, 3); +} + +/* ************************************************************************* */ +void NHD12832_SetDimMode(uint8_t contrast, uint8_t brightness) +{ + // contrast: contrast control for bank 0 (default: 0x80) + // brightness: brightness for area color banks (default: 0x80) + uint8_t cmd[4] = {NHD12832_SET_DIM_MODE_CFG, 0, contrast, brightness}; + NHD12832_SendCmd(cmd, 4); +} + +/* ************************************************************************* */ +void NHD12832_SetReadModifyWriteMode(uint8_t en) +{ + uint8_t cmd = NHD12832_SET_READ_MOD_WRITE_EN; // 0: enable read-modify-write mode (default) + + if(!en) { + cmd |= 0xE; // 0xE: disable read-modify-write mode + } + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_SetNOP(void) +{ + uint8_t cmd = NHD12832_NOP; + NHD12832_SendCmd(&cmd, 1); +} + +/* ************************************************************************* */ +void NHD12832_FillRAM(uint8_t data) // show regular pattern +{ + uint8_t i, j; + + for(i = 0; i < 8; i++) { + NHD12832_SetStartPage(i); + NHD12832_SetStartColumn(0); + + for(j = 0; j < 132; j++) { + NHD12832_SendData(&data, 1); + } + } +} + +/* ************************************************************************* */ +void NHD12832_SetBankColor(void) +{ + uint8_t cmd[10] = {NHD12832_SET_AREA_COLOR_PAGE0, 0, 0x55, 0xAA, 0xFF, NHD12832_SET_AREA_COLOR_PAGE1, 0xFF, 0xFF, 0xFF, 0xFF}; + NHD12832_SendCmd(cmd, sizeof(cmd)); +} + +// Show regular pattern (partial or full screen) +/* ************************************************************************* */ +void NHD12832_FillBlock(uint8_t data, uint8_t start_page, uint8_t end_page, uint8_t start_column, uint8_t total_column) +{ + uint8_t i, j; + + for(i = start_page; i < (end_page + 1); i++) { + NHD12832_SetStartPage(i); + NHD12832_SetStartColumn(start_column); + for(j = 0; j < total_column; j++) { + NHD12832_SendData(&data, 1); + } + } +} + +/* ************************************************************************* */ +void NHD12832_ShowChecerkBoard(void) // Show checker board (full screen) +{ + uint8_t i, j, data[2] = {0x55, 0xAA}; + + for(i = 0; i < 8; i++) { + NHD12832_SetStartPage(i); + NHD12832_SetStartColumn(0); + + for(j = 0; j < 66; j++) { + NHD12832_SendData(data, 2); + } + } +} + +/* ************************************************************************* */ +void NHD12832_ShowPattern(uint8_t *data, uint8_t start_page, uint8_t end_page, uint8_t start_column, uint8_t total_column) +{ + uint8_t i, *src = data; + + for(i = start_page; i < (end_page + 1); i++) { + NHD12832_SetStartPage(i); + NHD12832_SetStartColumn(start_column); + NHD12832_SendData(src, total_column); + } +} + +/* ************************************************************************* */ +void NHD12832_ShowFont5x7(uint8_t ascii, uint8_t start_page, uint8_t start_column) +{ + uint8_t space = 0; + + if(ascii >= 0x20 && ascii <= 0x7F) { + NHD12832_SetStartPage(start_page); + NHD12832_SetStartColumn(start_column); + NHD12832_SendData(&stdfont5x7[(ascii - 0x20)*5 + 6], 5); + NHD12832_SendData(&space, 1); + } +} + +/* ************************************************************************* */ +void NHD12832_ShowString(uint8_t *str, uint8_t start_page, uint8_t start_column) +{ + uint8_t *src = str; + + while(*src) { + NHD12832_ShowFont5x7(*src++, start_page, start_column); + start_column+=6; + } + + while (start_column < NHD12832_WIDTH) { + NHD12832_ShowFont5x7(' ', start_page, start_column); + start_column+=6; + } +} + +/* ************************************************************************* */ +void NHD12832_Clear(uint8_t start_page, uint8_t start_column) +{ + uint8_t column; + uint8_t space = 0; + + NHD12832_SetStartPage(start_page); + NHD12832_SetStartColumn(start_column); + + for (column = start_column; column < NHD12832_WIDTH; column++) { + NHD12832_SendData(&space, 1); + } +} + +/* ************************************************************************* */ +int NHD12832_Init(void) +{ + int err; + + // Sets GPIO to desired level for the board + Board_nhd12832_Init(); + + // Configure GPIO + GPIO_OutClr(&nhd12832_res); + if ((err = GPIO_Config(&nhd12832_res)) != E_NO_ERROR) { + return err; + } + GPIO_OutClr(&nhd12832_dc); + if ((err = GPIO_Config(&nhd12832_dc)) != E_NO_ERROR) { + return err; + } + + // Configure SPI interface + if ((err = SPIM_Init(NHD12832_SPI, &nhd12832_spim_cfg, &nhd12832_sys_cfg)) != E_NO_ERROR) { + return err; + } + + // Reset RES pin for 200us + GPIO_OutSet(&nhd12832_res); + + // Turn off display + NHD12832_TurnOnDisplay(0); + + // Set display clock to 160fps + NHD12832_SetDisplayClock(0, 1); + + // Set display duty to 1/32 (0xF - 0x3F) + NHD12832_SetMultiplexRatio(0x1F); + + // Shift mapping RAM counter (0x0 - 0x3F) + NHD12832_SetDisplayOffset(0); + + // Set mapping RAM display start line (0x0 - 0x3F) + NHD12832_SetStartLine(0); + + // Disable embedded DC/DC converter + NHD12832_TurnOnInternalDC(0); + + // Set monochrome & low power save mode + NHD12832_TurnOnAreaColorMode(5); + + // Set page addressing mode (0x0 - 0x2) + NHD12832_SetAddressingMode(2); + + // Set seg/column mapping (0x0 - 0x1) + NHD12832_SetSegRemap(1); + + // Set COM scan direction (0x0/0x8) + NHD12832_SetCommonRemap(0x8); + + // Set alternative configuration (0x0/0x10) + NHD12832_TurnOnLeftRightRemap(0); + + // Set all banks pulse width as 64 clocks + NHD12832_SetBanksPulseWidth(0x3F, 0x3F, 0x3F, 0x3F); + + // Set SEG output current + NHD12832_SetContrast(DEFAULT_BRIGHTNESS); + + // Set area brightness + NHD12832_SetAreaBrightness(DEFAULT_BRIGHTNESS); + + // Set pre-charge as 13 clocks and discharge as 2 clocks + NHD12832_SetPrechargePeriod(0x2, 0xD); + + // Set VCOM deselect level + NHD12832_SetVcomh(0x8); + + // Disable entire display (0x0/0x1) + NHD12832_TurnOnEntireDisplay(0); + + // Disable inverse display (0x0/0x1) + NHD12832_TurnOnInverseDisplay(0); + + // Clear screen + NHD12832_FillRAM(0); + + // Turn on display + NHD12832_TurnOnDisplay(1); + + return E_NO_ERROR; +} +/**@}*/ + diff --git a/port/max32630-fthr/board/Source/pb.c b/port/max32630-fthr/board/Source/pb.c new file mode 100644 index 0000000000..34524dcfaf --- /dev/null +++ b/port/max32630-fthr/board/Source/pb.c @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2017-02-28 17:26:15 -0600 (Tue, 28 Feb 2017) $ + * $Revision: 26771 $ + * + ******************************************************************************/ + +#include +#include "mxc_config.h" +#include "mxc_assert.h" +#include "pb.h" + +/******************************************************************************/ +int PB_Init(void) +{ + int retval = E_NO_ERROR; + unsigned int i; + + // Enable pushbutton inputs + for (i = 0; i < num_pbs; i++) { + if (GPIO_Config(&pb_pin[i]) != E_NO_ERROR) { + retval = E_UNKNOWN; + } + } + + return retval; +} + +/******************************************************************************/ +int PB_RegisterCallback(unsigned int pb, pb_callback callback) +{ + MXC_ASSERT(pb < num_pbs); + + if (callback) { + // Register callback + GPIO_RegisterCallback(&pb_pin[pb], callback, (void*)pb); + + // Configure and enable interrupt + GPIO_IntConfig(&pb_pin[pb], GPIO_INT_FALLING_EDGE); + GPIO_IntEnable(&pb_pin[pb]); + NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(pb_pin[pb].port)); + } else { + // Disable interrupt and clear callback + GPIO_IntDisable(&pb_pin[pb]); + GPIO_RegisterCallback(&pb_pin[pb], NULL, NULL); + } + + return E_NO_ERROR; +} + +//****************************************************************************** +void GPIO_P0_IRQHandler(void) +{ + GPIO_Handler(0); +} +void GPIO_P1_IRQHandler(void) +{ + GPIO_Handler(1); +} +void GPIO_P2_IRQHandler(void) +{ + GPIO_Handler(2); +} +void GPIO_P3_IRQHandler(void) +{ + GPIO_Handler(3); +} +void GPIO_P4_IRQHandler(void) +{ + GPIO_Handler(4); +} +void GPIO_P5_IRQHandler(void) +{ + GPIO_Handler(5); +} +void GPIO_P6_IRQHandler(void) +{ + GPIO_Handler(6); +} +void GPIO_P7_IRQHandler(void) +{ + GPIO_Handler(7); +} +void GPIO_P8_IRQHandler(void) +{ + GPIO_Handler(8); +} diff --git a/port/max32630-fthr/board/Source/stdio.c b/port/max32630-fthr/board/Source/stdio.c new file mode 100644 index 0000000000..b740111fdc --- /dev/null +++ b/port/max32630-fthr/board/Source/stdio.c @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + * + * $Date: 2016-06-01 13:52:10 -0500 (Wed, 01 Jun 2016) $ + * $Revision: 23141 $ + * + ******************************************************************************/ + +#include +#include +#include +#include +#include + +#if defined ( __GNUC__ ) +#include +#include +#endif /* __GNUC__ */ + +#if defined ( __CC_ARM ) +#include +#pragma import(__use_no_semihosting_swi) + +struct __FILE { int handle; }; +FILE __stdout; +FILE __stdin; + +#endif /* __CC_ARM */ + +/* Defines - Compiler Specific */ +#if defined ( __ICCARM__ ) +#define STDIN_FILENO 0 // Defines that are not included in the DLIB. +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +#define EBADF -1 +#endif /* __ICCARM__ */ + +#include "mxc_config.h" +#include "uart.h" +#include "board.h" + +#define MXC_UARTn MXC_UART_GET_UART(CONSOLE_UART) +#define UART_FIFO MXC_UART_GET_FIFO(CONSOLE_UART) + +static void UART_PutChar(const uint8_t data) +{ + // Wait for TXFIFO to not be full + while ((MXC_UARTn->tx_fifo_ctrl & MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY) == MXC_F_UART_TX_FIFO_CTRL_FIFO_ENTRY); + MXC_UARTn->intfl = MXC_F_UART_INTFL_TX_DONE; // clear DONE flag for UART_PrepForSleep + UART_FIFO->tx = data; +} + +static uint8_t UART_GetChar(void) +{ + while (!(MXC_UARTn->rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY)); + return UART_FIFO->rx; +} + +/* The following libc stub functions are required for a proper link with printf(). + * These can be tailored for a complete stdio implementation. + * GNUC requires all functions below. IAR & KEIL only use read and write. + */ +#if defined ( __GNUC__ ) +int _open(const char *name, int flags, int mode) +{ + return -1; +} +int _close(int file) +{ + return -1; +} +int _isatty(int file) +{ + return -1; +} +int _lseek(int file, off_t offset, int whence) +{ + return -1; +} +int _fstat(int file, struct stat *st) +{ + return -1; +} +#endif /* __GNUC__ */ + +/* Handle IAR and ARM/Keil Compilers for _read/_write. Keil uses fputc and + fgetc for stdio */ +#if defined (__ICCARM__) || defined ( __GNUC__ ) + +#if defined ( __GNUC__ ) // GNUC _read function prototype +int _read(int file, char *ptr, int len) +#elif defined ( __ICCARM__ ) // IAR Compiler _read function prototype +int __read(int file, unsigned char *ptr, size_t len) +#endif /* __GNUC__ */ +{ + unsigned int n; + int num = 0; + + switch (file) { + case STDIN_FILENO: + for (n = 0; n < len; n++) { + *ptr = UART_GetChar(); + UART_PutChar(*ptr); + ptr++; + num++; + } + break; + default: + errno = EBADF; + return -1; + } + return num; +} + +/* newlib/libc printf() will eventually call write() to get the data to the stdout */ +#if defined ( __GNUC__ ) +// GNUC _write function prototype +int _write(int file, char *ptr, int len) +{ + int n; +#elif defined ( __ICCARM__ ) // IAR Compiler _read function prototype +// IAR EW _write function prototype +int __write(int file, const unsigned char *ptr, size_t len) +{ + size_t n; +#endif /* __GNUC__ */ + + + switch (file) { + case STDOUT_FILENO: + case STDERR_FILENO: + for (n = 0; n < len; n++) { + if (*ptr == '\n') { + UART_PutChar('\r'); + } + UART_PutChar(*ptr++); + } + break; + default: + errno = EBADF; + return -1; + } + + return len; +} + +#endif /* ( __ICCARM__ ) || ( __GNUC__ ) */ + +/* Handle Keil/ARM Compiler which uses fputc and fgetc for stdio */ +#if defined ( __CC_ARM ) +int fputc(int c, FILE *f) { + if(c != '\n') { + UART_PutChar(c); + } else { + UART_PutChar('\r'); + UART_PutChar('\n'); + } + + return 0; +} + +int fgetc(FILE *f) { + return (UART_GetChar()); +} + +int ferror(FILE *f) { + return EOF; +} + +void _ttywrch(int c) { + if(c != '\n') { + UART_PutChar(c); + } else { + UART_PutChar('\r'); + UART_PutChar('\n'); + } +} + +void _sys_exit(int return_code) { + while(1) {} +} + +#endif /* __CC_ARM */ diff --git a/port/max32630-fthr/board/board.h b/port/max32630-fthr/board/max32630-fthr/Include/board.h similarity index 97% rename from port/max32630-fthr/board/board.h rename to port/max32630-fthr/board/max32630-fthr/Include/board.h index 71fd4c1b4f..ccabac84fc 100644 --- a/port/max32630-fthr/board/board.h +++ b/port/max32630-fthr/board/max32630-fthr/Include/board.h @@ -42,6 +42,8 @@ #ifndef _BOARD_H #define _BOARD_H +#include "mxc_config.h" +#include "adc.h" #include "gpio.h" #include "spim.h" #include "ioman.h" @@ -75,7 +77,7 @@ extern const uart_cfg_t console_uart_cfg; extern const sys_cfg_uart_t console_sys_cfg; // MAX14690 PMIC -#define MAX14690_I2CM_INST 0 +#define MAX14690_I2CM_INST 2 #define MAX14690_I2CM MXC_I2CM2 extern const ioman_cfg_t max14690_io_cfg; extern const gpio_cfg_t max14690_int; diff --git a/port/max32630-fthr/board/board.c b/port/max32630-fthr/board/max32630-fthr/Source/board.c similarity index 100% rename from port/max32630-fthr/board/board.c rename to port/max32630-fthr/board/max32630-fthr/Source/board.c diff --git a/port/max32630-fthr/board/max32630-fthr/board.mk b/port/max32630-fthr/board/max32630-fthr/board.mk new file mode 100644 index 0000000000..5a238111f7 --- /dev/null +++ b/port/max32630-fthr/board/max32630-fthr/board.mk @@ -0,0 +1,23 @@ +ifeq "$(BOARD_DIR)" "" +$(error BOARD_DIR must be set) +endif + +PROJ_CFLAGS+=-DRO_FREQ=96000000 + +# Source files for this board (add path to VPATH below) +SRCS += board.c +SRCS += stdio.c +SRCS += led.c +SRCS += pb.c +SRCS += max14690n.c +# TODO: Check can we drop the +# variant and use the common part +# SRCS += max14690.c + +# Where to find BSP source files +VPATH += $(BOARD_DIR)/Source +VPATH += $(BOARD_DIR)/../Source + +# Where to find BSP header files +IPATH += $(BOARD_DIR)/Include +IPATH += $(BOARD_DIR)/../Include \ No newline at end of file diff --git a/port/max32630-fthr/example/template/Categories.mk b/port/max32630-fthr/example/template/Categories.mk new file mode 100644 index 0000000000..081b28b1e9 --- /dev/null +++ b/port/max32630-fthr/example/template/Categories.mk @@ -0,0 +1,68 @@ + +# List of General Examples without Bluetooth + +EXAMPLES_GENERAL = \ + audio_duplex \ + led_counter \ + mod_player \ + sine_player \ + +# List of Examples that only use Bluetooth BR/EDR = Classic +EXAMPLES_CLASSIC_ONLY = \ + a2dp_sink_demo \ + a2dp_source_demo \ + avrcp_browsing_client \ + dut_mode_classic \ + gap_dedicated_bonding \ + gap_inquiry \ + gap_link_keys \ + hfp_ag_demo \ + hfp_hf_demo \ + hid_host_demo \ + hid_keyboard_demo \ + hid_mouse_demo \ + hsp_ag_demo \ + hsp_hs_demo \ + pbap_client_demo \ + sdp_bnep_query \ + sdp_general_query \ + sdp_rfcomm_query \ + spp_counter \ + spp_flowcontrol \ + spp_streamer \ + spp_streamer_client \ + +# List of Examples that only use Bluetooth LE +EXAMPLES_LE_ONLY = \ + ancs_client_demo \ + att_delayed_response \ + gap_le_advertisements \ + gatt_battery_query \ + gatt_browser \ + gatt_counter \ + gatt_device_information_query \ + gatt_heart_rate_client \ + gatt_streamer_server \ + hog_boot_host_demo \ + hog_host_demo \ + hog_keyboard_demo \ + hog_mouse_demo \ + le_credit_based_flow_control_mode_client \ + le_credit_based_flow_control_mode_server \ + le_mitm \ + le_streamer_client \ + nordic_spp_le_counter \ + nordic_spp_le_streamer \ + sm_pairing_central \ + sm_pairing_peripheral \ + ublox_spp_le_counter \ +# mesh_node_demo + +# List of Examples that use Bluetooth BR/EDR/LE = Dual Mode +EXAMPLES_DUAL_MODE = \ + gatt_counter \ + gatt_streamer_server \ + spp_and_gatt_counter \ + spp_and_gatt_streamer \ + +EXAMPLES_ALL = ${EXAMPLES_CLASSIC_ONLY} ${EXAMPLES_DUAL_MODE} ${EXAMPLES_LE_ONLY} ${EXAMPLES_GENERAL} \ No newline at end of file diff --git a/port/max32630-fthr/example/template/Dependencies.mk b/port/max32630-fthr/example/template/Dependencies.mk new file mode 100644 index 0000000000..b0ed3645e6 --- /dev/null +++ b/port/max32630-fthr/example/template/Dependencies.mk @@ -0,0 +1,350 @@ +SHELL := bash +PYTHON ?= python +# BTstack +VPATH += $(BTSTACK_ROOT)/chipset/cc256x +VPATH += $(BTSTACK_ROOT)/example +VPATH += $(BTSTACK_ROOT)/port/pegasus-max3263x +VPATH += $(BTSTACK_ROOT)/src +VPATH += $(BTSTACK_ROOT)/src/ble +VPATH += $(BTSTACK_ROOT)/src/classic +VPATH += $(BTSTACK_ROOT)/src/mesh +VPATH += ${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce +VPATH += ${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce +VPATH += ${BTSTACK_ROOT}/3rd-party/hxcmod-player +VPATH += ${BTSTACK_ROOT}/3rd-party/hxcmod-player/mods +VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ +VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4 +VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv6 +VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/netif +VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http +VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server +VPATH += ${BTSTACK_ROOT}/3rd-party/md5 +VPATH += ${BTSTACK_ROOT}/3rd-party/yxml +VPATH += ${BTSTACK_ROOT}/3rd-party/micro-ecc +VPATH += $(BTSTACK_ROOT)/platform/posix +VPATH += ${BTSTACK_ROOT}/platform/embedded +VPATH += ${BTSTACK_ROOT}/platform/lwip +VPATH += ${BTSTACK_ROOT}/platform/lwip/port +VPATH += ${BTSTACK_ROOT}/src/ble/gatt-service + +PROJ_CFLAGS += \ + -I$(BTSTACK_ROOT)/src \ + -I$(BTSTACK_ROOT)/src/ble \ + -I$(BTSTACK_ROOT)/src/classic \ + -I$(BTSTACK_ROOT)/src/mesh \ + -I$(BTSTACK_ROOT)/chipset/cc256x \ + -I$(BTSTACK_ROOT)/platform/posix \ + -I$(BTSTACK_ROOT)/platform/embedded \ + -I$(BTSTACK_ROOT)/platform/lwip \ + -I$(BTSTACK_ROOT)/platform/lwip/port \ + -I${BTSTACK_ROOT}/port/pegasus-max3263x \ + -I${BTSTACK_ROOT}/src/ble/gatt-service/ \ + -I${BTSTACK_ROOT}/example \ + -I${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include \ + -I${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include \ + -I${BTSTACK_ROOT}/3rd-party/md5 \ + -I${BTSTACK_ROOT}/3rd-party/yxml \ + -I${BTSTACK_ROOT}/3rd-party/micro-ecc \ + -I${BTSTACK_ROOT}/3rd-party/hxcmod-player \ + -I${BTSTACK_ROOT}/3rd-party/lwip/core/src/include \ + -I${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server \ + +CORE = \ + btstack_audio.c \ + btstack_crypto.c \ + btstack_link_key_db_tlv.c \ + btstack_linked_list.c \ + btstack_memory.c \ + btstack_memory_pool.c \ + btstack_run_loop.c \ + btstack_run_loop_embedded.c \ + btstack_stdin_embedded.c \ + btstack_tlv.c \ + btstack_tlv_flash_bank.c \ + btstack_uart_block_embedded.c \ + btstack_util.c \ + +COMMON = \ + ad_parser.c \ + hci.c \ + hci_cmd.c \ + hci_dump.c \ + hci_dump_embedded_stdout.c \ + hci_event_builder.c \ + hci_transport_h4.c \ + l2cap.c \ + l2cap_signaling.c \ + le_device_db_tlv.c \ + sm.c \ + uECC.c \ + +CLASSIC = \ + sdp_util.c \ + gatt_sdp.c \ + spp_server.c \ + rfcomm.c \ + bnep.c \ + sdp_server.c \ + device_id_server.c \ + +BLE = \ + att_db.c \ + att_server.c \ + le_device_db_tlv.c \ + att_dispatch.c \ + ancs_client.c \ + gatt_client.c \ + hid_device.c \ + battery_service_server.c \ + +SDP_CLIENT_OBJ = \ + sdp_client.o \ + sdp_client_rfcomm.o \ + +ATT = \ + att_dispatch.c \ + +GATT_SERVER = \ + att_db.c \ + att_server.c \ + +GATT_CLIENT = \ + gatt_client.c \ + gatt_service_client.c \ + battery_service_client.c \ + device_information_service_client.c \ + scan_parameters_service_client.c \ + hids_client.c \ + +PAN = \ + pan.c \ + +MBEDTLS = \ + bignum.c \ + ecp.c \ + ecp_curves.c \ + sm_mbedtls_allocator.c \ + memory_buffer_alloc.c \ + platform.c \ + + +LWIP_CORE_SRC = init.c mem.c memp.c netif.c udp.c ip.c pbuf.c inet_chksum.c def.c tcp.c tcp_in.c tcp_out.c timeouts.c sys_arch.c +LWIP_IPV4_SRC = acd.c dhcp.c etharp.c icmp.c ip4.c ip4_frag.c ip4_addr.c +LWIP_NETIF_SRC = ethernet.c +LWIP_HTTPD = altcp_proxyconnect.c fs.c httpd.c +LWIP_SRC = ${LWIP_CORE_SRC} ${LWIP_IPV4_SRC} ${LWIP_NETIF_SRC} ${LWIP_HTTPD} dhserver.c + +# List of files for Bluedroid SBC codec +include ${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/Makefile.inc +include ${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/Makefile.inc + +SBC_CODEC = \ + ${SBC_DECODER} \ + btstack_sbc_plc.c \ + btstack_sbc_decoder_bluedroid.c \ + ${SBC_ENCODER} \ + btstack_sbc_encoder_bluedroid.c \ + hfp_msbc.c \ + hfp_codec.c \ + btstack_sbc_bluedroid.c + +CVSD_PLC = \ + btstack_cvsd_plc.c \ + +AVDTP = \ + avdtp_util.c \ + avdtp.c \ + avdtp_initiator.c \ + avdtp_acceptor.c \ + avdtp_source.c \ + avdtp_sink.c \ + a2dp.c \ + a2dp_source.c \ + a2dp_sink.c \ + btstack_ring_buffer.c \ + btstack_resample.c \ + +AVRCP = \ + avrcp.c \ + avrcp_controller.c \ + avrcp_target.c \ + avrcp_browsing.c \ + avrcp_browsing_controller.c \ + avrcp_browsing_target.c \ + avrcp_media_item_iterator.c \ + +HXCMOD_PLAYER = \ + hxcmod.c \ + nao-deceased_by_disease.c \ + +MESH = \ + adv_bearer.c \ + beacon.c \ + gatt_bearer.c \ + mesh.c \ + mesh_access.c \ + mesh_configuration_client.c \ + mesh_configuration_server.c \ + mesh_crypto.c \ + mesh_foundation.c \ + mesh_generic_default_transition_time_client.c \ + mesh_generic_default_transition_time_server.c \ + mesh_generic_level_client.c \ + mesh_generic_level_server.c \ + mesh_generic_on_off_client.c \ + mesh_generic_on_off_server.c \ + mesh_health_server.c \ + mesh_iv_index_seq_number.c \ + mesh_keys.c \ + mesh_lower_transport.c \ + mesh_network.c \ + mesh_node.c \ + mesh_peer.c \ + mesh_provisioning_service_server.c \ + mesh_proxy.c \ + mesh_proxy_service_server.c \ + mesh_upper_transport.c \ + mesh_virtual_addresses.c \ + pb_adv.c \ + pb_gatt.c \ + provisioning.c \ + provisioning_device.c \ + provisioning_provisioner.c \ + +# List of GATT files used by either LE_ONLY or DUAL_MODE examples + +EXAMPLES_GATT_FILES = \ + ancs_client_demo.ga\ + att_delayed_response.ga\ + gatt_battery_query.ga\ + gatt_browser.ga\ + gatt_counter.ga\ + gatt_device_information_query.ga\ + gatt_streamer_server.ga\ + hog_host_demo.ga\ + hog_keyboard_demo.ga\ + hog_mouse_demo.ga\ + le_credit_based_flow_control_mode_server.ga\ + nordic_spp_le_counter.ga\ + nordic_spp_le_streamer.ga\ + sm_pairing_central.ga\ + sm_pairing_peripheral.ga\ + spp_and_gatt_counter.ga\ + spp_and_gatt_streamer.ga\ + ublox_spp_le_counter.ga + +include ${PORT_DIR}/example/template/Categories.mk +# define target variant for chipset/cc256x/Makefile.inc +ifneq ($(filter $(PROJECT),$(EXAMPLES_GENERAL)),) + $(info $(PROJECT) in EXAMPLES_GENERAL) +else + $(info $(PROJECT) not in EXAMPLES_GENERAL: $(EXAMPLES_GENERAL)) + override CONVERSION_SCRIPT = $(PYTHON) $(BTSTACK_ROOT)/chipset/cc256x/convert_bts_init_scripts.py + include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc + CORE += btstack_chipset_cc256x.c + COMMON += $(cc256x_init_script) + PROJ_CFLAGS += -DENABLE_HCI_INIT +endif + +# .o for .c +ATT_OBJ = $(ATT:.c=.o) +AVDTP_OBJ = $(AVDTP:.c=.o) +AVRCP_OBJ = $(AVRCP:.c=.o) +BLE_OBJ = $(BLE:.c=.o) +CLASSIC_OBJ = $(CLASSIC:.c=.o) +COMMON_OBJ = $(COMMON:.c=.o) +CORE_OBJ = $(CORE:.c=.o) +CVSD_PLC_OBJ = $(CVSD_PLC:.c=.o) +GATT_CLIENT_OBJ = $(GATT_CLIENT:.c=.o) +GATT_SERVER_OBJ = $(GATT_SERVER:.c=.o) +HXCMOD_PLAYER_OBJ = $(HXCMOD_PLAYER:.c=.o) +LWIP_OBJ = $(LWIP_SRC:.c=.o) +MESH_OBJ = $(MESH:.c=.o) +PAN_OBJ = $(PAN:.c=.o) +SBC_CODEC_OBJ = $(SBC_CODEC:.c=.o) + +# examples + +# general - no bluetooth +GENERAL_DEPS = ${CORE_OBJ} ${COMMON_OBJ} +audio_duplex_deps = ${GENERAL_DEPS} btstack_audio.o btstack_ring_buffer.o audio_duplex.c +led_counter_deps = ${GENERAL_DEPS} led_counter.c +mod_player_deps = ${GENERAL_DEPS} ${HXCMOD_PLAYER_OBJ} btstack_audio.o mod_player.c +sine_player_deps = ${GENERAL_DEPS} btstack_audio.o sine_player.c +# general - END + +# le - bluetooth le +BLE_DEPS = ${BLE_OBJ} ${GENERAL_DEPS} +ancs_client_demo_deps = ${BLE_DEPS} ${CLASSIC_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${GATT_CLIENT_OBJ} ancs_client.o ancs_client_demo.o +att_delayed_response_deps = ${BLE_DEPS} $(CLASSIC_OBJ) ${ATT_OBJ} ${GATT_SERVER_OBJ} att_delayed_response.o +gap_le_advertisements_deps = ${BLE_DEPS} gap_le_advertisements.c +gatt_battery_query_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${GATT_SERVER_OBJ} gatt_battery_query.o +gatt_browser_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${GATT_SERVER_OBJ} gatt_browser.o +gatt_device_information_query_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${GATT_SERVER_OBJ} gatt_device_information_query.o +gatt_heart_rate_client_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_CLIENT_OBJ} gatt_heart_rate_client.c +hog_boot_host_demo_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_CLIENT_OBJ} hog_boot_host_demo.o +hog_host_demo_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_CLIENT_OBJ} ${GATT_SERVER_OBJ} btstack_hid_parser.o btstack_hid.o hog_host_demo.o +hog_keyboard_demo_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} battery_service_server.o device_information_service_server.o btstack_hid_parser.o hids_device.o btstack_ring_buffer.o hog_keyboard_demo.o +hog_mouse_demo_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} battery_service_server.o device_information_service_server.o btstack_hid_parser.o hids_device.o hog_mouse_demo.o +le_credit_based_flow_control_mode_client_deps = ${BLE_DEPS} le_credit_based_flow_control_mode_client.c +le_credit_based_flow_control_mode_server_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} le_credit_based_flow_control_mode_server.o +le_mitm_deps = ${BLE_DEPS} le_mitm.c +le_streamer_client_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_CLIENT_OBJ} le_streamer_client.c +mesh_node_demo_deps = ${BLE_DEPS} ${MESH_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_OBJ} mesh_node_demo.o +nordic_spp_le_counter_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} nordic_spp_service_server.o nordic_spp_le_counter.o +nordic_spp_le_streamer_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} nordic_spp_service_server.o nordic_spp_le_streamer.o +sm_pairing_central_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${GATT_CLIENT_OBJ} sm_pairing_central.o +sm_pairing_peripheral_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${GATT_CLIENT_OBJ} sm_pairing_peripheral.o +ublox_spp_le_counter_deps = ${BLE_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} device_information_service_server.o ublox_spp_service_server.o ublox_spp_le_counter.o +# le - END + +# classic - no le +CLASSIC_DEPS = ${GENERAL_DEPS} ${CLASSIC_OBJ} +a2dp_sink_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${SBC_CODEC_OBJ} ${AVDTP_OBJ} avrcp.o avrcp_controller.o avrcp_target.o avrcp_cover_art_client.o obex_srm_client.o goep_client.o obex_parser.o obex_message_builder.o btstack_sample_rate_compensation.o a2dp_sink_demo.c +a2dp_source_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${SBC_CODEC_OBJ} ${AVDTP_OBJ} ${HXCMOD_PLAYER_OBJ} avrcp.o avrcp_controller.o avrcp_target.o a2dp_source_demo.c +ant_test_deps = ${CLASSIC_DEPS} ant_test.c +avrcp_browsing_client_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${AVRCP_OBJ} ${AVDTP_OBJ} avrcp_browsing_client.c +dut_mode_classic_deps = ${CLASSIC_DEPS} dut_mode_classic.c +gap_dedicated_bonding_deps = ${CLASSIC_DEPS} gap_dedicated_bonding.c +gap_inquiry_deps = ${CLASSIC_DEPS} gap_inquiry.c +gap_link_keys_deps = ${CLASSIC_DEPS} gap_link_keys.c +hfp_ag_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${SBC_CODEC_OBJ} ${CVSD_PLC_OBJ} wav_util.o sco_demo_util.o btstack_ring_buffer.o hfp.o hfp_gsm_model.o hfp_ag.o hfp_ag_demo.c +hfp_hf_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${SBC_CODEC_OBJ} ${CVSD_PLC_OBJ} wav_util.o sco_demo_util.o btstack_ring_buffer.o hfp.o hfp_hf.o hfp_hf_demo.c +hid_host_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} btstack_hid_parser.o hid_host.o hid_host_demo.o +hid_keyboard_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} btstack_ring_buffer.o hid_device.o btstack_hid_parser.o hid_keyboard_demo.o +hid_mouse_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} btstack_ring_buffer.o hid_device.o btstack_hid_parser.o hid_mouse_demo.o +hsp_ag_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${SBC_CODEC_OBJ} ${CVSD_PLC_OBJ} wav_util.o sco_demo_util.o btstack_ring_buffer.o hsp_ag.o hsp_ag_demo.c +hsp_hs_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${SBC_CODEC_OBJ} ${CVSD_PLC_OBJ} wav_util.o sco_demo_util.o btstack_ring_buffer.o hsp_hs.o hsp_hs_demo.c +panu_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${PAN_OBJ} panu_demo.c +pan_lwip_http_server_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} ${PAN_OBJ} ${LWIP_SRC} btstack_ring_buffer.o bnep_lwip.o pan_lwip_http_server.o +pbap_client_demo_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} md5.o obex_iterator.o obex_parser.o obex_message_builder.o obex_srm_client.o goep_client.o yxml.o pbap_client.o pbap_client_demo.o +sdp_bnep_query_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} sdp_bnep_query.c +sdp_general_query_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} sdp_general_query.c +sdp_rfcomm_query_deps = ${CLASSIC_DEPS} ${PAN_OBJ} ${SDP_CLIENT_OBJ} sdp_rfcomm_query.c +spp_counter_deps = ${CLASSIC_DEPS} spp_counter.c +spp_flowcontrol_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} spp_flowcontrol.c +spp_streamer_client_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} spp_streamer_client.c +spp_streamer_deps = ${CLASSIC_DEPS} ${SDP_CLIENT_OBJ} spp_streamer.c +# classic - END + +# dual - classic + le +DUAL_DEPS = ${GENERAL_DEPS} ${BLE_OBJ} ${CLASSIC_OBJ} +gatt_counter_deps = ${DUAL_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} battery_service_server.o gatt_counter.o +gatt_streamer_server_deps = ${DUAL_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} gatt_streamer_server.o +spp_and_gatt_counter_deps = ${DUAL_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} spp_and_gatt_counter.o +spp_and_gatt_streamer_deps = ${DUAL_DEPS} ${ATT_OBJ} ${GATT_SERVER_OBJ} spp_and_gatt_streamer.o +# dual - END + +# Expands PROJECT_FEATURES when $(PROJECT)_deps is empty. +# Expected values are the XX_DEPS and XX_OBJ values defined in Dependencies.mk +# e.g. PROJECT_FEATURES = DUAL_DEPS ATT_OBJ GATT_SERVER_OBJ +ifeq ($($(PROJECT)_deps),) + ifeq ($(PROJECT_FEATURES),) + $(warning $(PROJECT)_deps is empty) + else + # Add dependencies + $(foreach dep, $(PROJECT_FEATURES), $(eval $(PROJECT)_deps += $($(dep)))) + # Add main project file to build $(PROJECT).o from $(PROJECT).c + $(PROJECT)_deps += $(PROJECT) + endif +endif \ No newline at end of file diff --git a/port/max32630-fthr/example/template/Makefile b/port/max32630-fthr/example/template/Makefile deleted file mode 100644 index 85eb62fca3..0000000000 --- a/port/max32630-fthr/example/template/Makefile +++ /dev/null @@ -1,302 +0,0 @@ -################################################################################ - # Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. - # Ismail H. Kose - # Permission is hereby granted, free of charge, to any person obtaining a - # copy of this software and associated documentation files (the "Software"), - # to deal in the Software without restriction, including without limitation - # the rights to use, copy, modify, merge, publish, distribute, sublicense, - # and/or sell copies of the Software, and to permit persons to whom the - # Software is furnished to do so, subject to the following conditions: - # - # The above copyright notice and this permission notice shall be included - # in all copies or substantial portions of the Software. - # - # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - # IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES - # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - # OTHER DEALINGS IN THE SOFTWARE. - # - # Except as contained in this notice, the name of Maxim Integrated - # Products, Inc. shall not be used except as stated in the Maxim Integrated - # Products, Inc. Branding Policy. - # - # The mere transfer of this software does not imply any licenses - # of trade secrets, proprietary technology, copyrights, patents, - # trademarks, maskwork rights, or any other form of intellectual - # property whatsoever. Maxim Integrated Products, Inc. retains all - # ownership rights. - # - # $Date: 2016-03-23 13:28:53 -0700 (Wed, 23 Mar 2016) $ - # $Revision: 22067 $ - # - ############################################################################### - -# Maxim ARM Toolchain and Libraries -# https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630.html - -# This is the name of the build output file -PROJECT=spp_and_le_streamer - -# Specify the target processor -TARGET=MAX3263x -PROJ_CFLAGS+=-DRO_FREQ=96000000 -PROJ_CFLAGS+=-g3 -ggdb -DDEBUG -CPPFLAGS+=-g3 -ggdb -DDEBUG - -# Create Target name variables -TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z) -TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z) - -CC2564B = bluetooth_init_cc2564B_1.8_BT_Spec_4.1.o - -# Select 'GCC' or 'IAR' compiler -COMPILER=GCC - -ifeq "$(MAXIM_PATH)" "" -LIBS_DIR=/$(subst \,/,$(subst :,,$(HOME))/Maxim/Firmware/$(TARGET_UC)/Libraries) -$(warning "MAXIM_PATH need to be set. Please run setenv bash file in the Maxim Toolchain directory.") -else -LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries) -endif - -CMSIS_ROOT=$(LIBS_DIR)/CMSIS - -# Where to find source files for this test -VPATH= . ../../src - -# Where to find header files for this test -IPATH= . ../../src - -BOARD_DIR=$(LIBS_DIR)/Boards - -IPATH += ../../board/ -VPATH += ../../board/ - -# Source files for this test (add path to VPATH below) -SRCS = main.c -SRCS += hal_tick.c -SRCS += btstack_port.c -SRCS += ${PROJECT}.c -SRCS += board.c -SRCS += stdio.c -SRCS += led.c -SRCS += pb.c -SRCS += max14690n.c - -# Where to find BSP source files -VPATH += $(BOARD_DIR)/Source - -# Where to find BSP header files -IPATH += $(BOARD_DIR)/Include - -# BTstack -BTSTACK_ROOT ?= ../../../.. -VPATH += $(BTSTACK_ROOT)/chipset/cc256x -VPATH += $(BTSTACK_ROOT)/example -VPATH += $(BTSTACK_ROOT)/port/pegasus-max3263x -VPATH += $(BTSTACK_ROOT)/src -VPATH += $(BTSTACK_ROOT)/src/ble -VPATH += $(BTSTACK_ROOT)/src/classic -VPATH += ${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce -VPATH += ${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce -VPATH += ${BTSTACK_ROOT}/3rd-party/hxcmod-player -VPATH += ${BTSTACK_ROOT}/3rd-party/hxcmod-player/mods -VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ -VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4 -VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv6 -VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/netif -VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http -VPATH += ${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server -VPATH += ${BTSTACK_ROOT}/3rd-party/md5 -VPATH += ${BTSTACK_ROOT}/3rd-party/yxml -VPATH += ${BTSTACK_ROOT}/3rd-party/micro-ecc -VPATH += ${BTSTACK_ROOT}/platform/embedded -VPATH += ${BTSTACK_ROOT}/platform/lwip -VPATH += ${BTSTACK_ROOT}/platform/lwip/port -VPATH += ${BTSTACK_ROOT}/src/ble/gatt-service/ - -PROJ_CFLAGS += \ - -I$(BTSTACK_ROOT)/src \ - -I$(BTSTACK_ROOT)/src/ble \ - -I$(BTSTACK_ROOT)/src/classic \ - -I$(BTSTACK_ROOT)/chipset/cc256x \ - -I$(BTSTACK_ROOT)/platform/embedded \ - -I$(BTSTACK_ROOT)/platform/lwip \ - -I$(BTSTACK_ROOT)/platform/lwip/port \ - -I${BTSTACK_ROOT}/port/pegasus-max3263x \ - -I${BTSTACK_ROOT}/src/ble/gatt-service/ \ - -I${BTSTACK_ROOT}/example \ - -I${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include \ - -I${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include \ - -I${BTSTACK_ROOT}/3rd-party/md5 \ - -I${BTSTACK_ROOT}/3rd-party/yxml \ - -I${BTSTACK_ROOT}/3rd-party/micro-ecc \ - -I${BTSTACK_ROOT}/3rd-party/hxcmod-player \ - -I${BTSTACK_ROOT}/3rd-party/lwip/core/src/include \ - -I${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server \ - - -CORE = \ - ad_parser.o \ - btstack_linked_list.o \ - btstack_memory.o \ - btstack_memory_pool.o \ - btstack_run_loop.o \ - btstack_util.o \ - l2cap.o \ - l2cap_signaling.o \ - btstack_run_loop_embedded.o \ - $(CC2564B) \ - hci_transport_h4.o - -COMMON = \ - btstack_chipset_cc256x.o \ - hci.o \ - hci_cmd.o \ - hci_dump.o \ - hci_dump_embedded_stdout.o \ - hci_event_builder.o \ - btstack_uart_block_embedded.o \ - hal_flash_bank_mxc.o \ - btstack_audio.o \ - btstack_tlv.o \ - btstack_tlv_flash_bank.o \ - btstack_stdin_embedded.o \ - btstack_crypto.o \ - -CLASSIC = \ - btstack_link_key_db_tlv.o \ - hid_device.o \ - hid_host.o \ - rfcomm.o \ - sdp_util.o \ - spp_server.o \ - sdp_server.o \ - sdp_client.o \ - sdp_client_rfcomm.o - -BLE = \ - att_db.o \ - att_server.o \ - le_device_db_tlv.o \ - att_dispatch.o \ - sm.o \ - ancs_client.o \ - gatt_client.o \ - hid_device.o \ - battery_service_server.o \ - uECC.o \ - -AVDTP += \ - avdtp_util.c \ - avdtp.c \ - avdtp_initiator.c \ - avdtp_acceptor.c \ - avdtp_source.c \ - avdtp_sink.c \ - a2dp.c \ - a2dp_source.c \ - a2dp_sink.c \ - btstack_ring_buffer.c \ - btstack_resample.c \ - avrcp.c \ - avrcp_target.c \ - avrcp_controller.c \ - -HFP_OBJ += sco_demo_util.o btstack_ring_buffer.o hfp.o hfp_gsm_model.o hfp_ag.o hfp_hf.o - -# List of files for Bluedroid SBC codec -include ${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/Makefile.inc -include ${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/Makefile.inc - -SBC_DECODER += \ - btstack_sbc_plc.c \ - btstack_sbc_decoder_bluedroid.c \ - -SBC_ENCODER += \ - btstack_sbc_encoder_bluedroid.c \ - hfp_msbc.c \ - hfp_codec.c - -HXCMOD_PLAYER = \ - hxcmod.c \ - nao-deceased_by_disease.c \ - -LWIP_CORE_SRC = init.c mem.c memp.c netif.c udp.c ip.c pbuf.c inet_chksum.c def.c tcp.c tcp_in.c tcp_out.c timeouts.c sys_arch.c -LWIP_IPV4_SRC = acd.c dhcp.c etharp.c icmp.c ip4.c ip4_frag.c ip4_addr.c -LWIP_NETIF_SRC = ethernet.c -LWIP_HTTPD = altcp_proxyconnect.c fs.c httpd.c -LWIP_SRC = ${LWIP_CORE_SRC} ${LWIP_IPV4_SRC} ${LWIP_NETIF_SRC} ${LWIP_HTTPD} dhserver.c - -ADDITION = - -CORE_OBJ = $(CORE:.c=.o) -COMMON_OBJ = $(COMMON:.c=.o) -BLE_OBJ = $(BLE:.c=.o) -CLASSIC_OBJ = $(CLASSIC:.c=.o) -AVDTP_OBJ = $(AVDTP:.c=.o) -SBC_DECODER_OBJ = $(SBC_DECODER:.c=.o) -SBC_ENCODER_OBJ = $(SBC_ENCODER:.c=.o) -CVSD_PLC_OBJ = $(CVSD_PLC:.c=.o) -HXCMOD_PLAYER_OBJ = $(HXCMOD_PLAYER:.c=.o) - -SRCS += $(CORE_OBJ) -SRCS += $(COMMON_OBJ) -SRCS += $(BLE_OBJ) -SRCS += $(CLASSIC_OBJ) -SRCS += $(AVDTP_OBJ) -SRCS += $(SBC_DECODER_OBJ) -SRCS += $(SBC_ENCODER_OBJ) -SRCS += $(CVSD_PLC_OBJ) -SRCS += $(HXCMOD_PLAYER_OBJ) -SRCS += $(HFP_OBJ) -SRCS += hsp_hs.o hsp_ag.o -SRCS += obex_parser.o goep_client.o pbap_client.o md5.o yxml.o -SRCS += pan.c bnep.c bnep_lwip.c -SRCS += ${LWIP_SRC} - -# Enable assertion checking for development -PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE - -# Use this variables to specify and alternate tool path -#TOOL_DIR=/opt/gcc-arm-none-eabi-4_8-2013q4/bin - -# Use these variables to add project specific tool options -#PROJ_CFLAGS+=--specs=nano.specs -#PROJ_LDFLAGS+=--specs=nano.specs - -# Point this variable to a startup file to override the default file -#STARTUPFILE=start.S - -# Point this variable to a linker file to override the default file -# LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld - -%.h: %.gatt - python3 ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@ - -all: spp_and_le_streamer.h - -# Include the peripheral driver -PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET_UC)PeriphDriver -include $(PERIPH_DRIVER_DIR)/periphdriver.mk - -################################################################################ -# Include the rules for building for this target. All other makefiles should be -# included before this one. -include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk - -# fetch and convert init scripts -# use bluetooth_init_cc2564B_1.8_BT_Spec_4.1.c -include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc - -rm-compiled-gatt-file: - rm -f spp_and_le_counter.h - -clean: rm-compiled-gatt-file - -# The rule to clean out all the build products. -distclean: clean - $(MAKE) -C ${PERIPH_DRIVER_DIR} clean diff --git a/port/max32630-fthr/example/template/ProjectTemplate.mk b/port/max32630-fthr/example/template/ProjectTemplate.mk new file mode 100644 index 0000000000..be24d5079d --- /dev/null +++ b/port/max32630-fthr/example/template/ProjectTemplate.mk @@ -0,0 +1,155 @@ +################################################################################ + # Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + # Ismail H. Kose + # Permission is hereby granted, free of charge, to any person obtaining a + # copy of this software and associated documentation files (the "Software"), + # to deal in the Software without restriction, including without limitation + # the rights to use, copy, modify, merge, publish, distribute, sublicense, + # and/or sell copies of the Software, and to permit persons to whom the + # Software is furnished to do so, subject to the following conditions: + # + # The above copyright notice and this permission notice shall be included + # in all copies or substantial portions of the Software. + # + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + # IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + # OTHER DEALINGS IN THE SOFTWARE. + # + # Except as contained in this notice, the name of Maxim Integrated + # Products, Inc. shall not be used except as stated in the Maxim Integrated + # Products, Inc. Branding Policy. + # + # The mere transfer of this software does not imply any licenses + # of trade secrets, proprietary technology, copyrights, patents, + # trademarks, maskwork rights, or any other form of intellectual + # property whatsoever. Maxim Integrated Products, Inc. retains all + # ownership rights. + # + # $Date: 2016-03-23 13:28:53 -0700 (Wed, 23 Mar 2016) $ + # $Revision: 22067 $ + # + ############################################################################### + +# Maxim ARM Toolchain and Libraries +# https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630.html + +# This is the name of the build output file +PROJECT=inject_project + +# Specify the target processor +TARGET=MAX3263x +PORT_NAME=max32630-fthr +PROJ_CFLAGS+=-DRO_FREQ=96000000 + +# Create Target name variables +TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z) +TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z) + +# Select 'GCC' or 'IAR' compiler +COMPILER=GCC +PYTHON=python + +cc256x_init_script=bluetooth_init_cc2564B_1.8_BT_Spec_4.1.c + +ifeq "$(MAXIM_PATH)" "" +LIBS_DIR=$(realpath /$(subst \,/,$(subst :,,$(HOME))/Maxim/Firmware/$(TARGET_UC)/Libraries)) +$(warning "MAXIM_PATH need to be set. Please run setenv bash file in the Maxim Toolchain directory.") +else +LIBS_DIR=$(realpath /$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries)) +endif + +CMSIS_ROOT=$(LIBS_DIR)/CMSIS + +# BTstack +BTSTACK_ROOT ?= ../../../.. +BTSTACK_ROOT := $(realpath /$(subst \,/,$(subst :,,$(BTSTACK_ROOT)))) +PORT_DIR = ${BTSTACK_ROOT}/port/${PORT_NAME} + +# Where to find source and header files for this test +VPATH = . ${PORT_DIR}/src +IPATH = . ${PORT_DIR}/src + +# Source files for this test +SRCS = $(wildcard $(PORT_DIR)/src/*.c) + +# Board files for the max32630fthr board +# are not present in $(LIBS_DIR)/Boards/ +# The port mimics the structure of EvKit_V1 in the $(LIBS_DIR)/Boards/EvKit_V1 +BOARD_DIR ?= ${PORT_DIR}/board/max32630-fthr +include ${BOARD_DIR}/board.mk + +# Enable assertion checking for development +PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE + +# Project specific makefile (/xxx.mk) +# - defines btstack deps (PROJECT_FEATURES) +# - defines local sources (extend IPATH, VPATH, and SRCS) +include $(wildcard *.mk) +include ${PORT_DIR}/example/template/Dependencies.mk + +ifeq ($($(PROJECT)_deps),) + $(error $(PROJECT)_deps None) +endif + +PROJECT_DEPS = $($(PROJECT)_deps) +PROJECT_OBJS = $(PROJECT_DEPS:.c=.o) + +SRCS += $(PROJECT_OBJS) +SRCS += $(PROJECT_DEPS) + +#define gatt_h dependency before the target defining .mk include +all: inject_gatt_h + +# Use this variables to specify and alternate tool path +#TOOL_DIR=/opt/gcc-arm-none-eabi-4_8-2013q4/bin + +# Use these variables to add project specific tool options +#PROJ_CFLAGS+=--specs=nano.specs +#PROJ_LDFLAGS+=--specs=nano.specs + +# Point this variable to a startup file to override the default file +#STARTUPFILE=start.S + +# Point this variable to a linker file to override the default file +# LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld + +# Include the peripheral driver +PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET_UC)PeriphDriver +include $(PERIPH_DRIVER_DIR)/periphdriver.mk + +################################################################################ +# Include the rules for building for this target. All other makefiles should be +# included before this one. +include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk + +EXAMPLE_BIN_DIR ?= ../bin + +# Remove if you dont need to create and copy bin +all: bin + +%.h: %.gatt + $(PYTHON) ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@ + +# Build and copy all $(PROJECT).bin to EXAMPLE_BIN_DIR +bin: $(BUILD_DIR)/$(PROJECT).bin + $(info Copying $(PROJECT).bin to EXAMPLE_BIN_DIR: $(EXAMPLE_BIN_DIR)) + @mkdir -p $(EXAMPLE_BIN_DIR) + @cp $(BUILD_DIR)/$(PROJECT).bin $(EXAMPLE_BIN_DIR) + +rm-bin: + rm -f $(EXAMPLE_BIN_DIR)/$(PROJECT).bin + +rm-cc256x_init_script: + $(MAKE) -f ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc BTSTACK_ROOT=${BTSTACK_ROOT} clean-scripts + +rm-compiled-gatt-file: + +clean: rm-compiled-gatt-file rm-cc256x_init_script rm-bin + +# The rule to clean out all the build products. +distclean: clean + $(MAKE) -C ${PERIPH_DRIVER_DIR} clean diff --git a/port/max32630-fthr/scripts/create_examples.py b/port/max32630-fthr/scripts/create_examples.py index 55dd5fa141..e3095e79c6 100755 --- a/port/max32630-fthr/scripts/create_examples.py +++ b/port/max32630-fthr/scripts/create_examples.py @@ -8,51 +8,64 @@ import subprocess import sys +from create_project_makefile import createProjectMakefile + # build all template build_all = ''' SUBDIRS = \\ %s +include template/Categories.mk + all: -\techo Building all examples +\t@echo Building all examples \tfor dir in $(SUBDIRS); do \\ -\t$(MAKE) -C $$dir || exit 1; \\ +\t\t$(MAKE) -C $$dir || exit 1; \\ +\tdone + +general: +\t@echo Building general examples +\tfor dir in $(EXAMPLES_GENERAL); do \\ +\t\t$(MAKE) -C $$dir || exit 1; \\ +\tdone + +classic: +\t@echo Building classic examples +\tfor dir in $(EXAMPLES_CLASSIC_ONLY); do \\ +\t\t$(MAKE) -C $$dir || exit 1; \\ +\tdone + +ble: +\t@echo Building ble examples +\tfor dir in $(EXAMPLES_LE_ONLY); do \\ +\t\t$(MAKE) -C $$dir || exit 1; \\ +\tdone + +dual: +\t@echo Building dual examples +\tfor dir in $(EXAMPLES_DUAL_MODE); do \\ +\t\t$(MAKE) -C $$dir || exit 1; \\ \tdone clean: -\techo Cleaning all ports +\t@echo Cleaning all examples \tfor dir in $(SUBDIRS); do \\ -\t$(MAKE) -C $$dir clean; \\ +\t\t$(MAKE) -C $$dir clean; \\ \tdone ''' # get script path -script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../' - +print(os.path.dirname(sys.argv[0])) +script_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..')) +print(script_path) # get btstack root -btstack_root = script_path + '../../' - -## pick correct init script based on your hardware -# - init script for CC2564B -cc256x_init_script = 'bluetooth_init_cc2564B_1.8_BT_Spec_4.1.c' - -subprocess.call("make -f ../Makefile -C src " + cc256x_init_script, shell=True) - -# fetch init script -# print("Creating init script %s" % cc256x_init_script) -# make_template = 'make -f {BTSTACK_ROOT}chipset/cc256x/Makefile.inc -C {SCRIPT_PATH}src/ {INIT_SCRIPT} BTSTACK_ROOT={BTSTACK_ROOT}' -# make_command = make_template.format(BTSTACK_ROOT=btstack_root, SCRIPT_PATH=script_path, INIT_SCRIPT=cc256x_init_script) -# print(make_command) -# subprocess.call(make_command) - +btstack_root = os.path.abspath(os.path.join(script_path, '../..')) +print(btstack_root) # path to examples -examples_embedded = btstack_root + 'example/' +examples_embedded = os.path.join(btstack_root, 'example') # path to generated example projects -projects_path = script_path + "example/" - -# path to template -template_path = script_path + 'example/template/Makefile' +projects_path = os.path.join(script_path, "example") print("Creating example projects:") @@ -64,38 +77,28 @@ for file in example_files: if not file.endswith(".c"): continue - if file in ['panu_demo.c', 'sco_demo_util.c', 'ant_test.c']: + if file in ['panu_demo.c', 'sco_demo_util.c', 'ant_test.c', 'mesh_node_demo.c']: + continue + if file.startswith('le_audio_demo'): continue + example = file[:-2] examples.append(example) # create folder - project_folder = projects_path + example + "/" + project_folder = os.path.join(projects_path, example) if not os.path.exists(project_folder): os.makedirs(project_folder) # check if .gatt file is present - gatt_path = examples_embedded + example + ".gatt" + gatt_path = os.path.join(examples_embedded, example + ".gatt") gatt_h = "" if os.path.exists(gatt_path): - gatt_h = example+'.h' - - # create makefile - with open(project_folder + 'Makefile', 'wt') as fout: - with open(template_path, 'rt') as fin: - for line in fin: - if 'PROJECT=spp_and_le_streamer' in line: - fout.write('PROJECT=%s\n' % example) - continue - if 'all: spp_and_le_streamer.h' in line: - if len(gatt_h): - fout.write("all: %s\n" % gatt_h) - continue - fout.write(line) - - print("- %s" % example) - -with open(projects_path+'Makefile', 'wt') as fout: + gatt_h = example + '.h' + + createProjectMakefile(project_folder, btstack_root, gatt_h) + +with open(os.path.join(projects_path, 'Makefile'), 'wt') as fout: fout.write(build_all % ' \\\n'.join(examples)) print("Projects are ready for compile in example folder. See README for details.") diff --git a/port/max32630-fthr/scripts/create_project_makefile.py b/port/max32630-fthr/scripts/create_project_makefile.py new file mode 100644 index 0000000000..ccf0e4fc0c --- /dev/null +++ b/port/max32630-fthr/scripts/create_project_makefile.py @@ -0,0 +1,43 @@ +import os +import re +import shutil +import subprocess +import sys + +def createProjectMakefile(project_path, btstack_root, gatt_h = ""): + # path to template + template_path = os.path.join(btstack_root, 'port/max32630-fthr/' ,'example/template/ProjectTemplate.mk') + example = os.path.basename(project_path.strip("/")) + print(f"project - {example}") + example_files = os.listdir(project_path) + # check if .gatt file is present + if not len(gatt_h): + for file in example_files: + if not file.endswith(".gatt"): + continue + gatt_h = file[:-4] + "h" + break + + if (len(gatt_h)): + print(".. gatt - " + gatt_h) + + # create makefile + with open(os.path.join(project_path, 'Makefile'), 'wt') as fout: + with open(template_path, 'rt') as fin: + for line in fin: + if line.startswith('BTSTACK_ROOT ?='): + fout.write('BTSTACK_ROOT ?= %s\n' % btstack_root) + continue + if 'PROJECT=inject_project' in line: + fout.write('PROJECT=%s\n' % example) + continue + if 'all: inject_gatt_h' in line: + if len(gatt_h): + fout.write("all: %s\n" % gatt_h) + continue + if 'rm-compiled-gatt-file:' in line: + if len(gatt_h): + fout.write(line) + fout.write("\trm -f %s\n" % gatt_h) + continue + fout.write(line) diff --git a/port/max32630-fthr/scripts/setenv.bat b/port/max32630-fthr/scripts/setenv.bat new file mode 100644 index 0000000000..82cc508800 --- /dev/null +++ b/port/max32630-fthr/scripts/setenv.bat @@ -0,0 +1,47 @@ +@echo off +rem Setting windows build environment for max32630-fthr using Maxim SDK tools +rem [ARMCortexToolchain.exe](https://download.analog.com/sds/exclusive/SFW0001500A/ARMCortexToolchain.exe). +rem Note! +rem Initial(pro) version absolutely no sanity checks for the paths. + +set MAXIM_PATH=C:\Maxim + +echo. +echo Input MAXIM_PATH=(%MAXIM_PATH%) +set "maxim=" +set /P maxim=": " +if defined maxim set "MAXIM_PATH=%maxim%" +echo Selected MAXIM_PATH=(%MAXIM_PATH%) +echo. + +set TOOLCHAIN_PATH=%MAXIM_PATH%\Toolchain +echo Input TOOLCHAIN_PATH=(%TOOLCHAIN_PATH%) +set "toolchain=" +set /P toolchain=": " +if defined toolchain set "TOOLCHAIN_PATH=%toolchain%" +echo Selected TOOLCHAIN_PATH=(%TOOLCHAIN_PATH%) +echo. + +set MSYS_PATH=%TOOLCHAIN_PATH%\msys\1.0 +echo Input MSYS_PATH=(%MSYS_PATH%) +set "msys=" +set /P msys=": " +if defined msys set "MSYS_PATH=%msys%" +echo Selected MSYS_PATH=(%MSYS_PATH%) +echo. + +echo Current PATH=%PATH% +echo. + +echo Prepend path with %TOOLCHAIN_PATH%\bin;%MSYS_PATH%\bin;" +set /p var="Continue?[Y/(N)]: " +if "%var%"== "" goto :EOF +if %var%== Y goto prepend +if %var%== y goto prepend +else goto :EOF + +:prepend +set ORIG_PATH=%PATH% +set PATH=%TOOLCHAIN_PATH%\bin;%MSYS_PATH%\bin;%PATH% +echo %PATH% +echo. diff --git a/port/max32630-fthr/src/btstack_config.h b/port/max32630-fthr/src/btstack_config.h index 60a7fe393d..6b6c902bb8 100644 --- a/port/max32630-fthr/src/btstack_config.h +++ b/port/max32630-fthr/src/btstack_config.h @@ -15,6 +15,7 @@ #define ENABLE_CLASSIC #define ENABLE_LE_CENTRAL #define ENABLE_L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE +#define ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS #define ENABLE_LOG_ERROR diff --git a/port/max32630-fthr/src/btstack_port.c b/port/max32630-fthr/src/btstack_port.c index 95c4e2e5aa..69b9f78717 100644 --- a/port/max32630-fthr/src/btstack_port.c +++ b/port/max32630-fthr/src/btstack_port.c @@ -285,14 +285,6 @@ int bt_comm_init() { return 0; } -static hci_transport_config_uart_t config = { - HCI_TRANSPORT_CONFIG_UART, - 115200, - 4000000, - 1, // flow control - "max32630fthr", - }; - // hal_led.h implementation #include "hal_led.h" void hal_led_off(void){ @@ -390,26 +382,26 @@ void btstack_stdin_setup(void (*handler)(char c)){ #include "btstack_link_key_db_tlv.h" #include "le_device_db_tlv.h" +#if defined(ENABLE_HCI_INIT) + +static hci_transport_config_uart_t config = { + HCI_TRANSPORT_CONFIG_UART, + 115200, + 4000000, + 1, // flow control + "max32630fthr", +}; + #define HAL_FLASH_BANK_SIZE 0x2000 #define HAL_FLASH_BANK_0_ADDR 0x1FC000 #define HAL_FLASH_BANK_1_ADDR 0x1FE000 static hal_flash_bank_mxc_t hal_flash_bank_context; static btstack_tlv_flash_bank_t btstack_tlv_flash_bank_context; - - -/******************************************************************************/ -int bluetooth_main(void) +#endif +static void _hci_init() { - LED_Off(LED_GREEN); - LED_On(LED_RED); - LED_Off(LED_BLUE); - - bt_comm_init(); - /* BT Stack Initialization */ - btstack_memory_init(); - btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); - +#if defined(ENABLE_HCI_INIT) // enable packet logger // hci_dump_init(hci_dump_embedded_stdout_get_instance()); @@ -435,6 +427,23 @@ int bluetooth_main(void) // setup LE Device DB using TLV le_device_db_tlv_configure(btstack_tlv_impl, &btstack_tlv_flash_bank_context); +#endif +} + + +/******************************************************************************/ +int bluetooth_main(void) +{ + LED_Off(LED_GREEN); + LED_On(LED_RED); + LED_Off(LED_BLUE); + + bt_comm_init(); + /* BT Stack Initialization */ + btstack_memory_init(); + btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); + + _hci_init(); // go btstack_main(0, (void *)NULL);