Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dpiegdon committed Aug 5, 2019
1 parent c9e7860 commit fa53da0
Showing 1 changed file with 62 additions and 59 deletions.
121 changes: 62 additions & 59 deletions firmware/main.c
Expand Up @@ -41,9 +41,12 @@

#include "nullstreams.h"

#define MIN(x, y) ( ((x)<(y)) ? (x) : (y) )




#define MIN(x, y) ( ((x)<(y)) ? (x) : (y) )

//#define SHELL_OPTION_PARSING_DEBUG

/* Configuration for command "gpio" */
Expand Down Expand Up @@ -84,8 +87,7 @@ struct pinPort pinPorts[] = {
{true, false, "31", 12, GPIOB, ADC_CHANNEL_NONE}, // works
};

int pinIndexForMaplePin(const char * maplePin, bool onlyIfGpio, bool onlyIfAdc, bool assertIfNone)
{
int pinIndexForMaplePin(const char * maplePin, bool onlyIfGpio, bool onlyIfAdc, bool assertIfNone) {
unsigned i;
for(i = 0; i < sizeof(pinPorts)/sizeof(pinPorts[0]); i++) {
if(onlyIfGpio && !pinPorts[i].as_gpio)
Expand All @@ -99,6 +101,10 @@ int pinIndexForMaplePin(const char * maplePin, bool onlyIfGpio, bool onlyIfAdc,
return -1;
}





/* Configuration for command "uart" */
struct uartPort {
char *uartPortString;
Expand All @@ -113,10 +119,14 @@ struct uartPort uartPorts[] = {
{"3", 10, 11, GPIOB, GPIOB, &SD3} //Maple: Tx: D1, Rx: D0; STM32: Tx: PB10, Rx: PB11; 5V tolerant
};





/* Configuration for I2C commands and sensors */
I2CConfig i2ccfg = {
OPMODE_I2C,
8000, // 10kHZ I2C Frequency
8000, // 10kHZ I2C Frequency
STD_DUTY_CYCLE
};

Expand All @@ -133,6 +143,10 @@ struct i2cPort i2cPorts[] = {
{ &I2CD2, GPIOB, 10, GPIOB, 11 }
};





typedef enum {
TEMP,
HUMID
Expand All @@ -150,12 +164,15 @@ typedef struct {
#define MAX_NUM_SENSORS 16
i2cSensor sensorList[MAX_NUM_SENSORS];

#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(8192)




/*===========================================================================*/
/* Command line related. */
/* Implementation of commands */
/*===========================================================================*/

#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(8192)

static void cmd_gpio(BaseSequentialStream *chp, int argc, char *argv[]) {
uint8_t i;
char *dOpt = NULL, *pOpt = NULL, *vOpt = NULL;
Expand Down Expand Up @@ -199,7 +216,7 @@ static void cmd_gpio(BaseSequentialStream *chp, int argc, char *argv[]) {
for(i = 0; i < sizeof(pinPorts)/sizeof(pinPorts[0]); i++)
if(pinPorts[i].as_gpio)
chprintf(chp, "%s | ", pinPorts[i].pinNrString);
chprintf(chp, "\r\n"
chprintf(chp, "\r\n"
"\twith val: (only if direction out)\r\n"
"\t\t0 | 1\r\n");
return;
Expand Down Expand Up @@ -553,8 +570,7 @@ static void cmd_pwm(BaseSequentialStream *chp, int argc, char *argv[]) {



static void pulses_equidistant(GPIO_TypeDef *gpio, uint8_t pin, unsigned count, bool startLow, unsigned pulseLen_ms)
{
static void pulses_equidistant(GPIO_TypeDef *gpio, uint8_t pin, unsigned count, bool startLow, unsigned pulseLen_ms) {
unsigned i;
for(i = 0; i < count; ++i) {
if(startLow) {
Expand All @@ -570,22 +586,14 @@ static void pulses_equidistant(GPIO_TypeDef *gpio, uint8_t pin, unsigned count,
}
}





// function to calculate the time of pulse n during acceleration
static float t_pulse(int n,float a) {
static float t_pulse(int n, float a) {
float t;
t = sqrt(2. * n / a);
return t;
}





static void cmd_send_pulses(BaseSequentialStream *chp, int argc, char *argv[]){
static void cmd_send_pulses(BaseSequentialStream *chp, int argc, char *argv[]) {
uint8_t i;
char *pin = NULL, *count = NULL;
char *velocity = NULL, *acceleration = NULL;
Expand Down Expand Up @@ -725,36 +733,6 @@ static void cmd_send_pulses(BaseSequentialStream *chp, int argc, char *argv[]){



static void pulses_ramped(GPIO_TypeDef *gpio, uint8_t pin, unsigned count, bool startLow, unsigned minPulseLen_ms, unsigned rampSteps)
{
// min_delay determines the target speed
uint16_t rampLength = MIN(count/2, rampSteps);
uint8_t delay = minPulseLen_ms + rampSteps;
unsigned i;

for(i = 0; i < count; i++) {
if(startLow) {
palSetPad(gpio, pin);
chThdSleepMilliseconds(delay);
}
palClearPad(gpio, pin);
chThdSleepMilliseconds(delay);
if(!startLow) {
palSetPad(gpio, pin);
chThdSleepMilliseconds(delay);
}

if (i >= count - rampLength)
delay++;
else if (i < rampLength)
delay--;
}
}






/* Function for the rotary table/turntable */
static void cmd_motor_rotary(BaseSequentialStream *chp, int argc, char *argv[]) {
Expand Down Expand Up @@ -884,7 +862,6 @@ static void cmd_motor_rotary(BaseSequentialStream *chp, int argc, char *argv[])
}
return;


exit_with_usage:
chprintf(chp, "Usage: motor_rotary <mode> <arguments>\r\n"
"\tNumber of pulses to turn "
Expand All @@ -901,6 +878,34 @@ static void cmd_motor_rotary(BaseSequentialStream *chp, int argc, char *argv[])
}





static void pulses_ramped(GPIO_TypeDef *gpio, uint8_t pin, unsigned count, bool startLow, unsigned minPulseLen_ms, unsigned rampSteps) {
// min_delay determines the target speed
uint16_t rampLength = MIN(count/2, rampSteps);
uint8_t delay = minPulseLen_ms + rampSteps;
unsigned i;

for(i = 0; i < count; i++) {
if(startLow) {
palSetPad(gpio, pin);
chThdSleepMilliseconds(delay);
}
palClearPad(gpio, pin);
chThdSleepMilliseconds(delay);
if(!startLow) {
palSetPad(gpio, pin);
chThdSleepMilliseconds(delay);
}

if (i >= count - rampLength)
delay++;
else if (i < rampLength)
delay--;
}
}

static void cmd_motor_linear(BaseSequentialStream *chp, int argc, char *argv[]) {
// Pin declaration for use with the C5-E (gpio number arbitrary)
const char maplePinPulses[] = "26";
Expand Down Expand Up @@ -1123,10 +1128,6 @@ static int scanSensors(void) {
return numSensors;
}





static float readSensorTimeout(BaseSequentialStream *chp, uint8_t sensorID, uint16_t timeout) {
// Locals
float retVal = -1000; // Default return value for errors
Expand Down Expand Up @@ -1478,8 +1479,7 @@ static void cmd_pollsensors(BaseSequentialStream *chp, int argc, char *argv[]) {



void get_unique_device_id96(uint8_t ptr96bit[96/8])
{
void get_unique_device_id96(uint8_t ptr96bit[96/8]) {
uint8_t * uid_register = (uint8_t*)0x1ffff7e8;
memcpy(ptr96bit, uid_register, 96/8);
}
Expand Down Expand Up @@ -1508,8 +1508,7 @@ static void cmd_uniqueid(BaseSequentialStream *chp, int argc, char *argv[]) {

static bool adc_conversion_ok;

static void adc_bad_callback(ADCDriver *adcp, adcerror_t err)
{
static void adc_bad_callback(ADCDriver *adcp, adcerror_t err) {
(void)adcp;
(void)err;
adc_conversion_ok = false;
Expand Down Expand Up @@ -1642,6 +1641,10 @@ static const ShellConfig shell_cfg1 = {
commands
};





/*===========================================================================*/
/* Generic code. */
/*===========================================================================*/
Expand Down

0 comments on commit fa53da0

Please sign in to comment.