Compare commits
No commits in common. "8d99d529f5eeba36e87e7b1725878bdc77bb916a" and "6a2cc9a6ad333b8edd9c037617ea17ad69aeeae3" have entirely different histories.
8d99d529f5
...
6a2cc9a6ad
1 changed files with 18 additions and 58 deletions
76
leia/leia.c
76
leia/leia.c
|
|
@ -26,7 +26,6 @@ const char revision[] = Id;
|
|||
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#define SPI_Rx_SLEEP
|
||||
#include "spi_slave.h"
|
||||
|
|
@ -73,13 +72,10 @@ struct conf {
|
|||
uint8_t reset; // 12
|
||||
uint8_t dir; // 13
|
||||
uint16_t n_steps; // 14
|
||||
uint16_t dac_ramp; // 16
|
||||
uint16_t dac_step; // 18
|
||||
uint8_t adc_incr; // 20
|
||||
uint8_t adc_period; // 21
|
||||
uint8_t awake; // 22
|
||||
uint8_t ledoff; // 23
|
||||
uint8_t disable; // 24
|
||||
uint16_t dac_ramp; // 18
|
||||
uint16_t dac_step; // 20
|
||||
uint8_t adc_incr; // 23
|
||||
uint8_t adc_period; // 24
|
||||
uint8_t pad[7]; // 25
|
||||
uint8_t adc_ch[16]; // 32
|
||||
};
|
||||
|
|
@ -123,10 +119,7 @@ const struct conf runcon = {
|
|||
.lmask = LIMIT1 | LIMIT2 | FAULT1 | FAULT2,
|
||||
.lval = FAULT1 | FAULT2,
|
||||
.enable = SLEEP | RESET,
|
||||
.disable = ENABLE,
|
||||
.ledoff = LEDON,
|
||||
.awake = SLEEP,
|
||||
.reset = RESET,
|
||||
.reset = RESET,
|
||||
.adc_ch = {
|
||||
ADC_BG|ADC_SR, ADC_BG|ADC_R, ADC_GND|ADC_R,
|
||||
ADC_Iprim|ADC_SR, ADC_Iprim|ADC_R,
|
||||
|
|
@ -137,7 +130,6 @@ const struct conf runcon = {
|
|||
.adc_incr = 16, // one conversions per channel
|
||||
.adc_period = TICK_NS(1000000),
|
||||
.dac_step = 0x20,
|
||||
.pad = "\xff\xff\xff\xff\xff\xff\xff"
|
||||
};
|
||||
|
||||
void stepper_init()
|
||||
|
|
@ -681,21 +673,6 @@ uint8_t eeprom_load(uint16_t a)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
uint8_t eeprom_read_byte(uint16_t a, uint8_t *r)
|
||||
{
|
||||
cli();
|
||||
if (EECR & 1<<EEWE) {
|
||||
sei();
|
||||
return 1;
|
||||
}
|
||||
EEAR = a;
|
||||
EECR |= 1<<EERE;
|
||||
*r = EEDR;
|
||||
sei();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
void reg16(uint16_t *v, unsigned char *r, const unsigned char *c)
|
||||
{
|
||||
|
|
@ -886,22 +863,16 @@ int main()
|
|||
v.conf.n_steps = cmd[2] << ((cmd[1]>>4) & 7);
|
||||
// fall through, return n_steps
|
||||
case 's': reg16(&v.conf.n_steps, resp, cmd); break;
|
||||
case 'r': resp[2] = cmd[2];
|
||||
switch (cmd[2] & 0x3) {
|
||||
case 0: reg8(&v.conf.reset, resp, cmd);
|
||||
case 1: reg8(&v.conf.disable, resp, cmd);
|
||||
case 2: reg8(&v.conf.awake, resp, cmd);
|
||||
case 3: reg8(&v.conf.ledoff, resp, cmd);
|
||||
case 'r': reg8(&v.conf.reset, resp, cmd);
|
||||
resp[2] = cmd[2];
|
||||
if (cmd[2]) {
|
||||
v.conf.step = 0;
|
||||
if (cmd[2] & 0x80)
|
||||
stepper_init();
|
||||
if (cmd[2] & 1)
|
||||
stepper_start(v.conf.reset);
|
||||
}
|
||||
if (up && cmd[2] & 0x3)
|
||||
v.conf.enable = v.conf.awake | v.conf.ledoff | v.conf.disable;
|
||||
if (cmd[2] & 0x40)
|
||||
RESET_PORT = v.conf.enable;
|
||||
if (cmd[2] & 0x80)
|
||||
stepper_init();
|
||||
if (cmd[2] & 0x10)
|
||||
stepper_start(v.conf.reset);
|
||||
break;
|
||||
break;
|
||||
case 'd': reg16(&v.stat.dac, resp, cmd);
|
||||
dac_ramp(v.stat.dac);
|
||||
break;
|
||||
|
|
@ -964,13 +935,8 @@ int main()
|
|||
if (cmd[1] && upcase(cmd[1]))
|
||||
conf_init();
|
||||
break;
|
||||
case 'x': // read/write conf Byte, read eeprom byte
|
||||
case 'x': // conf Byte
|
||||
resp[2] = cmd[1];
|
||||
if (!up && cmd[2] & 0xf) {
|
||||
if (eeprom_read_byte(frame2int(cmd+1) & 0x7ff, resp+1))
|
||||
resp[0] = 'E';
|
||||
break;
|
||||
}
|
||||
if (cmd[1] >= sizeof(struct vars)) {
|
||||
resp[0] = 'E';
|
||||
resp[1] = sizeof(struct vars);
|
||||
|
|
@ -980,17 +946,11 @@ int main()
|
|||
if (up)
|
||||
((unsigned char *)(&v))[cmd[1]] = cmd[2];
|
||||
break;
|
||||
case 'y': // peek, poke IO space, read RAM, flash
|
||||
case 'y': // peek, poke
|
||||
resp[2] = cmd[1];
|
||||
if (!up)
|
||||
if (cmd[2]&0x80)
|
||||
resp[1] = pgm_read_u8((uint8_t*)(frame2int(cmd+1)& 0x7fff));
|
||||
else
|
||||
resp[1] = *(unsigned char *)(frame2int(cmd+1));
|
||||
else {
|
||||
resp[1] = *(unsigned char *)(cmd[1]+0);
|
||||
resp[1] = *(unsigned char *)(cmd[1]+0);
|
||||
if (up)
|
||||
*(unsigned char *)(cmd[1]+0) = cmd[2];
|
||||
}
|
||||
break;
|
||||
}
|
||||
spi_slave_Tx(resp, 3);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue