track ctrl

This commit is contained in:
kraus 2018-03-30 07:35:12 +02:00
parent 2ab51a37ff
commit 5076054488
2 changed files with 132 additions and 41 deletions

View File

@ -110,9 +110,11 @@ U8G2_ST75256_JLX256128_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 6, /* rese
void setup(void) {
// MKR Zero Test Board
u8g2.begin(/*Select=*/ 0, /*Right/Next=*/ 1, /*Left/Prev=*/ 2, /*Up=*/ 4, /*Down=*/ 3, /*Home/Cancel=*/ A6);
u8g2.begin(/*Select=*/ 0, /*Right/Next=*/ 1, /*Left/Prev=*/ 2, /*Up=*/ 4, /*Down=*/ 3, /*Home/Cancel=*/ A5);
u8g2.setFontMode(1);
Wire.begin();
}
struct menu_entry_type
@ -296,6 +298,15 @@ int8_t track_switch[4] = { 0, 0, 0, 0 };
int16_t track_switch_x[4][2] = { { 85, 85 }, { 9, 19 }, { 58, 58 }, { 105, 105 } };
int16_t track_switch_y[4][2] = { { 0, 16 }, { 55, 55 }, { 104, 114 }, { 114, 123 } };
/* sw=0..3, pos=0..1 */
void set_swtich(uint8_t sw, uint8_t pos)
{
Wire.beginTransmission(17); // switch controller
Wire.write(0);
Wire.write(sw*2+pos);
}
void show_tracks(void)
{
int i;
@ -347,25 +358,40 @@ void show_tracks(void)
}
void track_switch_test(void)
{
track_bold1_idx = -1;
track_bold2_idx = -1;
for(;;)
{
show_tracks();
if ( button_event == U8X8_MSG_GPIO_MENU_NEXT )
track_switch[3] ^=1;
if ( button_event == U8X8_MSG_GPIO_MENU_PREV )
track_switch[1] ^=1;
if ( button_event == U8X8_MSG_GPIO_MENU_UP )
track_switch[0] ^=1;
if ( button_event == U8X8_MSG_GPIO_MENU_DOWN )
track_switch[2] ^=1;
button_event = 0;
show_tracks();
if ( button_event == U8X8_MSG_GPIO_MENU_NEXT )
{
track_switch[3] ^=1;
set_swtich(3, track_switch[3]);
}
if ( button_event == U8X8_MSG_GPIO_MENU_PREV )
{
track_switch[1] ^=1;
set_swtich(1, track_switch[1]);
}
if ( button_event == U8X8_MSG_GPIO_MENU_UP )
{
track_switch[0] ^=1;
set_swtich(0, track_switch[0]);
}
if ( button_event == U8X8_MSG_GPIO_MENU_DOWN )
{
track_switch[2] ^=1;
set_swtich(2, track_switch[2]);
}
button_event = 0;
}
}
/*================================================================================*/
void loop(void)
{
uint16_t pos;

View File

@ -364,6 +364,77 @@ void __attribute__ ((interrupt, used)) SysTick_Handler(void)
}
/*
Delay by the provided number of system ticks.
The delay must be smaller than the RELOAD value.
This delay has an imprecision of about +/- 20 system ticks.
*/
static void _delay_system_ticks_sub(uint32_t sys_ticks)
{
uint32_t start_val, end_val, curr_val;
uint32_t load;
start_val = SysTick->VAL;
start_val &= 0x0ffffffUL;
end_val = start_val;
if ( end_val < sys_ticks )
{
/* check, if the operation after this if clause would lead to a negative result */
/* if this would be the case, then add the reload value first */
load = SysTick->LOAD;
load &= 0x0ffffffUL;
end_val += load;
}
/* counter goes towards zero, so end_val is below start value */
end_val -= sys_ticks;
/* wait until interval is left */
if ( start_val >= end_val )
{
for(;;)
{
curr_val = SysTick->VAL;
curr_val &= 0x0ffffffUL;
if ( curr_val <= end_val )
break;
if ( curr_val > start_val )
break;
}
}
else
{
for(;;)
{
curr_val = SysTick->VAL;
curr_val &= 0x0ffffffUL;
if ( curr_val <= end_val && curr_val > start_val )
break;
}
}
}
/*
Delay by the provided number of system ticks.
Any values between 0 and 0x0ffffffff are allowed.
*/
void delay_system_ticks(uint32_t sys_ticks)
{
uint32_t load4;
load4 = SysTick->LOAD;
load4 &= 0x0ffffffUL;
load4 >>= 2;
while ( sys_ticks > load4 )
{
sys_ticks -= load4;
_delay_system_ticks_sub(load4);
}
_delay_system_ticks_sub(sys_ticks);
}
void setHSIClock()
{
@ -524,6 +595,18 @@ void setGPIO( uint8_t n )
}
}
void setAllGPIO(void)
{
GPIOA->BSRR = GPIO_BSRR_BS_14
| GPIO_BSRR_BS_13
| GPIO_BSRR_BS_7
| GPIO_BSRR_BS_6
| GPIO_BSRR_BS_5
| GPIO_BSRR_BS_4
| GPIO_BSRR_BS_1
| GPIO_BSRR_BS_0;
}
int main()
{
uint8_t i;
@ -537,38 +620,20 @@ int main()
SysTick->VAL = 0;
SysTick->CTRL = 7; /* enable, generate interrupt (SysTick_Handler), do not divide by 2 */
for( i = 0; i < 4; i++ )
/*
for(;;)
{
delay_system_ticks(32000*200);
setGPIO(7);
delay_system_ticks(32000*200);
clearGPIO();
}
*/
for( i = 0; i < 8; i++ )
addCmdToGPIOQueue(i);
if ( gpio_queue_mem[0] != 0 )
for(;;)
;
if ( gpio_queue_mem[1] != 1 )
for(;;)
;
if ( gpio_queue_mem[2] != 2 )
for(;;)
;
if ( gpio_queue_mem[3] != 3 )
for(;;)
;
if ( gpio_queue_start != 0 )
for(;;)
;
if ( gpio_queue_end != 4 )
for(;;)
;
if ( getCmdFromGPIOQueue() != 0 )
for(;;)
;
for(;;)
{
processQueue();