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:
Michael Colton 2014-10-15 09:31:08 -06:00
parent f694e53e46
commit 46c832e409
22 changed files with 7514 additions and 8098 deletions

Binary file not shown.

View file

@ -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.

File diff suppressed because it is too large Load diff

View file

@ -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);

102
Source/include/TinyGPS.h Normal file
View file

@ -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

View file

@ -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;

View file

@ -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;

52
Source/include/queue.h Normal file
View file

@ -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_ */

View file

@ -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

65
Source/include/uart.h Normal file
View file

@ -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_ */

View file

@ -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

View file

@ -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);
}
}

609
Source/src/TinyGPS.c Normal file
View file

@ -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; }

View file

@ -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;

View file

@ -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;