2015-06-06 23:42:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 Daniel Campora
|
|
|
|
*
|
|
|
|
* 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 THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "mpconfigboard.h"
|
|
|
|
#include "inc/hw_types.h"
|
|
|
|
#include "inc/hw_gpio.h"
|
|
|
|
#include "inc/hw_ints.h"
|
|
|
|
#include "inc/hw_memmap.h"
|
|
|
|
#include "rom_map.h"
|
|
|
|
#include "pin.h"
|
|
|
|
#include "prcm.h"
|
|
|
|
#include "gpio.h"
|
|
|
|
#include "antenna.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if MICROPY_HW_ANTENNA_DIVERSITY
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
DEFINE CONSTANTS
|
|
|
|
******************************************************************************/
|
|
|
|
#define REG_PAD_CONFIG_26 (0x4402E108)
|
|
|
|
#define REG_PAD_CONFIG_27 (0x4402E10C)
|
|
|
|
|
2015-06-07 12:28:47 +01:00
|
|
|
/******************************************************************************
|
|
|
|
DEFINE PRIVATE DATA
|
|
|
|
******************************************************************************/
|
|
|
|
static antenna_type_t antenna_type_selected = ANTENNA_TYPE_INTERNAL;
|
|
|
|
|
2015-06-06 23:42:40 +01:00
|
|
|
/******************************************************************************
|
|
|
|
DEFINE PUBLIC FUNCTIONS
|
|
|
|
******************************************************************************/
|
|
|
|
void antenna_init0(void) {
|
2015-06-10 11:41:29 +01:00
|
|
|
// enable the peripheral clock and set the gpio direction for
|
|
|
|
// both antenna 1 and antenna 2 pins
|
|
|
|
MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
2015-06-06 23:42:40 +01:00
|
|
|
MAP_GPIODirModeSet(GPIOA3_BASE, 0x0C, GPIO_DIR_MODE_OUT);
|
|
|
|
|
2015-06-10 11:41:29 +01:00
|
|
|
// configure antenna 1 pin type and strength
|
|
|
|
HWREG(REG_PAD_CONFIG_26) = ((HWREG(REG_PAD_CONFIG_26) & ~(PAD_STRENGTH_MASK | PAD_TYPE_MASK)) | (0x00000020 | 0x00000000));
|
2015-06-06 23:42:40 +01:00
|
|
|
// set the mode
|
2015-06-10 11:41:29 +01:00
|
|
|
HWREG(REG_PAD_CONFIG_26) = ((HWREG(REG_PAD_CONFIG_26) & ~PAD_MODE_MASK) | 0x00000000) & ~(3 << 10);
|
2015-06-06 23:42:40 +01:00
|
|
|
// set the direction
|
|
|
|
HWREG(REG_PAD_CONFIG_26) = ((HWREG(REG_PAD_CONFIG_26) & ~0xC00) | 0x00000800);
|
|
|
|
|
2015-06-10 11:41:29 +01:00
|
|
|
// configure antenna 2 pin type and strength
|
|
|
|
HWREG(REG_PAD_CONFIG_27) = ((HWREG(REG_PAD_CONFIG_27) & ~(PAD_STRENGTH_MASK | PAD_TYPE_MASK)) | (0x00000020 | 0x00000000));
|
2015-06-06 23:42:40 +01:00
|
|
|
// set the mode
|
2015-06-10 11:41:29 +01:00
|
|
|
HWREG(REG_PAD_CONFIG_27) = ((HWREG(REG_PAD_CONFIG_27) & ~PAD_MODE_MASK) | 0x00000000) & ~(3 << 10);
|
2015-06-06 23:42:40 +01:00
|
|
|
// set the direction
|
2015-06-10 11:41:29 +01:00
|
|
|
HWREG(REG_PAD_CONFIG_27) = ((HWREG(REG_PAD_CONFIG_27) & ~0xC00) | 0x00000800);
|
2015-06-07 12:28:47 +01:00
|
|
|
|
|
|
|
// select the currently active antenna
|
|
|
|
antenna_select(antenna_type_selected);
|
2015-06-06 23:42:40 +01:00
|
|
|
}
|
|
|
|
|
2015-06-07 12:28:47 +01:00
|
|
|
void antenna_select (antenna_type_t _antenna) {
|
|
|
|
if (_antenna == ANTENNA_TYPE_INTERNAL) {
|
2015-06-06 23:42:40 +01:00
|
|
|
MAP_GPIOPinWrite(GPIOA3_BASE, 0x0C, 0x04);
|
2015-06-10 11:41:29 +01:00
|
|
|
// also configure the pull-up and pull-down accordingly
|
|
|
|
HWREG(REG_PAD_CONFIG_26) = ((HWREG(REG_PAD_CONFIG_26) & ~PAD_TYPE_MASK)) | PIN_TYPE_STD_PU;
|
|
|
|
HWREG(REG_PAD_CONFIG_27) = ((HWREG(REG_PAD_CONFIG_27) & ~PAD_TYPE_MASK)) | PIN_TYPE_STD_PD;
|
2015-06-06 23:42:40 +01:00
|
|
|
} else {
|
|
|
|
MAP_GPIOPinWrite(GPIOA3_BASE, 0x0C, 0x08);
|
2015-06-10 11:41:29 +01:00
|
|
|
// also configure the pull-up and pull-down accordingly
|
|
|
|
HWREG(REG_PAD_CONFIG_26) = ((HWREG(REG_PAD_CONFIG_26) & ~PAD_TYPE_MASK)) | PIN_TYPE_STD_PD;
|
|
|
|
HWREG(REG_PAD_CONFIG_27) = ((HWREG(REG_PAD_CONFIG_27) & ~PAD_TYPE_MASK)) | PIN_TYPE_STD_PU;
|
2015-06-06 23:42:40 +01:00
|
|
|
}
|
2015-06-07 12:28:47 +01:00
|
|
|
antenna_type_selected = _antenna;
|
2015-06-06 23:42:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|