Changeset - 02d3447dac18
[Not reviewed]
default
0 4 0
Ethan Zonca (ethanzonca) - 9 years ago 2017-01-12 09:21:40
e@ethanzonca.com
Add docs, remove startup delays
4 files changed with 73 insertions and 18 deletions:
0 comments (0 inline, 0 general)
Libraries/Si446x/si446x.c
Show inline comments
 
//
 
// Si446x: Initializes and configures a Si446x transceiver over SPI
 
//
 
/*
 
 * FeatherHAB
 
 *
 
 * This file is part of FeatherHAB.
 
 *
 
 * FeatherHab is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * FeatherHab is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with FeatherHAB. If not, see <http://www.gnu.org/licenses/>.
 
 *
 
 * Ethan Zonca
 
 *
 
 */
 
 
#include "stm32f0xx_hal.h"
 
 
#include "si446x.h"
 
#include "config.h"
 
#include "error.h"
 
#include "system/gpio.h"
 
#include "system/sysclk.h"
 
 
 
// Private variables
 
static SPI_HandleTypeDef hspi1;
 
static uint8_t si446x_cw_status = 0;
 
 
 
// Private function prototypes
 
static void __init_spi1(void);
 
 
 
// Initialize Si446x in 2FSK transmit mode
 
void si446x_init(void)
 
{
 
	// init spi port
 
	__init_spi1();
 
 
	GPIO_InitTypeDef GPIO_InitStruct;
 
 
	// GPIO: TCXO control
 
	GPIO_InitStruct.Pin = SI446x_TCXO_EN_PIN;
 
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
	GPIO_InitStruct.Pull = GPIO_NOPULL;
 
	HAL_GPIO_Init(SI446x_TCXO_EN_PORT, &GPIO_InitStruct);
 
	HAL_GPIO_WritePin(SI446x_TCXO_EN_PORT, SI446x_TCXO_EN_PIN, 1);
 
 
	// GPIO: VHF radio shutdown control
 
	GPIO_InitStruct.Pin = SI446x_SHUTDOWN_PIN;
 
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
	GPIO_InitStruct.Pull = GPIO_NOPULL;
 
	HAL_GPIO_Init(SI446x_SHUTDOWN_PORT, &GPIO_InitStruct);
 
 
	// Perform PoR (takes 20ms) and turn device on
 
	si446x_reset();
 
	si446x_reset();
 
 
    // Divide SI446x_VCXO_FREQ into its bytes; MSB first
 
    uint16_t x3 = SI446x_VCXO_FREQ / 0x1000000;
 
    uint16_t x2 = (SI446x_VCXO_FREQ - x3 * 0x1000000) / 0x10000;
 
    uint16_t x1 = (SI446x_VCXO_FREQ - x3 * 0x1000000 - x2 * 0x10000) / 0x100;
Source/main.c
Show inline comments
 
//
 
// mBuoy Depth Select Firmware
 
// Copyright 2015 SeaLandAire Technologies
 
//
 
/*
 
 * FeatherHAB
 
 *
 
 * This file is part of FeatherHAB.
 
 *
 
 * FeatherHab is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * FeatherHab is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with FeatherHAB. If not, see <http://www.gnu.org/licenses/>.
 
 *
 
 * Ethan Zonca
 
 *
 
 */
 
 
#include "stm32f0xx_hal.h"
 
 
#include "config.h"
 
#include "error.h"
 
#include "pressure.h"
 
#include "gps.h"
 
 
#include "system/gpio.h"
 
#include "system/sysclk.h"
 
#include "system/watchdog.h"
 
#include "system/uart.h"
 
#include "system/adc.h"
 
#include "stm32f0xx_hal.h"
 
 
#include "si446x/si446x.h"
 
#include "aprs/aprs.h"
 
#include "aprs/afsk.h"
 
#include "pressure.h"
 
#include "gps.h"
 
 
 
int main(void)
 
{
 
  hal_init();
 
  sysclock_init();
 
  gpio_init();
 
 
  HAL_Delay(100);
 
 
  adc_init();
 
 
  afsk_init();
 
  si446x_init();
 
  si446x_init();
 
 
  HAL_Delay(100);
 
 
  gps_poweron();
 
  HAL_Delay(100);
 
 
  pressure_init();
 
 
  // Software timers
 
  uint32_t last_transmission = HAL_GetTick();
 
  uint32_t last_led = HAL_GetTick();
 
 
  while (1)
 
  {
 
	  // Blink LEDs
 
	  if(HAL_GetTick() - last_transmission > 700)
 
	  {
 
		  gps_update_data(); // Will always return at 1hz rate (default measurement rate)
 
		  pressure_read();
 
		  aprs_send();
 
		  //while(afsk_busy());
 
 
		  last_transmission = HAL_GetTick();
 
	  }
 
 
	  if(HAL_GetTick() - last_led > 100)
 
	  {
 
		  HAL_GPIO_TogglePin(LED_POWER);
 
		  last_led = HAL_GetTick();
 
	  }
 
 
	  if(afsk_request_cwoff())
 
		  si446x_cw_off();
 
 
	  // High-frequency function calls
 
//	  watchdog_feed();
 
  }
 
}
 
Source/system/gpio.c
Show inline comments
 
//
 
// GPIO: Configure and initialize GPIOs
 
//
 
/*
 
 * FeatherHAB
 
 *
 
 * This file is part of FeatherHAB.
 
 *
 
 * FeatherHab is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * FeatherHab is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with FeatherHAB. If not, see <http://www.gnu.org/licenses/>.
 
 *
 
 * Ethan Zonca
 
 *
 
 */
 
 
#include "config.h"
 
#include "system/gpio.h"
 
#include "stm32f0xx_hal.h"
 
 
 
// Private variables
 
static uint8_t shutdown_triggered = 0;
 
static uint32_t shutdown_triggered_time = 0;
 
 
 
// Initialize GPIOs
 
void gpio_init(void)
 
{
 
  GPIO_InitTypeDef GPIO_InitStruct;
 
 
  // Enable clocks
 
  __GPIOC_CLK_ENABLE();
 
  __GPIOF_CLK_ENABLE();
 
  __GPIOA_CLK_ENABLE();
 
  __GPIOB_CLK_ENABLE();
 
 
  // LEDs 1/2
 
  GPIO_InitStruct.Pin = PIN_LED_POWER;
 
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
  GPIO_InitStruct.Pull = GPIO_NOPULL;
 
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
 
  HAL_GPIO_Init(PORT_LED_POWER, &GPIO_InitStruct);
 
 
  GPIO_InitStruct.Pin = GPS_NOTEN_PIN;
 
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
  GPIO_InitStruct.Pull = GPIO_NOPULL;
 
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
 
  HAL_GPIO_Init(GPS_NOTEN_PORT, &GPIO_InitStruct);
 
  HAL_GPIO_WritePin(GPS_NOTEN, 1); // yes, keep the chip disabled
 
 
 
  // Toggle the power LED
 
  HAL_GPIO_TogglePin(LED_POWER);
 
}
Source/system/uart.c
Show inline comments
 
//
 
// uart: configure and initialize GPS uart
 
//
 
 
#include "stm32f0xx_hal.h"
 
 
#include "system/uart.h"
 
#include "config.h"
 
#include "system/gpio.h"
 
 
UART_HandleTypeDef huart1;
 
DMA_HandleTypeDef hdma_usart1_rx;
 
DMA_HandleTypeDef hdma_usart1_tx;
 
uint8_t uart_initted = 0;
 
 
void uart_init(void)
 
{
 
    __GPIOB_CLK_ENABLE();
 
    __USART1_CLK_ENABLE();
 
 
    GPIO_InitTypeDef GPIO_InitStruct;
 
 
    // Init gpio pins for uart
 
    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
 
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 
    GPIO_InitStruct.Pull = GPIO_NOPULL; //GPIO_PULLUP;
 
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
 
    GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
 
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 
    // Init UART periph
 
    huart1.Instance = USART1;
 
    huart1.Init.BaudRate = 9600;
 
    huart1.Init.WordLength = UART_WORDLENGTH_8B;
 
    huart1.Init.StopBits = UART_STOPBITS_1;
 
    huart1.Init.Parity = UART_PARITY_NONE;
 
    huart1.Init.Mode = UART_MODE_TX_RX;
 
    huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 
    huart1.Init.OverSampling = UART_OVERSAMPLING_16;
 
    //huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
 
    huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT|UART_ADVFEATURE_DMADISABLEONERROR_INIT;
 
    huart1.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
 
    huart1.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;
 
    HAL_UART_Init(&huart1);
 
 
    HAL_Delay(100);
 
	uint8_t switch_baud[] = "$PUBX,41,1,0003,0001,115200,0*1E\r\n";
 
	HAL_UART_Transmit(uart_gethandle(), switch_baud, sizeof(switch_baud)/sizeof(uint8_t), 1000);
 
 
    HAL_UART_DeInit(&huart1);
 
    huart1.Init.BaudRate = 115200;
 
    HAL_UART_Init(&huart1);
0 comments (0 inline, 0 general)