[X9D] First compilation OK! Next step: integrate the code for the drivers (only LCD done) from FrSky...

This commit is contained in:
bsongis
2012-12-20 21:51:26 +00:00
parent 5f19f78509
commit e15654edad
762 changed files with 252758 additions and 1871 deletions
+17 -24
View File
@@ -113,7 +113,6 @@ inline uint8_t getAvailableFiles(char *prefix, FILINFO &info, char *filename)
void refreshModelAudioFiles()
{
#if 0
FILINFO info;
#if _USE_LFN
TCHAR lfn[_MAX_LFN + 1];
@@ -121,7 +120,7 @@ void refreshModelAudioFiles()
info.lfsize = sizeof(lfn);
#endif
char filename[32] = SOUNDS_PATH "/"; // TODO not 32!
char filename[64] = SOUNDS_PATH "/";
if (sd_card_mounted()) {
char *buf = strcat_modelname(&filename[sizeof(SOUNDS_PATH)], g_eeGeneral.currModel);
@@ -134,18 +133,20 @@ void refreshModelAudioFiles()
}
for (uint32_t i=0; i<MAX_MIXERS; i++) {
sdAvailableMixerAudioFiles[i] = getAvailableFiles(strcat_mixername_default(buf, i), info, filename) << 4;
char *tmp = strcat_mixername_nodefault(buf, i);
if (tmp != buf) sdAvailableMixerAudioFiles[i] += getAvailableFiles(tmp, info, filename);
sdAvailableMixerAudioFiles[i] = (tmp != buf ? getAvailableFiles(tmp, info, filename) : 0);
}
}
#endif
}
bool isAudioFileAvailable(uint32_t i, char * filename)
{
uint8_t category = (i >> 24);
#if defined(SIMU)
printf("isAudioFileAvailable(%08x)\n", i); fflush(stdout);
#endif
if (category == SYSTEM_AUDIO_CATEGORY) {
if (sdAvailableSystemAudioFiles & ((uint32_t)1 << i)) {
strcpy(filename, SYSTEM_SOUNDS_PATH "/");
@@ -154,7 +155,6 @@ bool isAudioFileAvailable(uint32_t i, char * filename)
return true;
}
}
#if 0
else if (category == PHASE_AUDIO_CATEGORY) {
uint8_t index = (i >> 16) & 0xFF;
uint8_t event = i & 0xFF;
@@ -162,7 +162,7 @@ bool isAudioFileAvailable(uint32_t i, char * filename)
strcpy(filename, SOUNDS_PATH "/");
char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel);
*str++ = '/';
char * tmp = strcat_phasename_nodefault(str, i);
char * tmp = strcat_phasename_nodefault(str, index);
if (tmp != str) {
strcpy(tmp, suffixes[event]);
strcat(tmp, SOUNDS_EXT);
@@ -173,7 +173,7 @@ bool isAudioFileAvailable(uint32_t i, char * filename)
strcpy(filename, SOUNDS_PATH "/");
char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel);
*str++ = '/';
char * tmp = strcat_phasename_default(str, i);
char * tmp = strcat_phasename_default(str, index);
if (tmp != str) {
strcpy(tmp, suffixes[event]);
strcat(tmp, SOUNDS_EXT);
@@ -188,18 +188,7 @@ bool isAudioFileAvailable(uint32_t i, char * filename)
strcpy(filename, SOUNDS_PATH "/");
char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel);
*str++ = '/';
char * tmp = strcat_mixername_nodefault(str, i);
if (tmp != str) {
strcpy(tmp, suffixes[event]);
strcat(tmp, SOUNDS_EXT);
return true;
}
}
else if ((sdAvailableMixerAudioFiles[index] >> 4) & (1 << event)) {
strcpy(filename, SOUNDS_PATH "/");
char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel);
*str++ = '/';
char * tmp = strcat_mixername_default(str, i);
char * tmp = strcat_mixername_nodefault(str, index);
if (tmp != str) {
strcpy(tmp, suffixes[event]);
strcat(tmp, SOUNDS_EXT);
@@ -207,7 +196,7 @@ bool isAudioFileAvailable(uint32_t i, char * filename)
}
}
}
#endif
return false;
}
#else
@@ -381,11 +370,11 @@ void AudioQueue::sdWakeup(AudioContext & context)
}
read /= 2;
register Dacc *dacptr = DACC;
#if defined(PCBSKY9X)
register Dacc *dacptr = DACC;
if (read) {
state = AUDIO_PLAYING_WAV;
if (dacptr->DACC_ISR & DACC_ISR_TXBUFE) {
dacptr->DACC_TPR = CONVERT_PTR(wavSamplesBuffer);
dacptr->DACC_TCR = read;
@@ -403,7 +392,6 @@ void AudioQueue::sdWakeup(AudioContext & context)
CoSetTmrCnt(audioTimer, (WAV_BUFFER_SIZE * 500) / context.pcmFreq, 0);
CoStartTmr(audioTimer);
}
wavSamplesBuffer += WAV_BUFFER_SIZE;
if (wavSamplesBuffer >= wavSamplesArray + 3 * WAV_BUFFER_SIZE)
wavSamplesBuffer = wavSamplesArray;
@@ -412,6 +400,7 @@ void AudioQueue::sdWakeup(AudioContext & context)
state = AUDIO_RESUMING;
CoSetFlag(audioFlag);
}
#endif
}
}
else {
@@ -439,11 +428,13 @@ void AudioQueue::wakeup()
if (state != AUDIO_PLAYING_TONE) {
state = AUDIO_PLAYING_TONE;
#if !defined(PCBX9D)
register Dacc *dacptr = DACC;
dacptr->DACC_TPR = CONVERT_PTR(Sine_values);
dacptr->DACC_TNPR = CONVERT_PTR(Sine_values);
dacptr->DACC_TCR = 50 ; // words, 100 16 bit values
dacptr->DACC_TNCR = 50 ; // words, 100 16 bit values
#endif
}
setFrequency(fragment.freq * 6100 / 4);
@@ -483,11 +474,13 @@ void AudioQueue::wakeup()
else if (ridx == widx && prioIdx < 0 && backgroundContext.fragment.duration > 0) {
if (state != AUDIO_PLAYING_TONE) {
state = AUDIO_PLAYING_TONE;
#if !defined(PCBX9D)
register Dacc *dacptr = DACC;
dacptr->DACC_TPR = CONVERT_PTR(Sine_values);
dacptr->DACC_TNPR = CONVERT_PTR(Sine_values);
dacptr->DACC_TCR = 50 ; // words, 100 16 bit values
dacptr->DACC_TNCR = 50 ; // words, 100 16 bit values
#endif
}
CoSetTmrCnt(audioTimer, backgroundContext.fragment.duration*2, 0);
backgroundContext.fragment.duration = 0;
+2 -4
View File
@@ -190,10 +190,8 @@ extern void pushPrompt(uint16_t prompt, uint8_t id=0);
#define PLAY_FILE(f, flags, id) audioQueue.playFile((f), (flags), (id))
#define STOP_PLAY(id) audioQueue.stopPlay((id))
#define AUDIO_RESET() audioQueue.reset()
#define PLAY_PHASE_OFF(phase)
// do { char filename[42/*TODO check*/]; if (isAudioFileAvailable((PHASE_AUDIO_CATEGORY << 24) + (phase << 16) + AUDIO_EVENT_OFF, filename)) audioQueue.playFile(filename); } while (0)
#define PLAY_PHASE_ON(phase)
// do { char filename[42]; if (isAudioFileAvailable((PHASE_AUDIO_CATEGORY << 24) + (phase << 16) + AUDIO_EVENT_ON, filename)) audioQueue.playFile(filename); } while (0)
#define PLAY_PHASE_OFF(phase) do { char filename[64]; if (isAudioFileAvailable((PHASE_AUDIO_CATEGORY << 24) + (phase << 16) + AUDIO_EVENT_OFF, filename)) audioQueue.playFile(filename); } while (0)
#define PLAY_PHASE_ON(phase) do { char filename[64]; if (isAudioFileAvailable((PHASE_AUDIO_CATEGORY << 24) + (phase << 16) + AUDIO_EVENT_ON, filename)) audioQueue.playFile(filename); } while (0)
extern void refreshSystemAudioFiles();
extern void refreshModelAudioFiles();
@@ -1,36 +1,35 @@
/****************************************************************************
* Copyright (c) 2011 by Michael Blandford. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
****************************************************************************
* History:
*
****************************************************************************/
/*
* Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de>
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
*/
#include "../open9x.h"
+75
View File
@@ -0,0 +1,75 @@
/*
* Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de>
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
*/
#ifndef audio_driver_h
#define audio_driver_h
#define NUM_VOL_LEVELS 24
extern void startSound( void ) ;
extern void buzzer_on( void ) ;
extern void buzzer_off( void ) ;
extern void buzzer_sound( uint8_t time ) ;
extern void setFrequency( uint32_t frequency ) ;
extern uint32_t getFrequency();
extern void start_timer1( void ) ;
extern void initDac( void ) ;
extern void end_sound( void ) ;
extern void write_coprocessor( uint8_t *ptr, uint32_t count ) ;
extern void read_coprocessor( bool onlytemp=false ) ;
extern uint8_t Coproc_read ;
extern int8_t Coproc_valid ;
extern int8_t Coproc_temp ;
extern int8_t Coproc_maxtemp ;
extern uint16_t *nextAudioData;
extern uint16_t nextAudioSize;
inline void toneStart()
{
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
DACC->DACC_IER = DACC_IER_ENDTX ;
}
inline void toneStop()
{
DACC->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt
}
extern volatile uint8_t Buzzer_count ;
extern void init_twi( void ) ;
extern void setVolume( register uint8_t volume ) ;
extern "C" void TWI0_IRQHandler (void) ;
#endif
+2 -5
View File
@@ -39,17 +39,14 @@
#include <stdint.h>
#include "chip.h"
#ifdef REVA
#if defined(REVA)
#include "AT91SAM3S2.h"
#else
#include "AT91SAM3S4.h"
#endif
#ifdef SIMU
#define CONVERT_PTR(x) ((uint32_t)(uint64_t)(x))
#else
#if !defined(SIMU)
#include "core_cm3.h"
#define CONVERT_PTR(x) ((uint32_t)(x))
#endif
//------------------------------------------------------------------------------
+271
View File
@@ -0,0 +1,271 @@
/*
* Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de>
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
*/
#include "../open9x.h"
uint32_t spi_PDC_action( register uint8_t *command, register uint8_t *tx, register uint8_t *rx, register uint32_t comlen, register uint32_t count )
{
#ifndef SIMU
register Spi *spiptr ;
register uint32_t condition ;
static uint8_t discard_rx_command[4] ;
// PMC->PMC_PCER0 |= 0x00200000L ; // Enable peripheral clock to SPI
Spi_complete = 0 ;
if ( comlen > 4 )
{
Spi_complete = 1 ;
return 0x4FFFF ;
}
condition = SPI_SR_TXEMPTY ;
spiptr = SPI ;
spiptr->SPI_CR = 1 ; // Enable
(void) spiptr->SPI_RDR ; // Dump any rx data
(void) spiptr->SPI_SR ; // Clear error flags
spiptr->SPI_RPR = (uint32_t)discard_rx_command ;
spiptr->SPI_RCR = comlen ;
if ( rx )
{
spiptr->SPI_RNPR = (uint32_t)rx ;
spiptr->SPI_RNCR = count ;
condition = SPI_SR_RXBUFF ;
}
spiptr->SPI_TPR = (uint32_t)command ;
spiptr->SPI_TCR = comlen ;
if ( tx )
{
spiptr->SPI_TNPR = (uint32_t)tx ;
}
else
{
spiptr->SPI_TNPR = (uint32_t)rx ;
}
spiptr->SPI_TNCR = count ;
spiptr->SPI_PTCR = SPI_PTCR_RXTEN | SPI_PTCR_TXTEN ; // Start transfers
// Wait for things to get started, avoids early interrupt
for ( count = 0 ; count < 1000 ; count += 1 )
{
if ( ( spiptr->SPI_SR & SPI_SR_TXEMPTY ) == 0 )
{
break ;
}
}
spiptr->SPI_IER = condition ;
#endif
return 0 ;
}
uint32_t spi_operation( register uint8_t *tx, register uint8_t *rx, register uint32_t count )
{
register Spi *spiptr;
register uint32_t result;
result = 0;
spiptr = SPI;
spiptr->SPI_CR = 1; // Enable
(void) spiptr->SPI_RDR; // Dump any rx data
while (count) {
result = 0;
while ((spiptr->SPI_SR & SPI_SR_TXEMPTY) == 0) {
// wait
if (++result > 10000) {
result = 0xFFFF;
break;
}
}
if (result > 10000) {
break;
}
spiptr->SPI_TDR = *tx++;
result = 0;
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
// wait for received
if (++result > 10000) {
result = 0x2FFFF;
break;
}
}
if (result > 10000) {
break;
}
*rx++ = spiptr->SPI_RDR;
count -= 1;
}
if (result <= 10000) {
result = 0;
}
spiptr->SPI_CR = 2; // Disable
return result ;
}
uint32_t eeprom_write_one(uint8_t byte, uint8_t count)
{
#ifndef SIMU
register Spi *spiptr;
register uint32_t result;
spiptr = SPI;
spiptr->SPI_CR = 1; // Enable
(void) spiptr->SPI_RDR; // Dump any rx data
spiptr->SPI_TDR = byte;
result = 0;
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
// wait for received
if (++result > 10000) {
break;
}
}
if (count == 0) {
spiptr->SPI_CR = 2; // Disable
return spiptr->SPI_RDR;
}
(void) spiptr->SPI_RDR; // Dump the rx data
spiptr->SPI_TDR = 0;
result = 0;
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
// wait for received
if (++result > 10000) {
break;
}
}
spiptr->SPI_CR = 2; // Disable
return spiptr->SPI_RDR ;
#else
return !Spi_complete;
#endif
}
void eeprom_write_enable()
{
eeprom_write_one(6, 0);
}
uint32_t eeprom_read_status()
{
return eeprom_write_one(5, 1);
}
// SPI i/f to EEPROM (4Mb)
// Peripheral ID 21 (0x00200000)
// Connections:
// SS PA11 (peripheral A)
// MISO PA12 (peripheral A)
// MOSI PA13 (peripheral A)
// SCK PA14 (peripheral A)
// Set clock to 3 MHz, AT25 device is rated to 70MHz, 18MHz would be better
void init_spi()
{
register Spi *spiptr ;
register uint32_t timer ;
register uint8_t *p ;
uint8_t spi_buf[4] ;
PMC->PMC_PCER0 |= 0x00200000L ; // Enable peripheral clock to SPI
/* Configure PIO */
configure_pins( 0x00007800, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
spiptr = SPI ;
timer = ( Master_frequency / 3000000 ) << 8 ; // Baud rate 3Mb/s
spiptr->SPI_MR = 0x14000011 ; // 0001 0100 0000 0000 0000 0000 0001 0001 Master
spiptr->SPI_CSR[0] = 0x01180009 | timer ; // 0000 0001 0001 1000 xxxx xxxx 0000 1001
NVIC_EnableIRQ(SPI_IRQn) ;
p = spi_buf ;
// *p = 0x39 ; // Unprotect sector command
// *(p+1) = 0 ;
// *(p+2) = 0 ;
// *(p+3) = 0 ; // 3 bytes address
// spi_operation( p, spi_buf, 4 ) ;
eeprom_write_enable() ;
*p = 1 ; // Write status register command
*(p+1) = 0 ;
spi_operation( p, spi_buf, 2 ) ;
}
#ifndef SIMU
extern "C" void SPI_IRQHandler()
{
register Spi *spiptr ;
spiptr = SPI ;
SPI->SPI_IDR = 0x07FF ; // All interrupts off
spiptr->SPI_CR = 2 ; // Disable
(void) spiptr->SPI_RDR ; // Dump any rx data
(void) spiptr->SPI_SR ; // Clear error flags
spiptr->SPI_PTCR = SPI_PTCR_RXTDIS | SPI_PTCR_TXTDIS ; // Stop tramsfers
Spi_complete = 1 ; // Indicate completion
// Power save
// PMC->PMC_PCER0 &= ~0x00200000L ; // Disable peripheral clock to SPI
}
#endif
void end_spi()
{
SPI->SPI_CR = 2 ; // Disable
SPI->SPI_IDR = 0x07FF ; // All interrupts off
NVIC_DisableIRQ(SPI_IRQn) ;
}
#if 0
uint32_t unprotect_eeprom()
{
register uint8_t *p;
eeprom_write_enable();
p = Spi_tx_buf;
*p = 0x39; // Unprotect sector command
*(p + 1) = 0;
*(p + 2) = 0;
*(p + 3) = 0; // 3 bytes address
return spi_operation( p, Spi_rx_buf, 4 ) ;
}
#endif
+5
View File
@@ -31,5 +31,10 @@
*
*/
#ifndef haptic_driver_h
#define haptic_driver_h
extern void hapticOff(void) ;
extern void hapticOn( uint32_t pwmPercent ) ;
#endif
+180
View File
@@ -0,0 +1,180 @@
/*
* Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de>
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
*/
#include "../open9x.h"
// keys:
// KEY_EXIT PA31 (PC24)
// KEY_MENU PB6 (PB5)
// KEY_DOWN LCD5 PC3 (PC5)
// KEY_UP LCD6 PC2 (PC1)
// KEY_RIGHT LCD4 PC4 (PC4)
// KEY_LEFT LCD3 PC5 (PC3)
// Reqd. bit 6 LEFT, 5 RIGHT, 4 UP, 3 DOWN 2 EXIT 1 MENU
// LCD pins 5 DOWN, 4 RIGHT, 3 LEFT, 1 UP
uint32_t readKeys()
{
register uint32_t x;
register uint32_t y;
x = lcdLock ? lcdInputs : PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
x <<= 1;
#if defined(REVA)
y = (x & 0x00000060);
if (x & 0x00000008)
y |= 0x10;
if (x & 0x00000010)
y |= 0x08;
if (PIOA->PIO_PDSR & 0x80000000)
y |= 0x04; // EXIT
if (PIOB->PIO_PDSR & 0x000000040)
y |= 0x02; // MENU
#else
y = (x & 0x00000020); // RIGHT
if (x & 0x00000004)
y |= 0x02 << KEY_UP; // UP
if (x & 0x00000010)
y |= 0x02 << KEY_LEFT; // LEFT
if (x & 0x00000040)
y |= 0x02 << KEY_DOWN; // DOWN
if (x & 0x02000000)
y |= 0x02 << KEY_EXIT; // EXIT
if (PIOB->PIO_PDSR & 0x000000020)
y |= 0x02 << KEY_MENU; // MENU
#endif
return y ;
}
uint32_t readTrims()
{
uint32_t trims;
uint32_t trima;
trims = 0;
trima = PIOA->PIO_PDSR;
// TRIM_LH_DOWN PA7 (PA23)
#if defined(REVA)
if ( ( trima & 0x0080 ) == 0 )
#else
if ((trima & 0x00800000) == 0)
#endif
{
trims |= 1;
}
// TRIM_LV_DOWN PA27 (PA24)
#if defined(REVA)
if ( ( trima & 0x08000000 ) == 0 )
#else
if ((trima & 0x01000000) == 0)
#endif
{
trims |= 4;
}
// TRIM_RV_UP PA30 (PA1)
#if defined(REVA)
if ( ( trima & 0x40000000 ) == 0 )
#else
if ((trima & 0x00000002) == 0)
#endif
{
trims |= 0x20;
}
// TRIM_RH_DOWN PA29 (PA0)
#if defined(REVA)
if ( ( trima & 0x20000000 ) == 0 )
#else
if ((trima & 0x00000001) == 0)
#endif
{
trims |= 0x40;
}
// TRIM_LH_UP PB4
if ((PIOB->PIO_PDSR & 0x10) == 0) {
trims |= 2;
}
trima = PIOC->PIO_PDSR;
// TRIM_LV_UP PC28
if ((trima & 0x10000000) == 0) {
trims |= 8;
}
// TRIM_RV_DOWN PC10
if ((trima & 0x00000400) == 0) {
trims |= 0x10;
}
// TRIM_RH_UP PC9
if ((trima & 0x00000200) == 0) {
trims |= 0x80;
}
return trims;
}
uint8_t keyDown()
{
return ~readKeys() & 0x7E ;
}
void readKeysAndTrims()
{
register uint32_t i;
#if defined(ROTARY_ENCODERS)
keys[BTN_REa].input(!(PIOB->PIO_PDSR & 0x40), BTN_REa);
#endif
uint8_t enuk = KEY_MENU;
uint8_t in = ~readKeys();
for (i = 1; i < 7; i++) {
keys[enuk].input(in & (1 << i), (EnumKeys) enuk);
++enuk;
}
in = readTrims();
for (i = 1; i < 256; i <<= 1) {
keys[enuk].input(in & i, (EnumKeys) enuk);
++enuk;
}
}
+108
View File
@@ -0,0 +1,108 @@
/*
* Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de>
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
*/
#include "../open9x.h"
// TODO illogical in the driver :(
void setupPulsesPPM();
void init_main_ppm( uint32_t period, uint32_t out_enable )
{
register Pio *pioptr ;
register Pwm *pwmptr ;
setupPulsesPPM() ;
if ( out_enable )
{
pioptr = PIOA ;
pioptr->PIO_ABCDSR[0] &= ~PIO_PA17 ; // Peripheral C
pioptr->PIO_ABCDSR[1] |= PIO_PA17 ; // Peripheral C
pioptr->PIO_PDR = PIO_PA17 ; // Disable bit A17 Assign to peripheral
}
pwmptr = PWM ;
// PWM3 for PPM output
pwmptr->PWM_CH_NUM[3].PWM_CMR = 0x0000000B ; // CLKA
if (g_model.pulsePol)
pwmptr->PWM_CH_NUM[3].PWM_CMR |= 0x00000200 ; // CPOL
pwmptr->PWM_CH_NUM[3].PWM_CPDR = period ; // Period in half uS
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period ; // Period in half uS
pwmptr->PWM_CH_NUM[3].PWM_CDTY = g_model.ppmDelay*100+600; // Duty in half uS
pwmptr->PWM_CH_NUM[3].PWM_CDTYUPD = g_model.ppmDelay*100+600; // Duty in half uS
pwmptr->PWM_ENA = PWM_ENA_CHID3 ; // Enable channel 3
NVIC_EnableIRQ(PWM_IRQn) ;
pwmptr->PWM_IER1 = PWM_IER1_CHID3 ;
}
void disable_main_ppm()
{
register Pio *pioptr ;
pioptr = PIOA ;
pioptr->PIO_PER = PIO_PA17 ; // Assign A17 to PIO
PWM->PWM_IDR1 = PWM_IDR1_CHID3 ;
NVIC_DisableIRQ(PWM_IRQn) ;
}
// Initialise the SSC to allow PXX output.
// TD is on PA17, peripheral A
void init_ssc()
{
register Ssc *sscptr ;
PMC->PMC_PCER0 |= 0x00400000L ; // Enable peripheral clock to SSC
configure_pins( PIO_PA17, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
sscptr = SSC ;
sscptr->SSC_CMR = Master_frequency / (125000*2) ; // 8uS per bit
sscptr->SSC_TCMR = 0 ; // 0000 0000 0000 0000 0000 0000 0000 0000
sscptr->SSC_TFMR = 0x00000027 ; // 0000 0000 0000 0000 0000 0000 1010 0111 (8 bit data, lsb)
sscptr->SSC_CR = SSC_CR_TXEN ;
}
void disable_ssc()
{
register Pio *pioptr ;
register Ssc *sscptr ;
// Revert back to pwm output
pioptr = PIOA ;
pioptr->PIO_PER = PIO_PA17 ; // Assign A17 to PIO
sscptr = SSC ;
sscptr->SSC_CR = SSC_CR_TXDIS ;
}
-76
View File
@@ -1,76 +0,0 @@
/****************************************************************************
* Copyright (c) 2011 by Michael Blandford. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
****************************************************************************
* History:
*
****************************************************************************/
#ifndef sound_driver_h
#define sound_driver_h
#define NUM_VOL_LEVELS 24
extern void startSound( void ) ;
extern void buzzer_on( void ) ;
extern void buzzer_off( void ) ;
extern void buzzer_sound( uint8_t time ) ;
extern void setFrequency( uint32_t frequency ) ;
extern uint32_t getFrequency();
extern void start_timer1( void ) ;
extern void initDac( void ) ;
extern void end_sound( void ) ;
extern void write_coprocessor( uint8_t *ptr, uint32_t count ) ;
extern void read_coprocessor( bool onlytemp=false ) ;
extern uint8_t Coproc_read ;
extern int8_t Coproc_valid ;
extern int8_t Coproc_temp ;
extern int8_t Coproc_maxtemp ;
extern uint16_t *nextAudioData;
extern uint16_t nextAudioSize;
inline void toneStart()
{
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
DACC->DACC_IER = DACC_IER_ENDTX ;
}
inline void toneStop()
{
DACC->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt
}
extern volatile uint8_t Buzzer_count ;
extern void init_twi( void ) ;
extern void setVolume( register uint8_t volume ) ;
extern "C" void TWI0_IRQHandler (void) ;
#endif