[Horus] Fixes. ADC + Switches + Trims + RTC OK

This commit is contained in:
Bertrand Songis
2016-01-08 22:21:26 +01:00
parent 685dece185
commit 82a4ad4103
43 changed files with 402 additions and 398 deletions
+15 -15
View File
@@ -130,14 +130,14 @@ void adcInit()
#define SPI_STICK2 1
#define SPI_STICK3 2
#define SPI_STICK4 3
#define SPI_POT1 4
#define SPI_POT2 5
#define SPI_POT3 6
#define SPI_SLIDER1 7
#define SPI_SLIDER2 8
#define SPI_S1 4
#define SPI_6POS 5
#define SPI_S2 6
#define SPI_S3 7
#define SPI_S4 8
#define SPI_TX_VOLTAGE 9
#define SPI_SLIDER3 10
#define SPI_SLIDER4 11
#define SPI_RS 10
#define SPI_LS 11
const uint16_t adcCommands[MOUSE1+2] =
{
@@ -145,13 +145,13 @@ const uint16_t adcCommands[MOUSE1+2] =
MANUAL_MODE | ( SPI_STICK2 << 7 ),
MANUAL_MODE | ( SPI_STICK3 << 7 ),
MANUAL_MODE | ( SPI_STICK4 << 7 ),
MANUAL_MODE | ( SPI_POT1 << 7 ),
MANUAL_MODE | ( SPI_POT2 << 7 ),
MANUAL_MODE | ( SPI_POT3 << 7 ),
MANUAL_MODE | ( SPI_SLIDER1 << 7 ),
MANUAL_MODE | ( SPI_SLIDER2 << 7 ),
MANUAL_MODE | ( SPI_SLIDER4 << 7 ),
MANUAL_MODE | ( SPI_SLIDER3 << 7 ),
MANUAL_MODE | ( SPI_S1 << 7 ),
MANUAL_MODE | ( SPI_6POS << 7 ),
MANUAL_MODE | ( SPI_S2 << 7 ),
MANUAL_MODE | ( SPI_LS << 7 ),
MANUAL_MODE | ( SPI_RS << 7 ),
MANUAL_MODE | ( SPI_S3 << 7 ),
MANUAL_MODE | ( SPI_S4 << 7 ),
MANUAL_MODE | ( SPI_TX_VOLTAGE << 7 ),
MANUAL_MODE | ( 0 << 7 ),
MANUAL_MODE | ( 0 << 7 )
@@ -199,7 +199,7 @@ void adcRead()
// On chip ADC read should have finished
}
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,1,-1, 1,1, -1,-1, 0,0,0};
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,1,-1, -1,-1, 1,1, 0,0,0};
uint16_t getAnalogValue(uint32_t index)
{
+20 -20
View File
@@ -1,23 +1,23 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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.
*/
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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 "../../opentx.h"
#if defined(__cplusplus) && !defined(SIMU)
+39 -39
View File
@@ -1,25 +1,25 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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 _HAL_H_
#define _HAL_H_
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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 _HAL_H_
#define _HAL_H_
// Keys
#define KEYS_RCC_AHB1Periph_GPIO (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOJ)
@@ -44,18 +44,18 @@
#define ENC_GPIO_PIN_B GPIO_Pin_10 // PH.10
// Switches
#define SWITCHES_GPIO_REG_A_H GPIOI->IDR
#define SWITCHES_GPIO_PIN_A_H GPIO_Pin_15 // PI.15
#define SWITCHES_GPIO_REG_A_L GPIOH->IDR
#define SWITCHES_GPIO_PIN_A_L GPIO_Pin_9 // PH.09
#define SWITCHES_GPIO_REG_A_H GPIOH->IDR
#define SWITCHES_GPIO_PIN_A_H GPIO_Pin_9 // PH.09
#define SWITCHES_GPIO_REG_A_L GPIOI->IDR
#define SWITCHES_GPIO_PIN_A_L GPIO_Pin_15 // PI.15
#define SWITCHES_GPIO_REG_B_H GPIOH->IDR
#define SWITCHES_GPIO_PIN_B_H GPIO_Pin_12 // PH.12
#define SWITCHES_GPIO_REG_B_L GPIOB->IDR
#define SWITCHES_GPIO_PIN_B_L GPIO_Pin_12 // PB.12
#define SWITCHES_GPIO_REG_C_H GPIOB->IDR
#define SWITCHES_GPIO_PIN_C_H GPIO_Pin_15 // PB.15
#define SWITCHES_GPIO_REG_C_L GPIOD->IDR
#define SWITCHES_GPIO_PIN_C_L GPIO_Pin_11 // PD.11
#define SWITCHES_GPIO_REG_C_H GPIOD->IDR
#define SWITCHES_GPIO_PIN_C_H GPIO_Pin_11 // PD.11
#define SWITCHES_GPIO_REG_C_L GPIOB->IDR
#define SWITCHES_GPIO_PIN_C_L GPIO_Pin_15 // PB.15
#define SWITCHES_GPIO_REG_D_H GPIOJ->IDR
#define SWITCHES_GPIO_PIN_D_H GPIO_Pin_7 // PJ.07
#define SWITCHES_GPIO_REG_D_L GPIOG->IDR
@@ -67,9 +67,9 @@
#define SWITCHES_GPIO_REG_F GPIOH->IDR
#define SWITCHES_GPIO_PIN_F GPIO_Pin_3 // PH.03
#define SWITCHES_GPIO_REG_G_H GPIOG->IDR
#define SWITCHES_GPIO_PIN_G_H GPIO_Pin_3 // PG.03
#define SWITCHES_GPIO_PIN_G_H GPIO_Pin_6 // PG.06
#define SWITCHES_GPIO_REG_G_L GPIOG->IDR
#define SWITCHES_GPIO_PIN_G_L GPIO_Pin_6 // PG.06
#define SWITCHES_GPIO_PIN_G_L GPIO_Pin_3 // PG.03
#define SWITCHES_GPIO_REG_H GPIOG->IDR
#define SWITCHES_GPIO_PIN_H GPIO_Pin_7 // PG.07
@@ -100,13 +100,13 @@
#define TRIMS_GPIO_PIN_LSU GPIO_Pin_13 // PB.13
// Index of all keys
#define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_C_H | TRIMS_GPIO_PIN_LSD | TRIMS_GPIO_PIN_LSU)
#define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_C_L | TRIMS_GPIO_PIN_LSD | TRIMS_GPIO_PIN_LSU)
#define KEYS_GPIOC_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_ENTER | KEYS_GPIO_PIN_RIGHT | TRIMS_GPIO_PIN_RHL)
#define KEYS_GPIOD_PINS (SWITCHES_GPIO_PIN_C_L | TRIMS_GPIO_PIN_LHL | TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_RSU)
#define KEYS_GPIOD_PINS (SWITCHES_GPIO_PIN_C_H | TRIMS_GPIO_PIN_LHL | TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_RSU)
#define KEYS_GPIOE_PINS (SWITCHES_GPIO_PIN_E_L)
#define KEYS_GPIOG_PINS (KEYS_GPIO_PIN_UP | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H | TRIMS_GPIO_PIN_RVD)
#define KEYS_GPIOH_PINS (SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_F | ENC_GPIO_PIN_A | ENC_GPIO_PIN_B)
#define KEYS_GPIOI_PINS (KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_LEFT | KEYS_GPIO_PIN_DOWN | SWITCHES_GPIO_PIN_A_H | TRIMS_GPIO_PIN_RHR)
#define KEYS_GPIOH_PINS (SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_F | ENC_GPIO_PIN_A | ENC_GPIO_PIN_B)
#define KEYS_GPIOI_PINS (KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_LEFT | KEYS_GPIO_PIN_DOWN | SWITCHES_GPIO_PIN_A_L | TRIMS_GPIO_PIN_RHR)
#define KEYS_GPIOJ_PINS (SWITCHES_GPIO_PIN_D_H | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | TRIMS_GPIO_PIN_RSD)
// ADC
@@ -130,8 +130,8 @@
// Power
#define PWR_RCC_AHB1Periph RCC_AHB1Periph_GPIOJ
#define PWR_GPIO GPIOJ
#define PWR_GPIO_PIN_ON GPIO_Pin_0 // PJ.00
#define PWR_GPIO_PIN_SWITCH GPIO_Pin_1 // PJ.01
#define PWR_GPIO_PIN_ON GPIO_Pin_1 // PJ.01
#define PWR_GPIO_PIN_SWITCH GPIO_Pin_0 // PJ.00
// Led
#define LED_RCC_AHB1Periph RCC_AHB1Periph_GPIOI
@@ -269,4 +269,4 @@
#define TIMER_2MHz_APB1Periph RCC_APB1Periph_TIM7
#define TIMER_2MHz_TIMER TIM7
#endif // _HAL_H_
#endif // _HAL_H_
+28 -21
View File
@@ -1,23 +1,23 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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.
*/
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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 "../../opentx.h"
uint32_t readKeys()
@@ -147,6 +147,13 @@ void readKeysAndTrims()
case SW_S ## x ## 2: \
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break
#define ADD_NEG_2POS_CASE(x) \
case SW_S ## x ## 2: \
xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break; \
case SW_S ## x ## 0: \
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break
#define ADD_3POS_CASE(x, i) \
case SW_S ## x ## 0: \
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
@@ -177,7 +184,7 @@ bool switchState(EnumKeys enuk)
ADD_3POS_CASE(C, 2);
ADD_3POS_CASE(D, 3);
ADD_3POS_CASE(E, 4);
ADD_2POS_CASE(F);
ADD_NEG_2POS_CASE(F);
ADD_3POS_CASE(G, 6);
ADD_2POS_CASE(H);
default:
+25 -65
View File
@@ -1,34 +1,29 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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.
*/
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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 "../../pwr.h"
#include "../horus/board_horus.h"
extern volatile uint32_t g_tmr10ms;
#define get_tmr10ms() g_tmr10ms
void pwrInit()
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIO Configuration*/
GPIO_InitStructure.GPIO_Pin = PWR_GPIO_PIN_ON;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
@@ -38,25 +33,20 @@ void pwrInit()
GPIO_InitStructure.GPIO_Pin = PWR_GPIO_PIN_SWITCH;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(PWR_GPIO, &GPIO_InitStructure);
// Soft power ON
GPIO_SetBits(PWR_GPIO, PWR_GPIO_PIN_ON);
// Init Module PWR
GPIO_ResetBits(EXTMODULE_GPIO_PWR, EXTMODULE_GPIO_PIN_PWR);
GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN_PWR;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(EXTMODULE_GPIO_PWR, &GPIO_InitStructure);
// TODO while (pwrPressed()) ;
pwrOn();
}
void pwrOn()
{
GPIO_SetBits(PWR_GPIO, PWR_GPIO_PIN_ON);
}
void pwrOff()
@@ -68,33 +58,3 @@ uint32_t pwrPressed()
{
return GPIO_ReadInputDataBit(PWR_GPIO, PWR_GPIO_PIN_SWITCH) == Bit_RESET;
}
#if !defined(BOOT)
uint32_t pwrPressTime = 0;
uint32_t pwrPressedDuration()
{
if (pwrPressTime == 0) {
return 0;
}
else {
return get_tmr10ms() - pwrPressTime;
}
}
uint32_t pwrCheck()
{
if (pwrPressed()) {
if (pwrPressTime == 0) {
pwrPressTime = get_tmr10ms();
}
else {
if (get_tmr10ms() - pwrPressTime > 250) {
return e_power_off;
}
}
}
else {
pwrPressTime = 0;
}
return e_power_on;
}
#endif
+5 -4
View File
@@ -1279,14 +1279,15 @@ int lcdRestoreBackupBuffer()
}
#endif
#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
void pwrInit() { }
void pwrOff() { }
#if defined(REV9E)
#if defined(PWR_BUTTON_DELAY)
uint32_t pwrPressed() { return false; }
#else
uint32_t pwrCheck() { return true; }
#endif
#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
void pwrInit() { }
void pwrOff() { }
int usbPlugged() { return false; }
void USART_DeInit(USART_TypeDef* ) { }
ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct) { return SUCCESS; }
+23 -23
View File
@@ -1,23 +1,23 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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.
*/
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* 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 "../../opentx.h"
#if defined(__cplusplus) && !defined(SIMU)
@@ -146,7 +146,7 @@ void boardInit()
#if defined(REV9E)
if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
lcdClear();
lcd_bmp(76, 2, bmp_lock, 0, 60);
lcdDrawBitmap(76, 2, bmp_lock, 0, 60);
lcdRefresh();
lcdRefreshWait();
@@ -158,10 +158,10 @@ void boardInit()
if (duration < PWR_PRESS_DURATION_MIN) {
unsigned index = duration / (PWR_PRESS_DURATION_MIN / 4);
lcdClear();
lcd_bmp(76, 2, bmp_startup, index*60, 60);
lcdDrawBitmap(76, 2, bmp_startup, index*60, 60);
}
else if (duration >= PWR_PRESS_DURATION_MAX) {
displaySleepBitmap();
drawSleepBitmap();
turnBacklightOff();
}
else {