Pretty big improvements to bitmap drawing code, and waterfall display code. Also a hack to deal with the red-things-stay-red bug (it's not ideal, it just blocks the encoder tick() if the display is drawing, doesn't seem to effect the feel of the interface in a bad way. Beginning to include GPS support. Working on some other display speedups (DMA and 16bit transfers, both are currently disabled)
This commit is contained in:
parent
f694e53e46
commit
46c832e409
Binary file not shown.
Binary file not shown.
|
@ -181,6 +181,7 @@
|
|||
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.1712731893" name="Resource Custom Build Step Output Type"/>
|
||||
</tool>
|
||||
</fileInfo>
|
||||
<fileInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.2032041769" name="uart.h" rcbsApplicability="disable" resourcePath="include/uart.h" toolsToInvoke=""/>
|
||||
<fileInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.138531628" name="stm32f415xx.h" rcbsApplicability="disable" resourcePath="system/include/cmsis/stm32f415xx.h" toolsToInvoke=""/>
|
||||
<fileInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.556398614" name="stm32f439xx.h" rcbsApplicability="disable" resourcePath="system/include/cmsis/stm32f439xx.h" toolsToInvoke=""/>
|
||||
<fileInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.1980029090" name="stm32f407xx.h" rcbsApplicability="disable" resourcePath="system/include/cmsis/stm32f407xx.h" toolsToInvoke=""/>
|
||||
|
@ -205,6 +206,9 @@
|
|||
<fileInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.1528905043" name="stm32f417xx.h" rcbsApplicability="disable" resourcePath="system/include/cmsis/stm32f417xx.h" toolsToInvoke=""/>
|
||||
<fileInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.708018723" name="stm32f437xx.h" rcbsApplicability="disable" resourcePath="system/include/cmsis/stm32f437xx.h" toolsToInvoke=""/>
|
||||
<fileInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.1431321268" name="stm32f427xx.h" rcbsApplicability="disable" resourcePath="system/include/cmsis/stm32f427xx.h" toolsToInvoke=""/>
|
||||
<fileInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.1883550001" name="uart.c" rcbsApplicability="disable" resourcePath="src/uart.c" toolsToInvoke="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.98059731.1625589465">
|
||||
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.98059731.1625589465" name="Cross ARM C Compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.98059731"/>
|
||||
</fileInfo>
|
||||
<folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298.608015733" name="/" resourcePath="DSP_Lib">
|
||||
<toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug.425450735" name="Cross ARM GCC" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug" unusedChildren="">
|
||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.1067485307.697494564" name="Optimization Level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.1067485307"/>
|
||||
|
@ -785,9 +789,9 @@
|
|||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="Source/TransformFunctions/arm_cfft_radix2_q31.c|Source/TransformFunctions/arm_cfft_radix2_q15.c|Source/TransformFunctions/arm_cfft_radix2_init_q31.c|Source/TransformFunctions/arm_cfft_radix2_init_q15.c|Source/TransformFunctions/arm_cfft_radix2_init_f32.c|Source/TransformFunctions/arm_cfft_radix2_f32.c|Source/FilteringFunctions|Source/ControllerFunctions|Source/MatrixFunctions|Source/StatisticsFunctions|Source/SupportFunctions" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="DSP_Lib"/>
|
||||
<entry excluding="ILI9341_t3.h" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/>
|
||||
<entry excluding="ILI9341_t3.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
|
||||
<entry excluding="include/cmsis/stm32f439xx.h|include/cmsis/stm32f437xx.h|include/cmsis/stm32f427xx.h|include/cmsis/stm32f417xx.h|include/cmsis/stm32f415xx.h|include/cmsis/stm32f407xx.h|include/cmsis/stm32f405xx.h|include/cmsis/stm32f401xe.h|include/cmsis/stm32f401xc.h|src/stm32f4-hal/stm32f4xx_hal_adc_ex.c|src/stm32f4-hal/stm32f4xx_hal_can.c|src/stm32f4-hal/stm32f4xx_hal_crc.c|src/stm32f4-hal/stm32f4xx_hal_cryp.c|src/stm32f4-hal/stm32f4xx_hal_cryp_ex.c|src/stm32f4-hal/stm32f4xx_hal_dac_ex.c|src/stm32f4-hal/stm32f4xx_hal_dcmi.c|src/stm32f4-hal/stm32f4xx_hal_dma2d.c|src/stm32f4-hal/stm32f4xx_hal_dma_ex.c|src/stm32f4-hal/stm32f4xx_hal_eth.c|src/stm32f4-hal/stm32f4xx_hal_hash.c|src/stm32f4-hal/stm32f4xx_hal_hash_ex.c|src/stm32f4-hal/stm32f4xx_hal_hcd.c|src/stm32f4-hal/stm32f4xx_hal_i2c.c|src/stm32f4-hal/stm32f4xx_hal_i2c_ex.c|src/stm32f4-hal/stm32f4xx_hal_i2s.c|src/stm32f4-hal/stm32f4xx_hal_i2s_ex.c|src/stm32f4-hal/stm32f4xx_hal_irda.c|src/stm32f4-hal/stm32f4xx_hal_ltdc.c|src/stm32f4-hal/stm32f4xx_hal_msp_template.c|src/stm32f4-hal/stm32f4xx_hal_nand.c|src/stm32f4-hal/stm32f4xx_hal_nor.c|src/stm32f4-hal/stm32f4xx_hal_pccard.c|src/stm32f4-hal/stm32f4xx_hal_pcd.c|src/stm32f4-hal/stm32f4xx_hal_rng.c|src/stm32f4-hal/stm32f4xx_hal_rtc.c|src/stm32f4-hal/stm32f4xx_hal_rtc_ex.c|src/stm32f4-hal/stm32f4xx_hal_sai.c|src/stm32f4-hal/stm32f4xx_hal_sd.c|src/stm32f4-hal/stm32f4xx_hal_sdram.c|src/stm32f4-hal/stm32f4xx_hal_smartcard.c|src/stm32f4-hal/stm32f4xx_hal_sram.c|src/stm32f4-hal/stm32f4xx_hal_uart.c|src/stm32f4-hal/stm32f4xx_hal_usart.c|src/stm32f4-hal/stm32f4xx_hal_wwdg.c|src/stm32f4-hal/stm32f4xx_ll_fmc.c|src/stm32f4-hal/stm32f4xx_ll_fsmc.c|src/stm32f4-hal/stm32f4xx_ll_sdmmc.c|src/stm32f4-hal/stm32f4xx_ll_usb.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="system"/>
|
||||
<entry excluding="uart.h|ILI9341_t3.h" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/>
|
||||
<entry excluding="uart.c|ILI9341_t3.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
|
||||
<entry excluding="include/cmsis/stm32f439xx.h|include/cmsis/stm32f437xx.h|include/cmsis/stm32f427xx.h|include/cmsis/stm32f417xx.h|include/cmsis/stm32f415xx.h|include/cmsis/stm32f407xx.h|include/cmsis/stm32f405xx.h|include/cmsis/stm32f401xe.h|include/cmsis/stm32f401xc.h|src/stm32f4-hal/stm32f4xx_hal_adc_ex.c|src/stm32f4-hal/stm32f4xx_hal_can.c|src/stm32f4-hal/stm32f4xx_hal_crc.c|src/stm32f4-hal/stm32f4xx_hal_cryp.c|src/stm32f4-hal/stm32f4xx_hal_cryp_ex.c|src/stm32f4-hal/stm32f4xx_hal_dac_ex.c|src/stm32f4-hal/stm32f4xx_hal_dcmi.c|src/stm32f4-hal/stm32f4xx_hal_dma2d.c|src/stm32f4-hal/stm32f4xx_hal_dma_ex.c|src/stm32f4-hal/stm32f4xx_hal_eth.c|src/stm32f4-hal/stm32f4xx_hal_hash.c|src/stm32f4-hal/stm32f4xx_hal_hash_ex.c|src/stm32f4-hal/stm32f4xx_hal_hcd.c|src/stm32f4-hal/stm32f4xx_hal_i2c.c|src/stm32f4-hal/stm32f4xx_hal_i2c_ex.c|src/stm32f4-hal/stm32f4xx_hal_i2s.c|src/stm32f4-hal/stm32f4xx_hal_i2s_ex.c|src/stm32f4-hal/stm32f4xx_hal_irda.c|src/stm32f4-hal/stm32f4xx_hal_ltdc.c|src/stm32f4-hal/stm32f4xx_hal_msp_template.c|src/stm32f4-hal/stm32f4xx_hal_nand.c|src/stm32f4-hal/stm32f4xx_hal_nor.c|src/stm32f4-hal/stm32f4xx_hal_pccard.c|src/stm32f4-hal/stm32f4xx_hal_pcd.c|src/stm32f4-hal/stm32f4xx_hal_rng.c|src/stm32f4-hal/stm32f4xx_hal_rtc_ex.c|src/stm32f4-hal/stm32f4xx_hal_sai.c|src/stm32f4-hal/stm32f4xx_hal_sd.c|src/stm32f4-hal/stm32f4xx_hal_sdram.c|src/stm32f4-hal/stm32f4xx_hal_smartcard.c|src/stm32f4-hal/stm32f4xx_hal_sram.c|src/stm32f4-hal/stm32f4xx_hal_wwdg.c|src/stm32f4-hal/stm32f4xx_ll_fmc.c|src/stm32f4-hal/stm32f4xx_ll_fsmc.c|src/stm32f4-hal/stm32f4xx_ll_sdmmc.c|src/stm32f4-hal/stm32f4xx_ll_usb.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="system"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
|
|
Binary file not shown.
13644
Source/Debug/PSDR.hex
13644
Source/Debug/PSDR.hex
File diff suppressed because it is too large
Load Diff
|
@ -55,6 +55,8 @@
|
|||
#define ILI9340_RAMWR 0x2C
|
||||
#define ILI9340_RAMRD 0x2E
|
||||
|
||||
#define ILI9340_RAMWRCNT 0x3C
|
||||
|
||||
#define ILI9340_PTLAR 0x30
|
||||
#define ILI9340_MADCTL 0x36
|
||||
|
||||
|
@ -122,6 +124,7 @@
|
|||
Adafruit_ILI9340_pushColor(uint16_t color),
|
||||
Adafruit_ILI9340_fillScreen(uint16_t color),
|
||||
Adafruit_ILI9340_drawPixel(int16_t x, int16_t y, uint16_t color),
|
||||
Adafruit_ILI9340_drawNextPixel(uint16_t color),
|
||||
Adafruit_ILI9340_drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
|
||||
Adafruit_ILI9340_drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
|
||||
Adafruit_ILI9340_fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
||||
|
@ -140,8 +143,8 @@
|
|||
*/
|
||||
|
||||
void Adafruit_ILI9340_spiwrite(uint8_t),
|
||||
Adafruit_ILI9340_writecommand(uint8_t c),
|
||||
Adafruit_ILI9340_writedata(uint8_t d),
|
||||
Adafruit_ILI9340_writecommand(uint16_t c),
|
||||
Adafruit_ILI9340_writedata(uint16_t d),
|
||||
Adafruit_ILI9340_commandList(uint8_t *addr);
|
||||
uint8_t Adafruit_ILI9340_spiread(void);
|
||||
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
TinyGPS - a small GPS library for Arduino providing basic NMEA parsing
|
||||
Based on work by and "distance_to" and "course_to" courtesy of Maarten Lamers.
|
||||
Suggestion to add satellites(), course_to(), and cardinal(), by Matt Monson.
|
||||
Precision improvements suggested by Wayne Holder.
|
||||
Copyright (C) 2008-2013 Mikal Hart
|
||||
All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef TinyGPS_h
|
||||
#define TinyGPS_h
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define _GPS_VERSION 13 // software version of this library
|
||||
#define _GPS_MPH_PER_KNOT 1.15077945
|
||||
#define _GPS_MPS_PER_KNOT 0.51444444
|
||||
#define _GPS_KMPH_PER_KNOT 1.852
|
||||
#define _GPS_MILES_PER_METER 0.00062137112
|
||||
#define _GPS_KM_PER_METER 0.001
|
||||
// #define _GPS_NO_STATS
|
||||
|
||||
//class TinyGPS
|
||||
//{
|
||||
//public:
|
||||
enum {
|
||||
GPS_INVALID_AGE = 0xFFFFFFFF, GPS_INVALID_ANGLE = 999999999,
|
||||
GPS_INVALID_ALTITUDE = 999999999, GPS_INVALID_DATE = 0,
|
||||
GPS_INVALID_TIME = 0xFFFFFFFF, GPS_INVALID_SPEED = 999999999,
|
||||
GPS_INVALID_FIX_TIME = 0xFFFFFFFF, GPS_INVALID_SATELLITES = 0xFF,
|
||||
GPS_INVALID_HDOP = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
static const float GPS_INVALID_F_ANGLE, GPS_INVALID_F_ALTITUDE, GPS_INVALID_F_SPEED;
|
||||
|
||||
void TinyGPS_init();
|
||||
bool TinyGPS_encode(char c); // process one character received from GPS
|
||||
//TinyGPS &operator << (char c) {encode(c); return *this;}
|
||||
|
||||
// lat/long in MILLIONTHs of a degree and age of fix in milliseconds
|
||||
// (note: versions 12 and earlier gave lat/long in 100,000ths of a degree.
|
||||
void TinyGPS_get_position(long *latitude, long *longitude, unsigned long *fix_age); //Used to end: unsigned long *fix_age = 0);
|
||||
|
||||
// date as ddmmyy, time as hhmmsscc, and age in milliseconds
|
||||
void TinyGPS_get_datetime(unsigned long *date, unsigned long *time, unsigned long *age); //Used to end: unsigned long *age = 0);
|
||||
|
||||
// signed altitude in centimeters (from GPGGA sentence)
|
||||
inline long TinyGPS_altitude();
|
||||
|
||||
// course in last full GPRMC sentence in 100th of a degree
|
||||
inline unsigned long TinyGPS_course();
|
||||
|
||||
// speed in last full GPRMC sentence in 100ths of a knot
|
||||
inline unsigned long TinyGPS_speed();
|
||||
|
||||
// satellites used in last full GPGGA sentence
|
||||
inline unsigned short TinyGPS_satellites();
|
||||
|
||||
// horizontal dilution of precision in 100ths
|
||||
inline unsigned long TinyGPS_hdop();
|
||||
|
||||
int TinyGPS_hasFix();
|
||||
|
||||
void TinyGPS_f_get_position(float *latitude, float *longitude, unsigned long *fix_age); //Used to end: unsigned long *fix_age = 0);
|
||||
void TinyGPS_crack_datetime(int *year, unsigned char *month, unsigned char *day, //the unsigned chars were bytes before
|
||||
unsigned char *hour, unsigned char *minute, unsigned char *second, unsigned char *hundredths, unsigned long *fix_age); //Used to end: byte *hundredths = 0, unsigned long *fix_age = 0);
|
||||
float f_altitude();
|
||||
float f_course();
|
||||
float f_speed_knots();
|
||||
float f_speed_mph();
|
||||
float f_speed_mps();
|
||||
float f_speed_kmph();
|
||||
|
||||
int TinyGPS_library_version();
|
||||
|
||||
float TinyGPS_distance_between (long lat1, long long1, long lat2, long long2);
|
||||
// expects lat/long params in MILLIONTHs of decimal degree
|
||||
float TinyGPS_course_to (float lat1, float long1, float lat2, float long2);
|
||||
const char *TinyGPS_cardinal(float course);
|
||||
|
||||
int TinyGPS_feedGps();
|
||||
|
||||
#ifndef _GPS_NO_STATS
|
||||
void TinyGPS_stats(unsigned long *chars, unsigned short *good_sentences, unsigned short *failed_cs);
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -4,6 +4,7 @@
|
|||
#ifndef HAL_H_
|
||||
#define HAL_H_
|
||||
|
||||
#include <main.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
//#include <stm32f10x.h>
|
||||
|
@ -13,8 +14,9 @@
|
|||
#endif
|
||||
#include <stm32f4xx_hal_gpio.h>
|
||||
// #include <stm32f10x_gpio.h>
|
||||
// #include <uart.h>
|
||||
|
||||
#include <uart.h>
|
||||
#include "stm32f4xx_hal_dma.h"
|
||||
#include "stm32f4xx_hal_usart.h"
|
||||
|
||||
|
||||
|
||||
|
@ -55,6 +57,8 @@
|
|||
|
||||
__IO uint32_t timingDelay;
|
||||
|
||||
#define MEDIATEK_MODULE
|
||||
#define hal_gpsUart USART1
|
||||
|
||||
// gpio pins
|
||||
// extern const Gpio_Pin RX_TO_GSM;
|
||||
|
@ -68,11 +72,12 @@
|
|||
// extern const Gpio_Pin FINGER_PRINT_BUTTON;
|
||||
extern const Gpio_Pin LCD_NSS;
|
||||
// extern const Gpio_Pin LOW_BAT;
|
||||
// extern const Gpio_Pin RX_TO_GPS;
|
||||
// extern const Gpio_Pin TX_FROM_GPS;
|
||||
// extern const Gpio_Pin GPS_RESET;
|
||||
// extern const Gpio_Pin GPS_FIX_LED;
|
||||
// extern const Gpio_Pin GPS_PPS;
|
||||
extern const Gpio_Pin RX_TO_GPS;
|
||||
extern const Gpio_Pin TX_FROM_GPS;
|
||||
extern const Gpio_Pin GPS_RESET;
|
||||
extern const Gpio_Pin GPS_FIX_LED;
|
||||
extern const Gpio_Pin GPS_PPS;
|
||||
extern const Gpio_Pin GPS_POWER;
|
||||
extern const Gpio_Pin SPI1_SCK;
|
||||
extern const Gpio_Pin SPI1_MISO;
|
||||
extern const Gpio_Pin SPI1_MOSI;
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
#include "stm32f4xx_hal_dac.h"
|
||||
|
||||
#include "images.h"
|
||||
#include "stm32f4xx_hal_dma.h"
|
||||
|
||||
#include "stm32f4xx_hal_def.h"
|
||||
|
||||
TIM_HandleTypeDef TimHandle;
|
||||
TIM_HandleTypeDef TimHandle4;
|
||||
|
@ -59,4 +62,16 @@ TIM_HandleTypeDef TimHandle4;
|
|||
#define MASKWHITE 0b1111111111111111
|
||||
#define MASKBLACK 0b0000000000000000
|
||||
|
||||
/* Definition for SPIx's DMA */
|
||||
#define SPIx_TX_DMA_CHANNEL DMA_CHANNEL_3
|
||||
#define SPIx_TX_DMA_STREAM DMA2_Stream5
|
||||
#define SPIx_RX_DMA_CHANNEL DMA_CHANNEL_3
|
||||
#define SPIx_RX_DMA_STREAM DMA2_Stream2
|
||||
|
||||
/* Definition for SPIx's NVIC */
|
||||
#define SPIx_DMA_TX_IRQn DMA2_Stream3_IRQn
|
||||
#define SPIx_DMA_RX_IRQn DMA2_Stream0_IRQn
|
||||
#define SPIx_DMA_TX_IRQHandler DMA2_Stream3_IRQHandler
|
||||
#define SPIx_DMA_RX_IRQHandler DMA2_Stream0_IRQHandler
|
||||
|
||||
SPI_HandleTypeDef SpiHandle;
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* queue.h
|
||||
*
|
||||
* queue/circular buffer
|
||||
*
|
||||
* Copyright 2013 RPH Engineering, VPI Engineering
|
||||
*/
|
||||
|
||||
#ifndef QUEUE_H_
|
||||
#define QUEUE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
|
||||
// a Q that can store up to 256 bytes
|
||||
typedef struct _Queue8
|
||||
{
|
||||
uint8_t qCount; // number of bytes in the Q
|
||||
uint8_t size; // size of q, in bytes
|
||||
uint8_t readIndex;
|
||||
uint8_t writeIndex;
|
||||
uint8_t* data;
|
||||
} Queue8;
|
||||
|
||||
|
||||
|
||||
void queue8_init(Queue8* queue, uint8_t* dataPtr, uint8_t size);
|
||||
// initialize a Queue8
|
||||
|
||||
bool queue8_isQFull(Queue8* queue);
|
||||
// return true if the Q is full, else false
|
||||
|
||||
bool queue8_isQEmpty(Queue8* queue);
|
||||
// return true if the Q is empty, else false
|
||||
|
||||
int queue8_enqueue(Queue8* queue, uint8_t data);
|
||||
// enqueue data on queue
|
||||
// returns 0 on success, negative o/w
|
||||
|
||||
int queue8_dequeue(Queue8* queue, uint8_t* data);
|
||||
// pull a byte of data off queue and put it in *data
|
||||
// returns 0 on success, negative o/w
|
||||
|
||||
void queue8_purge(Queue8* queue);
|
||||
// purge a q
|
||||
|
||||
int queue8_getCount(Queue8* queue);
|
||||
// get the count of entries in the q
|
||||
|
||||
|
||||
#endif /* QUEUE_H_ */
|
|
@ -17,7 +17,7 @@
|
|||
//#include <stm32f4xx_hal.h>
|
||||
#include <stm32f4xx_hal_spi.h>
|
||||
|
||||
SPI_HandleTypeDef SpiHandle;
|
||||
//SPI_HandleTypeDef SpiHandle;
|
||||
|
||||
void spi_init(void);
|
||||
// set up the used SPI (SPI2) and pins
|
||||
|
@ -28,7 +28,7 @@ SPI_HandleTypeDef SpiHandle;
|
|||
//
|
||||
// void spi_postSpi2Semaphore(void);
|
||||
// // post (make available) spi2 semaphore
|
||||
void spi_readWrite(SPI_HandleTypeDef SpiHandle, uint8_t *rxBuf, uint8_t *txBuf, int cnt);
|
||||
void spi_readWrite(SPI_HandleTypeDef SpiHandle, uint16_t *rxBuf, uint16_t *txBuf, uint16_t cnt); //was uint8_t
|
||||
//int spi_readWrite(SPI_TypeDef* SPIx, uint8_t *rxBuf, const uint8_t *txBuf, int cnt, uint16_t speed);
|
||||
// send data to the spi bus, read data in from the spi bus
|
||||
// returns the number of bytes written/read
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/* uart.h
|
||||
*
|
||||
* gunbox uart interface
|
||||
*
|
||||
* Copyright 2013 RPH Engineering, VPI Engineering
|
||||
*/
|
||||
|
||||
#ifndef UART_H_
|
||||
#define UART_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
enum Uarts
|
||||
{
|
||||
uart_uartNone,
|
||||
uart_uart1,
|
||||
uart_uart2,
|
||||
uart_uart3,
|
||||
};
|
||||
|
||||
|
||||
|
||||
int uart_putChar(uint8_t uart, char c);
|
||||
// enqueue a char to a uart
|
||||
// returns 0 on success
|
||||
|
||||
int uart_getChar(uint8_t uart, char* c);
|
||||
// dequeue a char from a uart and put it in *c
|
||||
// returns 0 on success
|
||||
|
||||
int uart_write(uint8_t uart, uint8_t* buffer, uint8_t size);
|
||||
// write a buffer of data to a uart
|
||||
// return the number of bytes written
|
||||
|
||||
int uart_read(uint8_t uart, uint8_t* buffer, uint8_t size);
|
||||
// try to read size bytes of data into buffer from a uart
|
||||
// return the number of bytes read
|
||||
|
||||
void uart_init(uint8_t uart);
|
||||
// initialize specified uart
|
||||
|
||||
void uart_deinit(uint8_t uart);
|
||||
// deinitialize specified uart
|
||||
|
||||
void uart_enable(uint8_t uart);
|
||||
// enable a uart, enables rxne interrupt, does not set other config info
|
||||
|
||||
void uart_disable(uint8_t uart);
|
||||
// disable a uart and the uart rxne and txe itnerrupts but leave registers setup
|
||||
|
||||
void uart_purgeRxQueue(uint8_t uart);
|
||||
// purge the rx q for uart
|
||||
|
||||
int uart_getRxQueueCount(uint8_t uart);
|
||||
// get the count for the rx q for uart
|
||||
|
||||
int uart_queueHasChar(char c, uint8_t uart);
|
||||
// return true if the rx q contains c
|
||||
|
||||
int uart_queueContains(char thingToFind[], int thingToFindLength, uint8_t);
|
||||
|
||||
|
||||
#endif /* UART_H_ */
|
|
@ -375,16 +375,51 @@ void Adafruit_GFX_drawBitmap(int16_t x, int16_t y,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//#include "Adafruit_ILI9340.h"
|
||||
//#include "spi.h"
|
||||
#include "hal.h"
|
||||
#include "stm32f4xx_hal_spi.h"
|
||||
void Adafruit_GFX_drawColorBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h, uint16_t tintMask)
|
||||
{
|
||||
int16_t i, j, bmIndex;
|
||||
|
||||
for(j=0; j<h; j++) {
|
||||
for(i=0; i<w; i++) {
|
||||
bmIndex = i+w*j;
|
||||
Adafruit_ILI9340_drawPixel(x+i, y+j, bitmap[bmIndex] & tintMask);
|
||||
Adafruit_ILI9340_setAddrWindow(x,y,x+w-1, y+h-1);
|
||||
|
||||
//i = 0;
|
||||
HAL_GPIO_WritePin(LCD_DC.port, LCD_DC.pin, 1);
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 0);
|
||||
|
||||
// if(tintMask == 0xFFFF)
|
||||
// {
|
||||
// HAL_SPI_Transmit(&SpiHandle, bitmap, h*w*2, 1); //When you do it this way, the bytes are swapped. Hmmm
|
||||
// //So it looks weird.
|
||||
// } else {
|
||||
{
|
||||
uint8_t txBuf[10];
|
||||
|
||||
//HAL_SPI_Transmit(&SpiHandle, bitmap, 1 /*cnt * 2*/, 1);
|
||||
for(i = 0; i < w*h; i++)
|
||||
{
|
||||
txBuf[0] = (bitmap[i] & tintMask ) >> 8;
|
||||
txBuf[1] = (bitmap[i] & tintMask ) & 0xFF;
|
||||
//spi_readWrite(SpiHandle, rxBuf, bitmap, w*h);
|
||||
HAL_SPI_Transmit(&SpiHandle, txBuf, 2 /*cnt * 2*/, 1);
|
||||
//HAL_SPI_Transmit(&SpiHandle, bitmap[i+1], 1 /*cnt * 2*/, 1);
|
||||
//}
|
||||
//SET_BIT(csport, cspinmask);
|
||||
}
|
||||
}
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 1);
|
||||
|
||||
|
||||
|
||||
// for(j=0; j<h; j++) {
|
||||
// for(i=0; i<w; i++) {
|
||||
// bmIndex = i+w*j;
|
||||
// Adafruit_ILI9340_drawPixel(x+i, y+j, bitmap[bmIndex] & tintMask);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#if ARDUINO >= 100
|
||||
|
|
|
@ -56,8 +56,8 @@
|
|||
|
||||
// int _width = ILI9340_TFTWIDTH; //240;
|
||||
// int _height = ILI9340_TFTHEIGHT; //320
|
||||
uint8_t rxBuf[10];
|
||||
uint8_t txBuf[2];
|
||||
uint16_t rxBuf[10];
|
||||
uint16_t txBuf[2];
|
||||
|
||||
// Constructor when using hardware SPI. Faster, but must use SPI pins
|
||||
// specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.)
|
||||
|
@ -105,7 +105,7 @@ void Adafruit_ILI9340_spiwrite(uint8_t c) {
|
|||
}
|
||||
|
||||
|
||||
void Adafruit_ILI9340_writecommand(uint8_t c) {
|
||||
void Adafruit_ILI9340_writecommand(uint16_t c) {
|
||||
//CLEAR_BIT(dcport, dcpinmask);
|
||||
HAL_GPIO_WritePin(LCD_DC.port, LCD_DC.pin, 0);
|
||||
//digitalWrite(_dc, LOW);
|
||||
|
@ -117,8 +117,10 @@ void Adafruit_ILI9340_writecommand(uint8_t c) {
|
|||
//digitalWrite(_cs, LOW);
|
||||
|
||||
//spiwrite(c);
|
||||
txBuf[0] = c;
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
txBuf[0] = c; // & 0xFF;
|
||||
//spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
HAL_SPI_Transmit(&SpiHandle, txBuf, 1 /*cnt * 2*/, 1);
|
||||
|
||||
//HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)txBuf, (uint8_t *)rxBuf, 1, 1000);
|
||||
|
||||
//SET_BIT(csport, cspinmask);
|
||||
|
@ -127,7 +129,7 @@ void Adafruit_ILI9340_writecommand(uint8_t c) {
|
|||
}
|
||||
|
||||
|
||||
void Adafruit_ILI9340_writedata(uint8_t c) {
|
||||
void Adafruit_ILI9340_writedata(uint16_t c) {
|
||||
//SET_BIT(dcport, dcpinmask);
|
||||
HAL_GPIO_WritePin(LCD_DC.port, LCD_DC.pin, 1);
|
||||
//digitalWrite(_dc, HIGH);
|
||||
|
@ -139,8 +141,9 @@ void Adafruit_ILI9340_writedata(uint8_t c) {
|
|||
//digitalWrite(_cs, LOW);
|
||||
|
||||
//spiwrite(c);
|
||||
txBuf[0] = c;
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
txBuf[0] = c; // & 0xFF;
|
||||
//spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
HAL_SPI_Transmit(&SpiHandle, txBuf, 1 /*cnt * 2*/, 1);
|
||||
//HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)txBuf, (uint8_t *)rxBuf, 1, 1000);
|
||||
|
||||
//digitalWrite(_cs, HIGH);
|
||||
|
@ -392,21 +395,25 @@ void Adafruit_ILI9340_setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
|
|||
void Adafruit_ILI9340_pushColor(uint16_t color) {
|
||||
//digitalWrite(_dc, HIGH);
|
||||
//SET_BIT(dcport, dcpinmask);
|
||||
GPIO_WriteBit(LCD_DC.port, LCD_DC.pin, 1);
|
||||
//GPIO_WriteBit(LCD_DC.port, LCD_DC.pin, 1);
|
||||
HAL_GPIO_WritePin(LCD_DC.port, LCD_DC.pin, 1);
|
||||
//digitalWrite(_cs, LOW);
|
||||
//CLEAR_BIT(csport, cspinmask);
|
||||
GPIO_WriteBit(LCD_NSS.port, LCD_NSS.pin, 0);
|
||||
// GPIO_WriteBit(LCD_NSS.port, LCD_NSS.pin, 0);
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 0);
|
||||
|
||||
//spiwrite(color >> 8);
|
||||
//spiwrite(color);
|
||||
uint8_t rxBuf[10];
|
||||
uint8_t txBuf[2] = {color >> 8, color};
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 2);
|
||||
//uint16_t rxBuf[10];
|
||||
//uint16_t txBuf[2] = {color >> 8, color};
|
||||
txBuf[0] = color;
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
|
||||
|
||||
|
||||
//SET_BIT(csport, cspinmask);
|
||||
GPIO_WriteBit(LCD_NSS.port, LCD_NSS.pin, 1);
|
||||
//GPIO_WriteBit(LCD_NSS.port, LCD_NSS.pin, 1);
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 1);
|
||||
//digitalWrite(_cs, HIGH);
|
||||
}
|
||||
|
||||
|
@ -425,15 +432,38 @@ void Adafruit_ILI9340_drawPixel(int16_t x, int16_t y, uint16_t color) {
|
|||
|
||||
//spiwrite(color >> 8);
|
||||
//spiwrite(color);
|
||||
uint8_t rxBuf[10];
|
||||
uint8_t txBuf[2] = {color >> 8, color};
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 2);
|
||||
//uint8_t rxBuf[10];
|
||||
//uint8_t txBuf[2] = {color >> 8, color};
|
||||
txBuf[0] = color;
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
|
||||
//SET_BIT(csport, cspinmask);
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 1);
|
||||
//digitalWrite(_cs, HIGH);
|
||||
}
|
||||
|
||||
void Adafruit_ILI9340_drawNextPixel(uint16_t color) {
|
||||
|
||||
Adafruit_ILI9340_writecommand(ILI9340_RAMWRCNT);
|
||||
|
||||
//digitalWrite(_dc, HIGH);
|
||||
//SET_BIT(dcport, dcpinmask);
|
||||
HAL_GPIO_WritePin(LCD_DC.port, LCD_DC.pin, 1);
|
||||
//digitalWrite(_cs, LOW);
|
||||
//CLEAR_BIT(csport, cspinmask);
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 0);
|
||||
|
||||
//spiwrite(color >> 8);
|
||||
//spiwrite(color);
|
||||
//uint8_t rxBuf[10];
|
||||
//uint8_t txBuf[2] = {color >> 8, color};
|
||||
txBuf[0] = color;
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
|
||||
//SET_BIT(csport, cspinmask);
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 1);
|
||||
//digitalWrite(_cs, HIGH);
|
||||
}
|
||||
|
||||
void Adafruit_ILI9340_drawFastVLine(int16_t x, int16_t y, int16_t h,
|
||||
uint16_t color) {
|
||||
|
@ -446,7 +476,7 @@ void Adafruit_ILI9340_drawFastVLine(int16_t x, int16_t y, int16_t h,
|
|||
|
||||
Adafruit_ILI9340_setAddrWindow(x, y, x, y+h-1);
|
||||
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
//uint8_t hi = color >> 8, lo = color;
|
||||
|
||||
//SET_BIT(dcport, dcpinmask);
|
||||
HAL_GPIO_WritePin(LCD_DC.port, LCD_DC.pin, 1);
|
||||
|
@ -455,15 +485,15 @@ void Adafruit_ILI9340_drawFastVLine(int16_t x, int16_t y, int16_t h,
|
|||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 0);
|
||||
//digitalWrite(_cs, LOW);
|
||||
|
||||
uint8_t rxBuf[10];
|
||||
uint8_t txBuf[2];
|
||||
//uint8_t rxBuf[10];
|
||||
//uint8_t txBuf[2];
|
||||
while (h--) {
|
||||
//spiwrite(hi);
|
||||
//spiwrite(lo);
|
||||
txBuf[0] = hi;
|
||||
txBuf[1] = lo;
|
||||
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 2);
|
||||
//txBuf[0] = hi;
|
||||
//txBuf[1] = lo;
|
||||
txBuf[0] = color;
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
}
|
||||
//SET_BIT(csport, cspinmask);
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 1);
|
||||
|
@ -479,7 +509,7 @@ void Adafruit_ILI9340_drawFastHLine(int16_t x, int16_t y, int16_t w,
|
|||
if((x+w-1) >= _width) w = _width-x;
|
||||
Adafruit_ILI9340_setAddrWindow(x, y, x+w-1, y);
|
||||
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
//uint8_t hi = color >> 8, lo = color;
|
||||
//SET_BIT(dcport, dcpinmask);
|
||||
HAL_GPIO_WritePin(LCD_DC.port, LCD_DC.pin, 1);
|
||||
//CLEAR_BIT(csport, cspinmask);
|
||||
|
@ -490,10 +520,10 @@ void Adafruit_ILI9340_drawFastHLine(int16_t x, int16_t y, int16_t w,
|
|||
while (w--) {
|
||||
//spiwrite(hi);
|
||||
//spiwrite(lo);
|
||||
txBuf[0] = hi;
|
||||
txBuf[1] = lo;
|
||||
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 2);
|
||||
//txBuf[0] = hi;
|
||||
//txBuf[1] = lo;
|
||||
txBuf[0] = color;
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
}
|
||||
//SET_BIT(csport, cspinmask);
|
||||
HAL_GPIO_WritePin(LCD_NSS.port, LCD_NSS.pin, 1);
|
||||
|
@ -515,7 +545,7 @@ void Adafruit_ILI9340_fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
|||
|
||||
Adafruit_ILI9340_setAddrWindow(x, y, x+w-1, y+h-1);
|
||||
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
// uint8_t hi = color >> 8, lo = color;
|
||||
|
||||
//SET_BIT(dcport, dcpinmask);
|
||||
HAL_GPIO_WritePin(LCD_DC.port, LCD_DC.pin, 1);
|
||||
|
@ -528,10 +558,11 @@ void Adafruit_ILI9340_fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
|||
for(x=w; x>0; x--) {
|
||||
//spiwrite(hi);
|
||||
//spiwrite(lo);
|
||||
txBuf[0] = hi;
|
||||
txBuf[1] = lo;
|
||||
//txBuf[0] = hi;
|
||||
//txBuf[1] = lo;
|
||||
txBuf[0] = color;
|
||||
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 2);
|
||||
spi_readWrite(SpiHandle, rxBuf, txBuf, 1);
|
||||
//HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)txBuf, (uint8_t*)rxBuf, 2, 1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,609 @@
|
|||
/*
|
||||
TinyGPS - a small GPS library for Arduino providing basic NMEA parsing
|
||||
Based on work by and "distance_to" and "course_to" courtesy of Maarten Lamers.
|
||||
Suggestion to add satellites(), course_to(), and cardinal(), by Matt Monson.
|
||||
Precision improvements suggested by Wayne Holder.
|
||||
Copyright (C) 2008-2013 Mikal Hart
|
||||
All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "TinyGPS.h"
|
||||
#include <math.h>
|
||||
//#include <trig.h>
|
||||
#include <hal.h>
|
||||
|
||||
#define _GPRMC_TERM "GPRMC"
|
||||
#define _GPGGA_TERM "GPGGA"
|
||||
|
||||
#define TWO_PI 6.28318530717958647693 //These numbers are included in Processing, since we aren't using Processing we need to include them here.
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
#define GPS_HYBERNATE_COMMAND "$PMTK161,0*28\x0D\x0A"
|
||||
|
||||
enum {_GPS_SENTENCE_GPGGA, _GPS_SENTENCE_GPRMC, _GPS_SENTENCE_OTHER};
|
||||
|
||||
// properties
|
||||
unsigned long _time, _new_time;
|
||||
unsigned long _date, _new_date;
|
||||
long _latitude, _new_latitude;
|
||||
long _longitude, _new_longitude;
|
||||
long _altitude, _new_altitude;
|
||||
unsigned long _speed, _new_speed;
|
||||
unsigned long _course, _new_course;
|
||||
unsigned long _hdop, _new_hdop;
|
||||
unsigned short _numsats, _new_numsats;
|
||||
unsigned long timeOfLastChar = 0;
|
||||
|
||||
unsigned long _last_time_fix, _new_time_fix;
|
||||
unsigned long _last_position_fix, _new_position_fix;
|
||||
|
||||
// parsing state variables
|
||||
unsigned char _parity; //was byte
|
||||
bool _is_checksum_term;
|
||||
char _term[15];
|
||||
unsigned char _sentence_type; //was byte
|
||||
unsigned char _term_number; //was byte
|
||||
unsigned char _term_offset; //was byte
|
||||
bool _gps_data_good;
|
||||
|
||||
#ifndef _GPS_NO_STATS
|
||||
// statistics
|
||||
unsigned long _encoded_characters;
|
||||
unsigned short _good_sentences;
|
||||
unsigned short _failed_checksum;
|
||||
unsigned short _passed_checksum;
|
||||
#endif
|
||||
|
||||
// internal utilities
|
||||
int TinyGPS_from_hex(char a);
|
||||
unsigned long TinyGPS_parse_decimal();
|
||||
unsigned long TinyGPS_parse_degrees();
|
||||
bool TinyGPS_term_complete();
|
||||
bool TinyGPS_gpsisdigit(char c); //{ return c >= '0' && c <= '9'; }
|
||||
long TinyGPS_gpsatol(const char *str);
|
||||
int TinyGPS_gpsstrcmp(const char *str1, const char *str2);
|
||||
|
||||
|
||||
void TinyGPS_init()
|
||||
{
|
||||
_time = GPS_INVALID_TIME;
|
||||
_date = GPS_INVALID_DATE;
|
||||
_latitude = GPS_INVALID_ANGLE;
|
||||
_longitude = GPS_INVALID_ANGLE;
|
||||
_altitude = GPS_INVALID_ALTITUDE;
|
||||
_speed = GPS_INVALID_SPEED;
|
||||
_course = GPS_INVALID_ANGLE;
|
||||
_hdop = GPS_INVALID_HDOP;
|
||||
_numsats = GPS_INVALID_SATELLITES;
|
||||
_last_time_fix = GPS_INVALID_FIX_TIME;
|
||||
_last_position_fix = GPS_INVALID_FIX_TIME;
|
||||
_parity = 0;
|
||||
_is_checksum_term = false;
|
||||
_sentence_type = _GPS_SENTENCE_OTHER;
|
||||
_term_number = 0;
|
||||
_term_offset = 0;
|
||||
_gps_data_good = false;
|
||||
#ifndef _GPS_NO_STATS
|
||||
_encoded_characters = 0;
|
||||
_good_sentences = 0;
|
||||
_failed_checksum = 0;
|
||||
#endif
|
||||
{
|
||||
_term[0] = '\0';
|
||||
}
|
||||
|
||||
//Initial Uart setup
|
||||
uart_init(hal_gpsUart);
|
||||
|
||||
#ifdef SIRF_MODULE
|
||||
//TODO: Determine which of these delays can be eliminated or reduced
|
||||
hal_delay_ms(1000);
|
||||
|
||||
|
||||
//Put module into binary mode to accept TricklePower command
|
||||
//Putting module into binary at 4800 DOES NOT WORK (it sets itself to 9600)
|
||||
//uart_write(hal_gpsUart, "$PSRF100,0,57600,8,1,0*37\r\n", 27); //Does put module into binary mode, baud rate is correct.
|
||||
uart_write(hal_gpsUart, "$PSRF100,0,9600,8,1,0*0C\r\n", 26); //Does put module into binary mode, baud rate is correct.
|
||||
hal_delay_ms(1000);
|
||||
|
||||
//Now we're working at 9600
|
||||
hal_setupUart3(9600);
|
||||
|
||||
//Enable tricklepower mode (mid 151)
|
||||
uart_write(hal_gpsUart, "\xA0\xA2\x00\x09\x97\x00\x00\x00\xC8\x00\x00\x01\x90\x01\xF0\xB0\xB3",17); //No additional CR or LF needed.
|
||||
|
||||
hal_delay_ms(1000);
|
||||
|
||||
//Set Low Power acquisition parameters (mid 167)
|
||||
uart_write(hal_gpsUart, "\xA0\xA2\x00\x0F\xA7\x00\x00\x75\x30\x00\x04\x93\xE0\x00\x00\x07\x08\x00\x01\x02\xD3\xB0\xB3", 23);
|
||||
|
||||
hal_delay_ms(1000);
|
||||
|
||||
//revert to NMEA mode (Puts it into 9600 so I don't have to rewrite the command, but I will if I need to)
|
||||
uart_write(hal_gpsUart, "\xA0\xA2\x00\x18\x81\x02\x01\x01\x00\x01\x00\x01\x00\x01\x01\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x25\x80\x01\x34\xB0\xB3", 32);
|
||||
hal_delay_ms(1000);
|
||||
#endif
|
||||
#ifdef MEDIATEK_MODULE
|
||||
//Send it something to wake it up
|
||||
uart_write(hal_gpsUart, "\r\n", 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Power on GPS (this probably shouldn't be in TinyGPS
|
||||
//void TinyGPS_powerOnGps()
|
||||
//{
|
||||
// //I think any character will wake it up, so... why not send a few carriage returns?
|
||||
// uart_write(hal_gpsUart, "\r\r\r", 3);
|
||||
//}
|
||||
|
||||
//Hybernate GPS (also shouldn't be in TinyGPS
|
||||
//void TinyGPS_hybernateGps()
|
||||
//{
|
||||
// uart_write(hal_gpsUart, (unsigned char*) GPS_HYBERNATE_COMMAND, sizeof GPS_HYBERNATE_COMMAND - 1);
|
||||
//}
|
||||
|
||||
//GPS power status. Since the only way we know (right?) is by watching for characters,
|
||||
//and they only come once per second, it's possible this will be wrong for up to a second, you know?
|
||||
//Also shouldn't be in TinyGPS
|
||||
int TinyGPS_gpsIsOn()
|
||||
{
|
||||
return hal_checkTimeout(timeOfLastChar, 1100) ? 0 : 1;
|
||||
}
|
||||
|
||||
int TinyGPS_feedGps() //probably not the right place to put this. Maybe in the GPS.c?
|
||||
{
|
||||
char c;
|
||||
while(uart_getChar(hal_gpsUart, &c) != -1)
|
||||
{
|
||||
timeOfLastChar = hal_getCurrentTime_ms();
|
||||
//return TinyGPS_encode(c);
|
||||
// could return here if returns true, but probably not for each character
|
||||
TinyGPS_encode(c);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int TinyGPS_hasFix() //The right way to do this would be to parse the NMEA sentences to get this information, but I am in a hurry.
|
||||
{
|
||||
bool returnVal = (_last_position_fix != GPS_INVALID_FIX_TIME && !hal_checkTimeout(_last_position_fix, 5000)) ? 1 : 0;
|
||||
return returnVal; //So I can see what's happening.
|
||||
}
|
||||
|
||||
#define COMBINE(sentence_type, term_number) (((unsigned)(sentence_type) << 5) | term_number)
|
||||
|
||||
//
|
||||
// internal utilities
|
||||
//
|
||||
int TinyGPS_from_hex(char a)
|
||||
{
|
||||
if (a >= 'A' && a <= 'F')
|
||||
return a - 'A' + 10;
|
||||
else if (a >= 'a' && a <= 'f')
|
||||
return a - 'a' + 10;
|
||||
else
|
||||
return a - '0';
|
||||
}
|
||||
|
||||
long TinyGPS_gpsatol(const char *str)
|
||||
{
|
||||
long ret = 0;
|
||||
while (TinyGPS_gpsisdigit(*str))
|
||||
ret = 10 * ret + *str++ - '0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TinyGPS_gpsstrcmp(const char *str1, const char *str2)
|
||||
{
|
||||
while (*str1 && *str1 == *str2)
|
||||
++str1, ++str2;
|
||||
return *str1;
|
||||
}
|
||||
|
||||
unsigned long TinyGPS_parse_decimal()
|
||||
{
|
||||
char *p = _term;
|
||||
bool isneg = *p == '-';
|
||||
if (isneg) ++p;
|
||||
unsigned long ret = 100UL * TinyGPS_gpsatol(p);
|
||||
while (TinyGPS_gpsisdigit(*p)) ++p;
|
||||
if (*p == '.')
|
||||
{
|
||||
if (TinyGPS_gpsisdigit(p[1]))
|
||||
{
|
||||
ret += 10 * (p[1] - '0');
|
||||
if (TinyGPS_gpsisdigit(p[2]))
|
||||
ret += p[2] - '0';
|
||||
}
|
||||
}
|
||||
return isneg ? -ret : ret;
|
||||
}
|
||||
|
||||
bool TinyGPS_gpsisdigit(char c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
// Parse a string in the form ddmm.mmmmmmm...
|
||||
unsigned long TinyGPS_parse_degrees()
|
||||
{
|
||||
char *p;
|
||||
unsigned long left_of_decimal = TinyGPS_gpsatol(_term);
|
||||
unsigned long hundred1000ths_of_minute = (left_of_decimal % 100UL) * 100000UL;
|
||||
for (p=_term; TinyGPS_gpsisdigit(*p); ++p);
|
||||
if (*p == '.')
|
||||
{
|
||||
unsigned long mult = 10000;
|
||||
while (TinyGPS_gpsisdigit(*++p))
|
||||
{
|
||||
hundred1000ths_of_minute += mult * (*p - '0');
|
||||
mult /= 10;
|
||||
}
|
||||
}
|
||||
return (left_of_decimal / 100) * 1000000 + (hundred1000ths_of_minute + 3) / 6;
|
||||
}
|
||||
|
||||
// Processes a just-completed term
|
||||
// Returns true if new sentence has just passed checksum test and is validated
|
||||
bool TinyGPS_term_complete()
|
||||
{
|
||||
if (_is_checksum_term)
|
||||
{
|
||||
unsigned char checksum = 16 * TinyGPS_from_hex(_term[0]) + TinyGPS_from_hex(_term[1]); //Was byte
|
||||
if (checksum == _parity)
|
||||
{
|
||||
if (_gps_data_good)
|
||||
{
|
||||
#ifndef _GPS_NO_STATS
|
||||
++_good_sentences;
|
||||
#endif
|
||||
_last_time_fix = _new_time_fix;
|
||||
_last_position_fix = _new_position_fix;
|
||||
|
||||
switch(_sentence_type)
|
||||
{
|
||||
case _GPS_SENTENCE_GPRMC:
|
||||
_time = _new_time;
|
||||
_date = _new_date;
|
||||
_latitude = _new_latitude;
|
||||
_longitude = _new_longitude;
|
||||
_speed = _new_speed;
|
||||
_course = _new_course;
|
||||
break;
|
||||
case _GPS_SENTENCE_GPGGA:
|
||||
_altitude = _new_altitude;
|
||||
_time = _new_time;
|
||||
_latitude = _new_latitude;
|
||||
_longitude = _new_longitude;
|
||||
_numsats = _new_numsats;
|
||||
_hdop = _new_hdop;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _GPS_NO_STATS
|
||||
else
|
||||
++_failed_checksum;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// the first term determines the sentence type
|
||||
if (_term_number == 0)
|
||||
{
|
||||
if (!TinyGPS_gpsstrcmp(_term, _GPRMC_TERM))
|
||||
_sentence_type = _GPS_SENTENCE_GPRMC;
|
||||
else if (!TinyGPS_gpsstrcmp(_term, _GPGGA_TERM))
|
||||
_sentence_type = _GPS_SENTENCE_GPGGA;
|
||||
else
|
||||
_sentence_type = _GPS_SENTENCE_OTHER;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_sentence_type != _GPS_SENTENCE_OTHER && _term[0])
|
||||
switch(COMBINE(_sentence_type, _term_number))
|
||||
{
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 1): // Time in both sentences
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 1):
|
||||
_new_time = TinyGPS_parse_decimal();
|
||||
_new_time_fix = hal_getCurrentTime_ms(); //millis(); //TODO: put a callback so we can remove the hal.h dependency.
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 2): // GPRMC validity
|
||||
_gps_data_good = _term[0] == 'A';
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 3): // Latitude
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 2):
|
||||
_new_latitude = TinyGPS_parse_degrees();
|
||||
_new_position_fix = hal_getCurrentTime_ms(); //millis();
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 4): // N/S
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 3):
|
||||
if (_term[0] == 'S')
|
||||
_new_latitude = -_new_latitude;
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 5): // Longitude
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 4):
|
||||
_new_longitude = TinyGPS_parse_degrees();
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 6): // E/W
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 5):
|
||||
if (_term[0] == 'W')
|
||||
_new_longitude = -_new_longitude;
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 7): // Speed (GPRMC)
|
||||
_new_speed = TinyGPS_parse_decimal();
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 8): // Course (GPRMC)
|
||||
_new_course = TinyGPS_parse_decimal();
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPRMC, 9): // Date (GPRMC)
|
||||
_new_date = TinyGPS_gpsatol(_term);
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 6): // Fix data (GPGGA)
|
||||
_gps_data_good = _term[0] > '0';
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 7): // Satellites used (GPGGA)
|
||||
_new_numsats = (unsigned char)atoi(_term);
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 8): // HDOP
|
||||
_new_hdop = TinyGPS_parse_decimal();
|
||||
break;
|
||||
case COMBINE(_GPS_SENTENCE_GPGGA, 9): // Altitude (GPGGA)
|
||||
_new_altitude = TinyGPS_parse_decimal();
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool TinyGPS_encode(char c)
|
||||
{
|
||||
bool valid_sentence = false;
|
||||
|
||||
#ifndef _GPS_NO_STATS
|
||||
++_encoded_characters;
|
||||
#endif
|
||||
switch(c)
|
||||
{
|
||||
case ',': // term terminators
|
||||
_parity ^= c;
|
||||
case '\r':
|
||||
case '\n':
|
||||
case '*':
|
||||
if (_term_offset < sizeof(_term))
|
||||
{
|
||||
_term[_term_offset] = 0;
|
||||
valid_sentence = TinyGPS_term_complete();
|
||||
}
|
||||
++_term_number;
|
||||
_term_offset = 0;
|
||||
_is_checksum_term = c == '*';
|
||||
return valid_sentence;
|
||||
|
||||
case '$': // sentence begin
|
||||
_term_number = _term_offset = 0;
|
||||
_parity = 0;
|
||||
_sentence_type = _GPS_SENTENCE_OTHER;
|
||||
_is_checksum_term = false;
|
||||
_gps_data_good = false;
|
||||
return valid_sentence;
|
||||
}
|
||||
|
||||
// ordinary characters
|
||||
if (_term_offset < sizeof(_term) - 1)
|
||||
_term[_term_offset++] = c;
|
||||
if (!_is_checksum_term)
|
||||
_parity ^= c;
|
||||
|
||||
return valid_sentence;
|
||||
}
|
||||
|
||||
#ifndef _GPS_NO_STATS
|
||||
void TinyGPS_stats(unsigned long *chars, unsigned short *sentences, unsigned short *failed_cs)
|
||||
{
|
||||
if (chars) *chars = _encoded_characters;
|
||||
if (sentences) *sentences = _good_sentences;
|
||||
if (failed_cs) *failed_cs = _failed_checksum;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* static */
|
||||
float TinyGPS_distance_between (long lat1_, long long1_, long lat2_, long long2_)
|
||||
{
|
||||
// returns distance in meters between two positions, both specified
|
||||
// as signed decimal-degrees latitude and longitude. Uses great-circle
|
||||
// distance computation for hypothetical sphere of radius 6372795 meters.
|
||||
// Because Earth is no exact sphere, rounding errors may be up to 0.5%.
|
||||
// Courtesy of Maarten Lamers
|
||||
//float delta = radians(long1-long2); //I'm not including a math library just for this!
|
||||
float lat1 = lat1_ / 1000000.0;
|
||||
float long1 = long1_ / 1000000.0;
|
||||
float lat2 = lat2_ / 1000000.0;
|
||||
float long2 = long2_ / 1000000.0;
|
||||
float delta = (long1-long2) * PI/180.0;
|
||||
float sdlong = sin(delta);
|
||||
float cdlong = cos(delta);
|
||||
//lat1 = radians(lat1);
|
||||
//lat2 = radians(lat2);
|
||||
lat1 = (lat1) * PI/180.0;
|
||||
lat2 = (lat2) * PI/180.0;
|
||||
float slat1 = sin(lat1);
|
||||
float clat1 = cos(lat1);
|
||||
float slat2 = sin(lat2);
|
||||
float clat2 = cos(lat2);
|
||||
delta = (clat1 * slat2) - (slat1 * clat2 * cdlong);
|
||||
//delta = sq(delta); //I'm not including a math library just for this!
|
||||
delta = delta * delta;
|
||||
//delta += sq(clat2 * sdlong);
|
||||
delta += (clat2 * sdlong) * (clat2 * sdlong);
|
||||
delta = sqrt(delta);
|
||||
float denom = (slat1 * slat2) + (clat1 * clat2 * cdlong);
|
||||
delta = atan2(delta, denom);
|
||||
return delta * 6372795;
|
||||
}
|
||||
|
||||
float TinyGPS_course_to (float lat1, float long1, float lat2, float long2)
|
||||
{
|
||||
// returns course in degrees (North=0, West=270) from position 1 to position 2,
|
||||
// both specified as signed decimal-degrees latitude and longitude.
|
||||
// Because Earth is no exact sphere, calculated course may be off by a tiny fraction.
|
||||
// Courtesy of Maarten Lamers
|
||||
//float dlon = radians(long2-long1);
|
||||
float dlon = (long2-long1) * PI/180.0;
|
||||
//lat1 = radians(lat1);
|
||||
//lat2 = radians(lat2);
|
||||
lat1 = (lat1) * PI/180.0;
|
||||
lat2 = (lat2) * PI/180.0;
|
||||
float a1 = sin(dlon) * cos(lat2);
|
||||
float a2 = sin(lat1) * cos(lat2) * cos(dlon);
|
||||
a2 = cos(lat1) * sin(lat2) - a2;
|
||||
a2 = atan2(a1, a2);
|
||||
if (a2 < 0.0)
|
||||
{
|
||||
a2 += TWO_PI;
|
||||
}
|
||||
//return degrees(a2);
|
||||
return (a2) * 180.0 / PI;
|
||||
}
|
||||
|
||||
const char *TinyGPS_cardinal (float course)
|
||||
{
|
||||
static const char* directions[] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"};
|
||||
|
||||
int direction = (int)((course + 11.25f) / 22.5f);
|
||||
return directions[direction % 16];
|
||||
}
|
||||
|
||||
// lat/long in MILLIONTHs of a degree and age of fix in milliseconds
|
||||
// (note: versions 12 and earlier gave this value in 100,000ths of a degree.
|
||||
void TinyGPS_get_position(long *latitude, long *longitude, unsigned long *fix_age)
|
||||
{
|
||||
//*fix_age = 0; //Do I want this?
|
||||
if (latitude) *latitude = _latitude;
|
||||
if (longitude) *longitude = _longitude;
|
||||
if (fix_age) *fix_age = _last_position_fix == GPS_INVALID_FIX_TIME ?
|
||||
GPS_INVALID_AGE : /*millis()*/ hal_getCurrentTime_ms() - _last_position_fix;
|
||||
}
|
||||
|
||||
// date as ddmmyy, time as hhmmsscc, and age in milliseconds
|
||||
void TinyGPS_get_datetime(unsigned long *date, unsigned long *time, unsigned long *age)
|
||||
{
|
||||
//*age = 0; //Do I want this?
|
||||
if (date) *date = _date;
|
||||
if (time) *time = _time;
|
||||
if (age) *age = _last_time_fix == GPS_INVALID_FIX_TIME ?
|
||||
GPS_INVALID_AGE : /*millis()*/ hal_getCurrentTime_ms() - _last_time_fix;
|
||||
}
|
||||
|
||||
void TinyGPS_f_get_position(float *latitude, float *longitude, unsigned long *fix_age)
|
||||
{
|
||||
//*fix_age = 0; //Do I want this?
|
||||
long lat, lon;
|
||||
TinyGPS_get_position(&lat, &lon, fix_age);
|
||||
*latitude = lat == GPS_INVALID_ANGLE ? GPS_INVALID_F_ANGLE : (lat / 1000000.0);
|
||||
*longitude = lat == GPS_INVALID_ANGLE ? GPS_INVALID_F_ANGLE : (lon / 1000000.0);
|
||||
}
|
||||
|
||||
void TinyGPS_crack_datetime(int *year, unsigned char *month, unsigned char *day,
|
||||
unsigned char *hour, unsigned char *minute, unsigned char *second, unsigned char *hundredths, unsigned long *age)
|
||||
{
|
||||
//*hundredths = 0; //Do I want this?
|
||||
//*age = 0; //And this?
|
||||
unsigned long date, time;
|
||||
TinyGPS_get_datetime(&date, &time, age);
|
||||
if (year)
|
||||
{
|
||||
*year = date % 100;
|
||||
*year += *year > 80 ? 1900 : 2000;
|
||||
}
|
||||
if (month) *month = (date / 100) % 100;
|
||||
if (day) *day = date / 10000;
|
||||
if (hour) *hour = time / 1000000;
|
||||
if (minute) *minute = (time / 10000) % 100;
|
||||
if (second) *second = (time / 100) % 100;
|
||||
if (hundredths) *hundredths = time % 100;
|
||||
}
|
||||
|
||||
float TinyGPS_f_altitude()
|
||||
{
|
||||
return _altitude == GPS_INVALID_ALTITUDE ? GPS_INVALID_F_ALTITUDE : _altitude / 100.0;
|
||||
}
|
||||
|
||||
float TinyGPS_f_course()
|
||||
{
|
||||
return _course == GPS_INVALID_ANGLE ? GPS_INVALID_F_ANGLE : _course / 100.0;
|
||||
}
|
||||
|
||||
float TinyGPS_f_speed_knots()
|
||||
{
|
||||
return _speed == GPS_INVALID_SPEED ? GPS_INVALID_F_SPEED : _speed / 100.0;
|
||||
}
|
||||
|
||||
float TinyGPS_f_speed_mph()
|
||||
{
|
||||
float sk = TinyGPS_f_speed_knots();
|
||||
return sk == GPS_INVALID_F_SPEED ? GPS_INVALID_F_SPEED : _GPS_MPH_PER_KNOT * sk;
|
||||
}
|
||||
|
||||
float TinyGPS_f_speed_mps()
|
||||
{
|
||||
float sk = TinyGPS_f_speed_knots();
|
||||
return sk == GPS_INVALID_F_SPEED ? GPS_INVALID_F_SPEED : _GPS_MPS_PER_KNOT * sk;
|
||||
}
|
||||
|
||||
float TinyGPS_f_speed_kmph()
|
||||
{
|
||||
float sk = TinyGPS_f_speed_knots();
|
||||
return sk == GPS_INVALID_F_SPEED ? GPS_INVALID_F_SPEED : _GPS_KMPH_PER_KNOT * sk;
|
||||
}
|
||||
|
||||
const float TinyGPS_GPS_INVALID_F_ANGLE = 1000.0;
|
||||
const float TinyGPS_GPS_INVALID_F_ALTITUDE = 1000000.0;
|
||||
const float TinyGPS_GPS_INVALID_F_SPEED = -1.0;
|
||||
|
||||
// signed altitude in centimeters (from GPGGA sentence)
|
||||
inline long TinyGPS_altitude() { return _altitude; }
|
||||
|
||||
// course in last full GPRMC sentence in 100th of a degree
|
||||
inline unsigned long TinyGPS_course() { return _course; }
|
||||
|
||||
// speed in last full GPRMC sentence in 100ths of a knot
|
||||
inline unsigned long TinyGPS_speed() { return _speed; }
|
||||
|
||||
// satellites used in last full GPGGA sentence
|
||||
inline unsigned short TinyGPS_satellites() { return _numsats; }
|
||||
|
||||
// horizontal dilution of precision in 100ths
|
||||
inline unsigned long TinyGPS_hdop() { return _hdop; }
|
||||
|
||||
int TinyGPS_library_version() { return _GPS_VERSION; }
|
|
@ -37,8 +37,8 @@
|
|||
//const Gpio_Pin FINGER_PRINT_BUTTON = { GPIOB, GPIO_Pin_6 };
|
||||
|
||||
//const Gpio_Pin LOW_BAT = { GPIOB, GPIO_Pin_8 };
|
||||
//const Gpio_Pin RX_TO_GPS = { GPIOB, GPIO_Pin_10 };
|
||||
//const Gpio_Pin TX_FROM_GPS = { GPIOB, GPIO_Pin_11 };
|
||||
const Gpio_Pin RX_TO_GPS = { GPIOB, GPIO_PIN_6 };
|
||||
const Gpio_Pin TX_FROM_GPS = { GPIOB, GPIO_PIN_7 };
|
||||
|
||||
|
||||
|
||||
|
@ -127,9 +127,10 @@ const Gpio_Pin KEY2 = { GPIOD, GPIO_PIN_11 };
|
|||
//const Gpio_Pin POWER_GOOD = { GPIOC, GPIO_Pin_14 };
|
||||
//const Gpio_Pin POWER_SWITCH = { GPIOC, GPIO_Pin_15 };
|
||||
//const Gpio_Pin ACCEL_NSS = { GPIOD, GPIO_Pin_2 }; // currently labeled SPI2_NSS on schem
|
||||
//const Gpio_Pin GPS_RESET = { GPIOC, GPIO_Pin_4 };
|
||||
//const Gpio_Pin GPS_FIX_LED = { GPIOC, GPIO_Pin_3 };
|
||||
//const Gpio_Pin GPS_PPS = { GPIOC, GPIO_Pin_2 };
|
||||
const Gpio_Pin GPS_RESET = { GPIOD, GPIO_PIN_1 };
|
||||
const Gpio_Pin GPS_FIX_LED = { GPIOD, GPIO_PIN_3 };
|
||||
const Gpio_Pin GPS_PPS = { GPIOD, GPIO_PIN_4 };
|
||||
const Gpio_Pin GPS_POWER = { GPIOD, GPIO_PIN_0 };
|
||||
|
||||
//// timer pins
|
||||
//const Timer_Pin LED_G =
|
||||
|
@ -677,21 +678,33 @@ void hal_setupPins(void)
|
|||
// gpioInitStructure.GPIO_Mode = GPIO_Mode_IPD;
|
||||
// GPIO_Init(NC_1.port, &gpioInitStructure);
|
||||
|
||||
// gpioInitStructure.GPIO_Pin = GPS_RESET.pin;
|
||||
// gpioInitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
// gpioInitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //I don't know if the module has ANYTHING hooked up to these pins yet.
|
||||
// GPIO_Init(GPS_RESET.port, &gpioInitStructure);
|
||||
gpioInitStructure.Pin = GPS_POWER.pin;
|
||||
gpioInitStructure.Speed = GPIO_SPEED_LOW;
|
||||
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP; //I don't know if the module has ANYTHING hooked up to these pins yet.
|
||||
gpioInitStructure.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPS_POWER.port, &gpioInitStructure);
|
||||
HAL_GPIO_WritePin(GPS_POWER.port, GPS_POWER.pin, 0); //
|
||||
|
||||
// gpioInitStructure.GPIO_Pin = GPS_FIX_LED.pin;
|
||||
// gpioInitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
// gpioInitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //I don't know if the module has ANYTHING hooked up to these pins yet.
|
||||
// GPIO_Init(GPS_FIX_LED.port, &gpioInitStructure);
|
||||
gpioInitStructure.Pin = GPS_RESET.pin;
|
||||
gpioInitStructure.Speed = GPIO_SPEED_LOW;
|
||||
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP; //I don't know if the module has ANYTHING hooked up to these pins yet.
|
||||
gpioInitStructure.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPS_RESET.port, &gpioInitStructure);
|
||||
HAL_GPIO_WritePin(GPS_POWER.port, GPS_POWER.pin, 0);
|
||||
|
||||
// gpioInitStructure.GPIO_Pin = GPS_PPS.pin;
|
||||
// gpioInitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
// gpioInitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //I don't know if the module has ANYTHING hooked up to these pins yet.
|
||||
// GPIO_Init(GPS_PPS.port, &gpioInitStructure);
|
||||
gpioInitStructure.Pin = GPS_FIX_LED.pin;
|
||||
gpioInitStructure.Speed = GPIO_SPEED_LOW;
|
||||
gpioInitStructure.Mode = GPIO_MODE_INPUT; //I don't know if the module has ANYTHING hooked up to these pins yet.
|
||||
gpioInitStructure.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPS_FIX_LED.port, &gpioInitStructure);
|
||||
|
||||
gpioInitStructure.Pin = GPS_PPS.pin;
|
||||
gpioInitStructure.Speed = GPIO_SPEED_LOW;
|
||||
gpioInitStructure.Mode = GPIO_MODE_INPUT; //I don't know if the module has ANYTHING hooked up to these pins yet.
|
||||
gpioInitStructure.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPS_PPS.port, &gpioInitStructure);
|
||||
}
|
||||
|
||||
//
|
||||
//void hal_timerSetCompare(const Timer_Channel* timer, uint16_t value)
|
||||
//{
|
||||
|
@ -781,22 +794,22 @@ void hal_setupPins(void)
|
|||
// NVIC_InitTypeDef nvicInitStructure;
|
||||
//
|
||||
// // Finger Print UART Input / Output GPIO
|
||||
// gpioInitStructure.GPIO_Pin = FPR_TX.pin;
|
||||
// gpioInitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
// gpioInitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
// GPIO_Init(FPR_TX.port, &gpioInitStructure);
|
||||
// gpioInitStructure.Pin = TX_FROM_GPS.pin;
|
||||
// gpioInitStructure.Speed = GPIO_SPEED_LOW;
|
||||
// gpioInitStructure.Mode = GPIO_MODE_INPUT;
|
||||
// GPIO_Init(TX_FROM_GPS.port, &gpioInitStructure);
|
||||
//
|
||||
// gpioInitStructure.GPIO_Pin = FPR_RX.pin;
|
||||
// gpioInitStructure.GPIO_Speed = GPIO_Speed_2MHz; // TBD
|
||||
// gpioInitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
// GPIO_Init(FPR_RX.port, &gpioInitStructure);
|
||||
// GPIO_WriteBit(FPR_RX.port, FPR_RX.pin, 0);
|
||||
// gpioInitStructure.Pin = RX_TO_GPS.pin;
|
||||
// gpioInitStructure.Speed = GPIO_SPEED_MEDIUM; // TBD
|
||||
// gpioInitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
// GPIO_Init(RX_TO_GPS.port, &gpioInitStructure);
|
||||
// HAL_GPIO_WritePin(RX_TO_GPS.port, RX_TO_GPS.pin, 0);
|
||||
//
|
||||
// // Usart 1
|
||||
// USART_StructInit(&usartInitStructure);
|
||||
// usartInitStructure.USART_BaudRate = 9600; // TODO - fpr define
|
||||
// usartInitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
// USART_Init(USART1, &usartInitStructure);
|
||||
// HAL_USART_DeInit(&usartInitStructure);
|
||||
// usartInitStructure.BaudRate = 9600; // TODO - fpr define
|
||||
// usartInitStructure.Mode = USART_MODE_TX_RX;
|
||||
// HAL_USART_Init(USART1, &usartInitStructure);
|
||||
//
|
||||
// // Setup USART1 Interrupts
|
||||
// nvicInitStructure.NVIC_IRQChannel = USART1_IRQn;
|
||||
|
@ -806,10 +819,10 @@ void hal_setupPins(void)
|
|||
// NVIC_Init(&nvicInitStructure);
|
||||
//
|
||||
// // enable usart and rx interrupt
|
||||
// USART_Cmd(USART1, ENABLE);
|
||||
// USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
||||
// //HAL_U USART_Cmd(USART1, ENABLE);
|
||||
// //USART_ITConfig(USART1 , ENABLE);
|
||||
//}
|
||||
//
|
||||
|
||||
//void hal_resetUart1(void)
|
||||
//{
|
||||
// NVIC_InitTypeDef nvicInitStructure;
|
||||
|
|
|
@ -92,6 +92,8 @@ float fftMaxMaxMin = 0.2;
|
|||
int transmitting = 0;
|
||||
unsigned int tone = 0;
|
||||
|
||||
uint8_t displayUpdating = 0;
|
||||
|
||||
/** System Clock Configuration
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
|
@ -264,8 +266,69 @@ void setupPeripheralPower()
|
|||
__GPIOC_CLK_ENABLE();
|
||||
__GPIOD_CLK_ENABLE();
|
||||
__GPIOE_CLK_ENABLE();
|
||||
__DMA1_CLK_ENABLE();
|
||||
__DMA2_CLK_ENABLE();
|
||||
}
|
||||
|
||||
void configDMA(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
static DMA_HandleTypeDef hdma_tx;
|
||||
static DMA_HandleTypeDef hdma_rx;
|
||||
|
||||
|
||||
hdma_tx.Instance = SPIx_TX_DMA_STREAM;
|
||||
|
||||
hdma_tx.Init.Channel = SPIx_TX_DMA_CHANNEL;
|
||||
hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_tx.Init.Mode = DMA_NORMAL;
|
||||
hdma_tx.Init.Priority = DMA_PRIORITY_LOW;
|
||||
hdma_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
||||
hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||||
hdma_tx.Init.MemBurst = DMA_MBURST_INC4;
|
||||
hdma_tx.Init.PeriphBurst = DMA_PBURST_INC4;
|
||||
|
||||
HAL_DMA_Init(&hdma_tx);
|
||||
|
||||
/* Associate the initialized DMA handle to the the SPI handle */
|
||||
__HAL_LINKDMA(hspi, hdmatx, hdma_tx);
|
||||
|
||||
/* Configure the DMA handler for Transmission process */
|
||||
hdma_rx.Instance = SPIx_RX_DMA_STREAM;
|
||||
|
||||
hdma_rx.Init.Channel = SPIx_RX_DMA_CHANNEL;
|
||||
hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_rx.Init.Mode = DMA_NORMAL;
|
||||
hdma_rx.Init.Priority = DMA_PRIORITY_HIGH;
|
||||
hdma_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
||||
hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||||
hdma_rx.Init.MemBurst = DMA_MBURST_INC4;
|
||||
hdma_rx.Init.PeriphBurst = DMA_PBURST_INC4;
|
||||
|
||||
HAL_DMA_Init(&hdma_rx);
|
||||
|
||||
/* Associate the initialized DMA handle to the the SPI handle */
|
||||
__HAL_LINKDMA(hspi, hdmarx, hdma_rx);
|
||||
|
||||
/*##-4- Configure the NVIC for DMA #########################################*/
|
||||
/* NVIC configuration for DMA transfer complete interrupt (SPI3_TX) */
|
||||
HAL_NVIC_SetPriority(15/*SPIx_DMA_TX_IRQn*/, 0, 1);
|
||||
HAL_NVIC_EnableIRQ(SPIx_DMA_TX_IRQn);
|
||||
|
||||
/* NVIC configuration for DMA transfer complete interrupt (SPI3_RX) */
|
||||
HAL_NVIC_SetPriority(SPIx_DMA_RX_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(SPIx_DMA_RX_IRQn);
|
||||
|
||||
|
||||
//HAL_DMA_Start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -308,27 +371,30 @@ int isFwd;
|
|||
|
||||
void Tick(void)
|
||||
{
|
||||
Position2 = (HAL_GPIO_ReadPin(encoderB.port, encoderB.pin) * 2) + HAL_GPIO_ReadPin(encoderA.port, encoderA.pin);;
|
||||
if (Position2 != Position)
|
||||
if(!displayUpdating)
|
||||
{
|
||||
isFwd = ((Position == 0) && (Position2 == 1)) || ((Position == 1) && (Position2 == 3)) ||
|
||||
((Position == 3) && (Position2 == 2)) || ((Position == 2) && (Position2 == 0));
|
||||
if (!HAL_GPIO_ReadPin(encoderP.port, encoderP.pin))
|
||||
Position2 = (HAL_GPIO_ReadPin(encoderB.port, encoderB.pin) * 2) + HAL_GPIO_ReadPin(encoderA.port, encoderA.pin);;
|
||||
if (Position2 != Position)
|
||||
{
|
||||
if (isFwd) menuEncoderTicks += 1;
|
||||
else menuEncoderTicks -= 1;
|
||||
menuPos = menuEncoderTicks/2;
|
||||
menuPos = menuPos % menuCount;
|
||||
isFwd = ((Position == 0) && (Position2 == 1)) || ((Position == 1) && (Position2 == 3)) ||
|
||||
((Position == 3) && (Position2 == 2)) || ((Position == 2) && (Position2 == 0));
|
||||
if (!HAL_GPIO_ReadPin(encoderP.port, encoderP.pin))
|
||||
{
|
||||
if (isFwd) menuEncoderTicks += 1;
|
||||
else menuEncoderTicks -= 1;
|
||||
menuPos = menuEncoderTicks/2;
|
||||
menuPos = menuPos % menuCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isFwd) Pos++;
|
||||
else Pos--;
|
||||
}
|
||||
//if (Pos < Min) Pos = Min;
|
||||
//if (Pos > Max) Pos = Max;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isFwd) Pos++;
|
||||
else Pos--;
|
||||
}
|
||||
//if (Pos < Min) Pos = Min;
|
||||
//if (Pos > Max) Pos = Max;
|
||||
Position = Position2;
|
||||
}
|
||||
Position = Position2;
|
||||
}
|
||||
|
||||
int getPos(void)
|
||||
|
@ -624,6 +690,9 @@ main(int argc, char* argv[])
|
|||
hal_setupPins();
|
||||
spi_init();
|
||||
|
||||
configDMA(&SpiHandle );
|
||||
|
||||
|
||||
timer_start();
|
||||
|
||||
blink_led_init();
|
||||
|
@ -636,8 +705,28 @@ main(int argc, char* argv[])
|
|||
|
||||
Adafruit_ILI9340_begin();
|
||||
Adafruit_ILI9340_setRotation(1);
|
||||
//Adafruit_GFX_fillScreen(ILI9340_BLACK);
|
||||
Adafruit_GFX_fillScreen(ILI9340_BLACK);
|
||||
Adafruit_GFX_fillScreen(ILI9340_BLACK);
|
||||
|
||||
//drawNextPixel test
|
||||
// Adafruit_ILI9340_drawPixel(100,100,ILI9340_CYAN);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_BLUE);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_RED);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_WHITE);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_YELLOW);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_CYAN);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_RED);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_BLUE);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_RED);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_WHITE);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_YELLOW);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_CYAN);
|
||||
// Adafruit_ILI9340_drawNextPixel(ILI9340_RED);
|
||||
|
||||
|
||||
// while(1);
|
||||
|
||||
|
||||
Adafruit_GFX_setTextSize(3);
|
||||
Adafruit_GFX_setTextWrap(1);
|
||||
Adafruit_GFX_setTextColor(ILI9340_WHITE, ILI9340_BLACK);
|
||||
|
@ -655,6 +744,8 @@ main(int argc, char* argv[])
|
|||
|
||||
updateDisplay(1);
|
||||
|
||||
|
||||
|
||||
setGainPot(128, 128);
|
||||
|
||||
//MAIN LOOP - Lowest Priority
|
||||
|
@ -816,8 +907,15 @@ float calculateRmsOfSample(float* samples, int length)
|
|||
|
||||
#define freqVOffset 108 //120 - (8*3/2)
|
||||
#define freqHOffset 142
|
||||
|
||||
|
||||
//TODO: Should I make a menuItem struct? Would that be helpful? The menus are a pain right now...
|
||||
uint8_t redItems[30];
|
||||
|
||||
|
||||
void updateDisplay(uint8_t force)
|
||||
{
|
||||
displayUpdating = 1;
|
||||
static char freqChar[14];
|
||||
static char lastFreqChar[] = {'$','$','$','$','$','$','$','$','$','$','$','$','$','$',};
|
||||
|
||||
|
@ -836,11 +934,11 @@ void updateDisplay(uint8_t force)
|
|||
sprintf(&freqChar, "%8d", vfoAFrequency);
|
||||
|
||||
//So on each of these elements, we update when the value changes, when we're forced to, when the item becomes selected, or unselected.
|
||||
if(freqChar[0] != lastFreqChar[0] || force || (menuPos != menuLastPos && (menuPos == 0 || menuLastPos == 0)))
|
||||
if(freqChar[0] != lastFreqChar[0] || force || (menuPos != menuLastPos && (menuPos == 0 || menuLastPos == 0)))
|
||||
{
|
||||
drawNumber(freqChar[0], freqHOffset + 16*0, freqVOffset + 0, menuPos == 0 ? MASKRED : MASKWHITE);
|
||||
}
|
||||
if(freqChar[1] != lastFreqChar[1] || force || (menuPos != menuLastPos && (menuPos == 0 || menuLastPos == 0)))
|
||||
if(freqChar[1] != lastFreqChar[1] || redItems[0] || force || (menuPos != menuLastPos && (menuPos == 0 || menuLastPos == 0)))
|
||||
{
|
||||
drawNumber(freqChar[1], freqHOffset + 16*1, freqVOffset + 0, menuPos == 0 ? MASKRED : MASKWHITE);
|
||||
}
|
||||
|
@ -926,11 +1024,13 @@ void updateDisplay(uint8_t force)
|
|||
}
|
||||
|
||||
modeLast = mode;
|
||||
|
||||
}
|
||||
|
||||
if(afGain * 0.99 )
|
||||
|
||||
menuLastPos = menuPos;
|
||||
displayUpdating = 0;
|
||||
}
|
||||
|
||||
void drawWaterfall()
|
||||
|
@ -972,18 +1072,22 @@ void drawWaterfall()
|
|||
// but now narrow signal can disappear when they are right at the center....
|
||||
// Will that be better when I lower the sample frequency? Maybe I should do that next.
|
||||
|
||||
for(i = 1; i < 120; i++)
|
||||
Adafruit_ILI9340_setAddrWindow(waterfallScanLine, 0, waterfallScanLine, 120);
|
||||
for(i = 120; i != 0; i--)
|
||||
{
|
||||
mags = (log2(magnitudes[i] + 1)) / fftMaxMax * 100; //Log needs to be at least 1 right? We could do a + (1-fftMin) maybe? Worth it?
|
||||
//mags = magnitudes[i] / fftMaxMax * 32;
|
||||
Adafruit_ILI9340_drawPixel(waterfallScanLine, (120 - i), gradient[(uint8_t) mags]);
|
||||
//Adafruit_ILI9340_drawPixel(waterfallScanLine, (120 - i), gradient[(uint8_t) mags]);
|
||||
Adafruit_ILI9340_pushColor(gradient[(uint8_t) mags]);
|
||||
}
|
||||
|
||||
for(i = 135; i < 255; i++)
|
||||
Adafruit_ILI9340_setAddrWindow(waterfallScanLine, 120, waterfallScanLine, 239);
|
||||
for(i = 255; i > 135; i--)
|
||||
{
|
||||
mags = (log2(magnitudes[i] + 1)) / fftMaxMax * 100;
|
||||
//mags = magnitudes[i] / fftMaxMax * 32;
|
||||
Adafruit_ILI9340_drawPixel(waterfallScanLine, 359 - (i - 15), gradient[(uint8_t) mags]);
|
||||
//Adafruit_ILI9340_drawPixel(waterfallScanLine, 359 - (i - 15), gradient[(uint8_t) mags]);
|
||||
Adafruit_ILI9340_pushColor(gradient[(uint8_t) mags]);
|
||||
}
|
||||
|
||||
waterfallScanLine++;
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
/* queue.c
|
||||
*
|
||||
* queue / circular buffer
|
||||
*
|
||||
* Copyright 2013 RPH Engineering, VPI Engineering
|
||||
*/
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
|
||||
|
||||
void queue8_init(Queue8* queue, uint8_t* dataPtr, uint8_t size)
|
||||
{
|
||||
// initialize a Queue8
|
||||
|
||||
queue->qCount = 0;
|
||||
queue->size = size;
|
||||
queue->readIndex = 0;
|
||||
queue->writeIndex = 0;
|
||||
queue->data = dataPtr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool queue8_isQFull(Queue8* queue)
|
||||
{
|
||||
// return true if the Q is full, else false
|
||||
|
||||
return queue->qCount == queue->size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool queue8_isQEmpty(Queue8* queue)
|
||||
{
|
||||
// return true if the Q is empty, else false
|
||||
|
||||
return queue->qCount == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int queue8_enqueue(Queue8* queue, uint8_t data)
|
||||
{
|
||||
// enqueue data on queue
|
||||
// returns 0 on success, negative o/w
|
||||
|
||||
int status = 0;
|
||||
|
||||
//if( queue->qCount == queue->size )
|
||||
if( (queue->readIndex == 0 && queue->writeIndex == queue->size - 1)
|
||||
|| (queue->writeIndex + 1) == queue->readIndex
|
||||
)
|
||||
{
|
||||
status = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->data[queue->writeIndex] = data;
|
||||
if( ++queue->writeIndex >= queue->size )
|
||||
queue->writeIndex = 0;
|
||||
|
||||
//++queue->qCount;
|
||||
}
|
||||
|
||||
//Am I wrong that nothing was ever updating the count?
|
||||
queue->qCount = queue8_getCount(queue);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int queue8_dequeue(Queue8* queue, uint8_t* data)
|
||||
{
|
||||
// pull a byte of data off queue and put it in *data
|
||||
// returns 0 on success, negative o/w
|
||||
|
||||
int status = 0;
|
||||
|
||||
//if( queue->qCount == 0 )
|
||||
if( queue->readIndex == queue->writeIndex )
|
||||
{
|
||||
status = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*data = queue->data[queue->readIndex];
|
||||
if( ++queue->readIndex >= queue->size )
|
||||
queue->readIndex = 0;
|
||||
|
||||
//--queue->qCount;
|
||||
}
|
||||
|
||||
//Am I wrong that nothing was ever updating the count?
|
||||
queue->qCount = queue8_getCount(queue);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void queue8_purge(Queue8* queue)
|
||||
{
|
||||
// purge a q
|
||||
|
||||
queue->qCount = 0;
|
||||
queue->readIndex = 0;
|
||||
queue->writeIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int queue8_getCount(Queue8* queue)
|
||||
{
|
||||
// get the count of entries in the q
|
||||
|
||||
int count;
|
||||
|
||||
if( queue->readIndex <= queue->writeIndex )
|
||||
count = queue->writeIndex - queue->readIndex;
|
||||
else
|
||||
count = queue->size - queue->readIndex + queue->writeIndex;
|
||||
|
||||
return count;
|
||||
}
|
|
@ -66,7 +66,7 @@ void spi_init(void)
|
|||
SpiHandle.Instance = SPI1;
|
||||
SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
SpiHandle.Init.Mode = SPI_MODE_MASTER;
|
||||
SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT; //Was 8BIT
|
||||
SpiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||
SpiHandle.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||
SpiHandle.Init.NSS = SPI_NSS_SOFT; //SPI_NSS_SOFT;
|
||||
|
@ -109,10 +109,17 @@ void spi_init(void)
|
|||
// spi2Semaphore = 1;
|
||||
//}
|
||||
|
||||
void spi_readWrite(SPI_HandleTypeDef SpiH, uint8_t* rxBuf, uint8_t* txBuf, int cnt)
|
||||
uint8_t txTmp[] = {0,0};
|
||||
void spi_readWrite(SPI_HandleTypeDef SpiH, uint16_t* rxBuf, uint16_t* txBuf, uint16_t cnt)
|
||||
{
|
||||
txTmp[0] = txBuf[0] >> 8;
|
||||
txTmp[1] = txBuf[0] & 0xFF;
|
||||
|
||||
//HAL_SPI_TransmitReceive(&SpiHandle, txBuf, rxBuf, cnt, 1000);
|
||||
HAL_SPI_Transmit(&SpiHandle, txBuf, cnt, 1);
|
||||
HAL_SPI_Transmit(&SpiHandle, txTmp, 2 /*cnt * 2*/, 1);
|
||||
//while(HAL_SPI_GetState(&SpiH) != HAL_SPI_STATE_READY);
|
||||
//HAL_SPI_Transmit_DMA(&SpiH, txBuf, cnt);
|
||||
//while(HAL_SPI_GetState(&SpiH) != HAL_SPI_STATE_READY);
|
||||
|
||||
// //High, second edge
|
||||
// //We're going to bitbang it for now, I guess
|
||||
|
|
|
@ -175,6 +175,16 @@ processStream();
|
|||
//__HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
void SPIx_DMA_TX_IRQHandler(void)
|
||||
{
|
||||
HAL_DMA_IRQHandler(SpiHandle.hdmatx);
|
||||
}
|
||||
|
||||
void SPIx_DMA_RX_IRQHandler(void)
|
||||
{
|
||||
HAL_DMA_IRQHandler(SpiHandle.hdmarx);
|
||||
}
|
||||
|
||||
//void TIM3_IRQHandler(void)
|
||||
//{
|
||||
// __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
|
||||
|
|
|
@ -0,0 +1,560 @@
|
|||
/* uart.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include "uart.h"
|
||||
#include <queue.h>
|
||||
#include <hal.h>
|
||||
#include <stm32f4xx_hal_usart.h>
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
uart1TxBufferSize = 64,
|
||||
uart1RxBufferSize = 64,
|
||||
uart2TxBufferSize = 64,
|
||||
uart2RxBufferSize = 128,
|
||||
uart3TxBufferSize = 64,
|
||||
uart3RxBufferSize = 64
|
||||
};
|
||||
|
||||
|
||||
|
||||
static uint8_t uart1TxBuffer[uart1TxBufferSize];
|
||||
static uint8_t uart1RxBuffer[uart1RxBufferSize];
|
||||
static uint8_t uart2TxBuffer[uart2TxBufferSize];
|
||||
static uint8_t uart2RxBuffer[uart2RxBufferSize];
|
||||
static uint8_t uart3TxBuffer[uart3TxBufferSize];
|
||||
static uint8_t uart3RxBuffer[uart3RxBufferSize];
|
||||
|
||||
static Queue8 uart1TxQ;
|
||||
static Queue8 uart1RxQ;
|
||||
static Queue8 uart2TxQ;
|
||||
static Queue8 uart2RxQ;
|
||||
static Queue8 uart3TxQ;
|
||||
static Queue8 uart3RxQ;
|
||||
|
||||
static bool uart1TxPrimed; // is uart tx reg empty interrupt enabled
|
||||
static bool uart2TxPrimed;
|
||||
static bool uart3TxPrimed;
|
||||
static bool uart1RxOverflow; // overlow in uart rx Q (currently set but not used)
|
||||
static bool uart2RxOverflow;
|
||||
static bool uart3RxOverflow;
|
||||
|
||||
|
||||
|
||||
int uart_putChar(uint8_t uart, char c)
|
||||
{
|
||||
// enqueue a char to a uart
|
||||
// returns 0 on success
|
||||
|
||||
int status;
|
||||
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
status = queue8_enqueue(&uart1TxQ, (uint8_t)c);
|
||||
|
||||
if( !uart1TxPrimed )
|
||||
{
|
||||
uart1TxPrimed = true;
|
||||
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
|
||||
}
|
||||
|
||||
break;
|
||||
case uart_uart2:
|
||||
status = queue8_enqueue(&uart2TxQ, (uint8_t)c);
|
||||
|
||||
if( !uart2TxPrimed )
|
||||
{
|
||||
uart2TxPrimed = true;
|
||||
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
|
||||
}
|
||||
break;
|
||||
case uart_uart3:
|
||||
status = queue8_enqueue(&uart3TxQ, (uint8_t)c);
|
||||
|
||||
if( !uart3TxPrimed )
|
||||
{
|
||||
uart3TxPrimed = true;
|
||||
USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
status = -1;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int uart_getChar(uint8_t uart, char* c)
|
||||
{
|
||||
// dequeue a char from a uart and put it in *c
|
||||
// returns 0 on success
|
||||
|
||||
int status;
|
||||
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
status = queue8_dequeue(&uart1RxQ, (uint8_t*)c);
|
||||
break;
|
||||
case uart_uart2:
|
||||
status = queue8_dequeue(&uart2RxQ, (uint8_t*)c);
|
||||
break;
|
||||
case uart_uart3:
|
||||
status = queue8_dequeue(&uart3RxQ, (uint8_t*)c);
|
||||
break;
|
||||
default:
|
||||
status = -1;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int uart_write(uint8_t uart, uint8_t* buffer, uint8_t size)
|
||||
{
|
||||
// write a buffer of data to a uart
|
||||
// return the number of bytes written
|
||||
|
||||
int status;
|
||||
uint8_t bytes = 0;
|
||||
Queue8* queue = 0;
|
||||
|
||||
USART_TypeDef* usart;
|
||||
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
queue = &uart1TxQ;
|
||||
uart1TxPrimed = true;
|
||||
usart = USART1;
|
||||
break;
|
||||
case uart_uart2:
|
||||
queue = &uart2TxQ;
|
||||
uart2TxPrimed = true;
|
||||
usart = USART2;
|
||||
break;
|
||||
case uart_uart3:
|
||||
queue = &uart3TxQ;
|
||||
uart3TxPrimed = true;
|
||||
usart = USART3;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if( queue )
|
||||
{
|
||||
uint8_t* bufferPtr = buffer;
|
||||
|
||||
for( bytes = 0; bytes < size; ++bytes )
|
||||
{
|
||||
status = queue8_enqueue(queue, *bufferPtr++);
|
||||
if( status )
|
||||
break;
|
||||
}
|
||||
|
||||
USART_ITConfig(usart, USART_IT_TXE, ENABLE);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int uart_read(uint8_t uart, uint8_t* buffer, uint8_t size)
|
||||
{
|
||||
// try to read size bytes of data into buffer from a uart
|
||||
// return the number of bytes read
|
||||
|
||||
int status;
|
||||
uint8_t bytes = 0;
|
||||
Queue8* queue = 0;
|
||||
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
queue = &uart1RxQ;
|
||||
break;
|
||||
case uart_uart2:
|
||||
queue = &uart2RxQ;
|
||||
break;
|
||||
case uart_uart3:
|
||||
queue = &uart3RxQ;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if( queue )
|
||||
{
|
||||
uint8_t* bufferPtr = buffer;
|
||||
|
||||
for( bytes = 0; bytes < size; ++bytes )
|
||||
{
|
||||
status = queue8_dequeue(queue, bufferPtr);
|
||||
if( status )
|
||||
break;
|
||||
|
||||
++bufferPtr;
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void uart_init(uint8_t uart)
|
||||
{
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
// setup data structures
|
||||
queue8_init(&uart1TxQ, uart1TxBuffer, uart1TxBufferSize);
|
||||
queue8_init(&uart1RxQ, uart1RxBuffer, uart1RxBufferSize);
|
||||
|
||||
// init h/w
|
||||
hal_setupUart1();
|
||||
|
||||
break;
|
||||
|
||||
case uart_uart2:
|
||||
queue8_init(&uart2TxQ, uart2TxBuffer, uart2TxBufferSize);
|
||||
queue8_init(&uart2RxQ, uart2RxBuffer, uart2RxBufferSize);
|
||||
|
||||
hal_setupUart2();
|
||||
|
||||
break;
|
||||
|
||||
case uart_uart3:
|
||||
queue8_init(&uart3TxQ, uart3TxBuffer, uart3TxBufferSize);
|
||||
queue8_init(&uart3RxQ, uart3RxBuffer, uart3RxBufferSize);
|
||||
|
||||
#ifdef SIRF_MODULE
|
||||
hal_setupUart3(4800);
|
||||
#endif
|
||||
#ifdef MEDIATEK_MODULE
|
||||
hal_setupUart3(9600);
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void uart_deinit(uint8_t uart)
|
||||
{
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
hal_resetUart1();
|
||||
|
||||
break;
|
||||
|
||||
case uart_uart2:
|
||||
hal_resetUart2();
|
||||
|
||||
break;
|
||||
|
||||
case uart_uart3:
|
||||
hal_resetUart3();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void uart_enable(uint8_t uart)
|
||||
{
|
||||
// enable a uart, enables rxne interrupt, does not set other config info
|
||||
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
USART_Cmd(USART1, ENABLE);
|
||||
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
||||
break;
|
||||
case uart_uart2:
|
||||
USART_Cmd(USART2, ENABLE);
|
||||
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
|
||||
break;
|
||||
case uart_uart3:
|
||||
USART_Cmd(USART3, ENABLE);
|
||||
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void uart_disable(uint8_t uart)
|
||||
{
|
||||
// disable a uart and the uart rxne and txe itnerrupts but leave registers setup
|
||||
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
|
||||
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
|
||||
USART_Cmd(USART1, DISABLE);
|
||||
break;
|
||||
case uart_uart2:
|
||||
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
|
||||
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
|
||||
USART_Cmd(USART2, DISABLE);
|
||||
break;
|
||||
case uart_uart3:
|
||||
USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
|
||||
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
|
||||
USART_Cmd(USART3, DISABLE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void uart_purgeRxQueue(uint8_t uart)
|
||||
{
|
||||
// purge the rx q for uart
|
||||
|
||||
Queue8* queue = 0;
|
||||
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
queue = &uart1RxQ;
|
||||
break;
|
||||
case uart_uart2:
|
||||
queue = &uart2RxQ;
|
||||
break;
|
||||
case uart_uart3:
|
||||
queue = &uart3RxQ;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
queue8_purge(queue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int uart_getRxQueueCount(uint8_t uart)
|
||||
{
|
||||
// get the count for the rx q for uart
|
||||
|
||||
int count;
|
||||
Queue8* queue = 0;
|
||||
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
queue = &uart1RxQ;
|
||||
break;
|
||||
case uart_uart2:
|
||||
queue = &uart2RxQ;
|
||||
break;
|
||||
case uart_uart3:
|
||||
queue = &uart3RxQ;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
count = queue8_getCount(queue);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
//Checks for a particular character within a Queue
|
||||
//Does not dequeueueue
|
||||
int uart_queueHasChar(char c, uint8_t uart)
|
||||
{
|
||||
Queue8* queue = 0;
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
queue = &uart1RxQ;
|
||||
break;
|
||||
case uart_uart2:
|
||||
queue = &uart2RxQ;
|
||||
break;
|
||||
case uart_uart3:
|
||||
queue = &uart3RxQ;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//I think this has a bug where if the queue is empty (ie pRD == pWR) it scans through the whole queue intead of returning immediately.
|
||||
//Since the queue may actually contain the desired char in it's currently unused spaces, this returns true, but since the dequeue function
|
||||
//doesn't remove them, the while loops that this function is placed in never release.
|
||||
if(queue->qCount == 0)
|
||||
return false;
|
||||
|
||||
uint8_t i = 0;
|
||||
for(i = queue->readIndex; i != queue->writeIndex; i++)
|
||||
{
|
||||
i = i % queue->size;
|
||||
if(queue->data[i] == c) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int uart_queueContains(char thingToFind[], int thingToFindLength, uint8_t uart)
|
||||
{
|
||||
Queue8* queue = 0;
|
||||
switch( uart )
|
||||
{
|
||||
case uart_uart1:
|
||||
queue = &uart1RxQ;
|
||||
break;
|
||||
case uart_uart2:
|
||||
queue = &uart2RxQ;
|
||||
break;
|
||||
case uart_uart3:
|
||||
queue = &uart3RxQ;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t i = 0;
|
||||
int examinationIndex = 0;
|
||||
|
||||
for(i = queue->readIndex; i != queue->writeIndex; i++)
|
||||
{
|
||||
i = i % queue->size;
|
||||
if(queue->data[i] == thingToFind[examinationIndex])
|
||||
examinationIndex++;
|
||||
else
|
||||
examinationIndex = 0;
|
||||
if (examinationIndex >= thingToFindLength) //We've matched all the characters we were looking for, return true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
// uart 1 interrupt handler
|
||||
// this function name must match that in the startup file
|
||||
|
||||
// handle uart rx char
|
||||
if( USART_GetITStatus(USART1, USART_IT_RXNE) != RESET )
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
data = USART_ReceiveData(USART1) & 0xFF;
|
||||
if( queue8_enqueue(&uart1RxQ, data) )
|
||||
uart1RxOverflow = true;
|
||||
}
|
||||
|
||||
// handle uart tx char empty
|
||||
if( USART_GetITStatus(USART1, USART_IT_TXE) != RESET )
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
if( !queue8_dequeue(&uart1TxQ, &data) )
|
||||
{
|
||||
USART_SendData(USART1, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
|
||||
uart1TxPrimed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//void USART2_IRQHandler(void)
|
||||
//{
|
||||
// // uart 2 interrupt handler
|
||||
// // this function name must match that in the startup file
|
||||
//
|
||||
// // handle uart rx char
|
||||
// if( USART_GetITStatus(USART2, USART_IT_RXNE) != RESET )
|
||||
// {
|
||||
// uint8_t data;
|
||||
//
|
||||
// data = USART_ReceiveData(USART2) & 0xFF;
|
||||
// if( queue8_enqueue(&uart2RxQ, data) )
|
||||
// uart2RxOverflow = true;
|
||||
// }
|
||||
//
|
||||
// // handle uart tx char empty
|
||||
// if( USART_GetITStatus(USART2, USART_IT_TXE) != RESET )
|
||||
// {
|
||||
// uint8_t data;
|
||||
//
|
||||
// if( !queue8_dequeue(&uart2TxQ, &data) )
|
||||
// {
|
||||
// USART_SendData(USART2, data);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
|
||||
// uart2TxPrimed = false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//void USART3_IRQHandler(void)
|
||||
//{
|
||||
// // uart 3 interrupt handler
|
||||
// // this function name must match that in the startup file
|
||||
//
|
||||
// // handle uart rx char
|
||||
// if( USART_GetITStatus(USART3, USART_IT_RXNE) != RESET )
|
||||
// {
|
||||
// uint8_t data;
|
||||
//
|
||||
// data = USART_ReceiveData(USART3) & 0xFF;
|
||||
// if( queue8_enqueue(&uart3RxQ, data) )
|
||||
// uart3RxOverflow = true;
|
||||
// }
|
||||
//
|
||||
// // handle uart tx char empty
|
||||
// if( USART_GetITStatus(USART3, USART_IT_TXE) != RESET )
|
||||
// {
|
||||
// uint8_t data;
|
||||
//
|
||||
// if( !queue8_dequeue(&uart3TxQ, &data) )
|
||||
// {
|
||||
// USART_SendData(USART3, data); HAL_USART_Transmit()
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
|
||||
// uart3TxPrimed = false;
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx_hal_def.h"
|
||||
#include "stm32f4xx_hal_dma.h"
|
||||
|
||||
/** @addtogroup STM32F4xx_HAL_Driver
|
||||
* @{
|
||||
|
@ -151,9 +152,9 @@ typedef struct __SPI_HandleTypeDef
|
|||
|
||||
uint16_t RxXferCount; /* SPI Rx Transfer Counter */
|
||||
|
||||
//DMA_HandleTypeDef *hdmatx; /* SPI Tx DMA handle parameters */
|
||||
DMA_HandleTypeDef *hdmatx; /* SPI Tx DMA handle parameters */
|
||||
|
||||
//DMA_HandleTypeDef *hdmarx; /* SPI Rx DMA handle parameters */
|
||||
DMA_HandleTypeDef *hdmarx; /* SPI Rx DMA handle parameters */
|
||||
|
||||
void (*RxISR)(struct __SPI_HandleTypeDef * hspi); /* function pointer on Rx ISR */
|
||||
|
||||
|
|
Loading…
Reference in New Issue