Final MOD_EXTRA_ROTARY_ENCODERS patch applied

This commit is contained in:
maxim.karban@gmail.com
2012-04-12 07:31:12 +00:00
parent b87f321cae
commit f350666920
2 changed files with 50 additions and 4 deletions
+1 -4
View File
@@ -388,11 +388,8 @@ PACK(typedef struct t_SwashRingData { // Swash Ring data
#if defined(PCBV4)
#if defined(MOD_EXTRA_ROTARY_ENCODERS)
#define NUM_EXTRA_ROTARY_ENCODERS 3
#define VPOT_STEP 5
#define VPOT_MAX 1000
#define VPOT_MIN -VPOT_MAX
#else //MOD_EXTRA_ROTARY_ENCODERS
#define NUM_EXTRA_ROTARY_ENCODERS 3
#define NUM_EXTRA_ROTARY_ENCODERS 0
#endif //MOD_EXTRA_ROTARY_ENCODERS
#define NUM_ROTARY_ENCODERS (2+NUM_EXTRA_ROTARY_ENCODERS)
#define ROTARY_ENCODER_MAX 1024
+49
View File
@@ -2189,6 +2189,42 @@ ISR(TIMER3_CAPT_vect) // G: High frequency noise can cause stack overflo with IS
#endif
}
#if defined (PCBV4) & defined(MOD_EXTRA_ROTARY_ENCODERS)
uint8_t vpotToChange = 0;
uint8_t vpot_mod_state = 0;
ISR(USART2_RX_vect)
{
//receive data from extension board
//bit 9 = 1 mean encoder number, following byte with bit 9 = 0 is increment value
/* Get status and 9th bit, then data */
/* from buffer */
//uint8_t status = UCSR2A;
uint16_t resh = UCSR2B;
uint16_t resl = UDR2;
uint16_t res = 0;
//if ( status & (1<<FEn)|(1<<DORn)|(1<<UPEn) )
/* Filter the 9th bit, then return */
resh = (resh >> 1) & 0x01;
res = ((resh << 8) | resl);
if((res & 0x100) == 0x100){
vpotToChange = res & 0xff;
vpot_mod_state = 1;
}else{
if(vpot_mod_state & (vpotToChange>0) & (vpotToChange<=NUM_EXTRA_ROTARY_ENCODERS))
{
int8_t vpot_inc = res & 0xff;
if(vpot_inc){
incRotaryEncoder(NUM_ROTARY_ENCODERS-NUM_EXTRA_ROTARY_ENCODERS+vpotToChange-1, vpot_inc);
}
vpot_mod_state = 0;
}
}
}
#endif //MOD_EXTRA_ROTARY_ENCODERS
extern uint16_t g_timeMain;
/*
@@ -2546,6 +2582,19 @@ int main(void)
*/
OCR4A = 0x7d;
TCCR4B = (1 << WGM42) | (3<<CS40); // CTC OCR1A, 16MHz / 64 (4us ticks)
#ifdef MOD_EXTRA_ROTARY_ENCODERS
//configure uart2 here
DDRH &= ~(1 << 0);
PORTH &= ~(1 << 0);
#define MOD_EXTRA_ROTARY_ENCODERS_USART_BAUD 9600UL
UBRR2 = F_CPU/(16*MOD_EXTRA_ROTARY_ENCODERS_USART_BAUD)-1;
//9 bit mode
UCSR2C = (1<<USBS2)|(3<<UCSZ20);
UCSR2B = (1<<RXEN2)|(0<<TXEN2)|(1<<UCSZ22);
UCSR2B |= 1 << RXCIE2; //enable interrupt on rx
#endif //MOD_EXTRA_ROTARY_ENCODERS
#endif
#if defined(PCBARM)