Merge branch 'easymotor-v3'
authorKeith Packard <keithp@keithp.com>
Fri, 28 Oct 2022 02:16:39 +0000 (19:16 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 28 Oct 2022 02:16:39 +0000 (19:16 -0700)
1  2 
ao-tools/ao-eeprom/ao-eeprom.c
ao-tools/lib/ao-eeprom-read.h
src/Makefile
src/lpc/ao_beep_lpc.c

index f63676300ebd76817b3cb6ac462d0d22c69f1af0,780badbed3d0d4a9ee56176690aba18777751303..1f367d9332265be4f4f9941afbe4b3e76ee87def
@@@ -148,7 -148,7 +148,7 @@@ ao_thrust(int16_t value, int16_t max_ad
  }
  
  static void
 -ao_pressure(int16_t value, int16_t max_adc, double ref, double r1, double r2)
 +ao_pressure(int16_t value, int16_t max_adc, double ref, double r1, double r2, double sensor_range)
  {
        printf(" pressure %5d", value);
        if (r1 && r2 && ref) {
                if (volts < 0.5) volts = 0.5;
                if (volts > 4.5) volts = 4.5;
  
 -              double psi = (volts - 0.5) / 4.0 * 2500.0;
 +              double psi = (volts - 0.5) / 4.0 * sensor_range;
                double pa = psi_to_pa(psi);
                printf(" %9.3f kPa", pa / 1000.0);
        }
@@@ -261,7 -261,6 +261,7 @@@ main (int argc, char **argv
                double  sense_r1 = 0.0, sense_r2 = 0.0;
                double  batt_r1 = 0.0, batt_r2 = 0.0;
                double  adc_ref = 0.0;
 +              double  pressure_sensor = 0.0;
                int16_t max_adc = 0;
  
                switch (eeprom->log_format) {
                        break;
                case AO_LOG_FORMAT_TELEFIRETWO:
                        len = 32;
 +                      pressure_sensor = 2500.0;
                        max_adc = 4095;
                        adc_ref = 3.3;
                        sense_r1 = batt_r1 = 5600;
                        break;
                case AO_LOG_FORMAT_TELEMEGA_4:
                        len = 32;
-                       break;
                        max_adc= 4095;
                        adc_ref = 3.3;
                        batt_r1 = 5600;
                        len = 16;
                        max_adc = 32767;
                        adc_ref = 3.3;
 +                      pressure_sensor = 1600.0;
                        batt_r1 = 5600;
                        batt_r2 = 10000;
                        sense_r1 = 5600;
                                        log_mega = (struct ao_log_mega *) &eeprom->data[pos];
                                        switch (log_mega->type) {
                                        case AO_LOG_FLIGHT:
 -                                              printf(" serial %5u flight %5u ground_accel %6d ground_pres %9u",
 +                                              printf(" serial %5u flight %5u ground_accel %6d ground_pres %9u kPa  %7.1f  %7.1f m",
                                                       eeprom->serial_number,
                                                       log_mega->u.flight.flight,
                                                       log_mega->u.flight.ground_accel,
 -                                                     log_mega->u.flight.ground_pres);
 +                                                     log_mega->u.flight.ground_pres,
 +                                                     log_mega->u.flight.ground_pres / 1000.0,
 +                                                     ao_pressure_to_altitude(log_mega->u.flight.ground_pres));
 +
                                                printf(" along %6d aross %6d through %6d",
                                                       log_mega->u.flight.ground_accel_along,
                                                       log_mega->u.flight.ground_accel_across,
                                        log_mini = (struct ao_log_mini *) &eeprom->data[pos];
                                        switch (log_mini->type) {
                                        case AO_LOG_FLIGHT:
 -                                              printf(" serial %5u flight %5u ground_pres %9u",
 +                                              printf(" serial %5u flight %5u ground_pres %9u kPa  %7.1f  %7.1f m",
                                                       eeprom->serial_number,
                                                       log_mini->u.flight.flight,
 -                                                     log_mini->u.flight.ground_pres);
 +                                                     log_mini->u.flight.ground_pres,
 +                                                     log_mini->u.flight.ground_pres / 1000.0,
 +                                                     ao_pressure_to_altitude(log_mini->u.flight.ground_pres));
                                                break;
                                        case AO_LOG_STATE:
                                                ao_state(log_mini->u.state.state,
                                        log_metrum = (struct ao_log_metrum *) &eeprom->data[pos];
                                        switch (log_metrum->type) {
                                        case AO_LOG_FLIGHT:
 -                                              printf(" serial %5u flight %5u ground_accel %6d ground_pres %9u ground_temp %9u",
 +                                              printf(" serial %5u flight %5u ground_accel %6d ground_pres %9u kPa  %7.1f  %7.1f m ground_temp %9u",
                                                       eeprom->serial_number,
                                                       log_metrum->u.flight.flight,
                                                       log_metrum->u.flight.ground_accel,
                                                       log_metrum->u.flight.ground_pres,
 +                                                     log_metrum->u.flight.ground_pres / 1000.0,
 +                                                     ao_pressure_to_altitude(log_metrum->u.flight.ground_pres),
                                                       log_metrum->u.flight.ground_temp);
                                                break;
                                        case AO_LOG_SENSOR:
                                        case AO_LOG_SENSOR:
                                                ao_pressure(log_firetwo->u.sensor.pressure,
                                                            max_adc, adc_ref,
 -                                                          sense_r1, sense_r2);
 +                                                          sense_r1, sense_r2,
 +                                                          pressure_sensor);
                                                ao_thrust(log_firetwo->u.sensor.thrust,
                                                          max_adc, adc_ref,
                                                          sense_r1, sense_r2);
                                                break;
                                        }
                                        break;
+                               case AO_LOG_FORMAT_EASYMOTOR:
+                                       log_motor = (struct ao_log_motor *) &eeprom->data[pos];
+                                       switch (log_motor->type) {
+                                       case AO_LOG_FLIGHT:
+                                               printf(" serial %5u flight %5u ground_accel %6d",
+                                                      eeprom->serial_number,
+                                                      log_motor->u.flight.flight,
+                                                      log_motor->u.flight.ground_accel);
+                                               printf(" along %6d aross %6d through %6d",
+                                                      log_motor->u.flight.ground_accel_along,
+                                                      log_motor->u.flight.ground_accel_across,
+                                                      log_motor->u.flight.ground_accel_through);
+                                               ao_volts("ground pressure",
+                                                        log_motor->u.flight.ground_motor_pressure,
+                                                        max_adc, adc_ref,
+                                                        sense_r1, sense_r2);
+                                               break;
+                                       case AO_LOG_STATE:
+                                               ao_state(log_motor->u.state.state,
+                                                        log_motor->u.state.reason);
+                                               break;
+                                       case AO_LOG_SENSOR:
+                                               ao_volts("pressure",
+                                                        log_motor->u.sensor.pressure,
+                                                        max_adc, adc_ref,
+                                                        sense_r1, sense_r2);
+                                               ao_volts("v_batt",
+                                                        log_motor->u.sensor.v_batt,
+                                                        max_adc,
+                                                        adc_ref, batt_r1, batt_r2);
+                                               printf(" accel %6d",
+                                                      log_motor->u.sensor.accel);
+                                               printf(" along %6d aross %6d through %6d",
+                                                      log_motor->u.sensor.accel_along,
+                                                      log_motor->u.sensor.accel_across,
+                                                      log_motor->u.sensor.accel_through);
+                                               break;
+                                       }
+                                       break;
                                case AO_LOG_FORMAT_DETHERM:
                                        break;
 +                              case AO_LOG_FORMAT_EASYMOTOR:
 +                                      log_motor = (struct ao_log_motor *) &eeprom->data[pos];
 +                                      switch (log_motor->type) {
 +                                      case AO_LOG_FLIGHT:
 +                                              printf(" serial %5u flight %5u",
 +                                                     eeprom->serial_number,
 +                                                     log_motor->u.flight.flight);
 +                                              break;
 +                                      case AO_LOG_STATE:
 +                                              ao_state(log_motor->u.state.state,
 +                                                       log_motor->u.state.reason);
 +                                              break;
 +                                      case AO_LOG_SENSOR:
 +                                              ao_pressure(log_motor->u.sensor.pressure,
 +                                                          max_adc, adc_ref,
 +                                                          sense_r1, sense_r2,
 +                                                          pressure_sensor);
 +                                              ao_volts("v_batt",
 +                                                       log_motor->u.sensor.v_batt,
 +                                                       max_adc,
 +                                                       adc_ref,
 +                                                       batt_r1, batt_r2);
 +                                              break;
 +                                      }
 +                                      break;
                                }
                        }
                        printf("\n");
index 11e4f91d92e0fe6f9daa13b1ff9828ac55de91a9,aaf6d3d68032de922e5f20e6fccb509af71eed08..9e60a5af9acdd0750b30e9934a190d47f1ab071d
@@@ -45,7 -45,7 +45,7 @@@
  #define AO_LOG_FORMAT_TELESTATIC      17      /* 32 byte typed telestatic records */
  #define AO_LOG_FORMAT_MICROPEAK2      18      /* 2-byte baro values with header */
  #define AO_LOG_FORMAT_TELEMEGA_4      19      /* 32 byte typed telemega records with 32 bit gyro cal and Bmx160 */
 -#define AO_LOG_FORMAT_EASYMOTOR               20      /* 16 byte typed easymotor records */
 +#define AO_LOG_FORMAT_EASYMOTOR               20      /* 16 byte typed easymotor records with pressure sensor and adxl375 */
  #define AO_LOG_FORMAT_NONE            127     /* No log at all */
  
  enum ao_pyro_flag {
@@@ -466,6 -466,37 +466,37 @@@ struct ao_log_mini 
        } u;                                            /* 16 */
  };                                                    /* 16 */
  
+ struct ao_log_motor {
+       char                    type;                   /* 0 */
+       uint8_t                 csum;                   /* 1 */
+       uint16_t                tick;                   /* 2 */
+       union {                                         /* 4 */
+               /* AO_LOG_FLIGHT */
+               struct {
+                       uint16_t        flight;                 /* 4 */
+                       int16_t         ground_accel;           /* 6 */
+                       int16_t         ground_accel_along;     /* 8 */
+                       int16_t         ground_accel_across;    /* 10 */
+                       int16_t         ground_accel_through;   /* 12 */
+                       int16_t         ground_motor_pressure;  /* 14 */
+               } flight;                                       /* 16 */
+               /* AO_LOG_STATE */
+               struct {
+                       uint16_t        state;                  /* 4 */
+                       uint16_t        reason;                 /* 6 */
+               } state;
+               /* AO_LOG_SENSOR */
+               struct {
+                       uint16_t        pressure;               /* 4 */
+                       uint16_t        v_batt;                 /* 6 */
+                       int16_t         accel;                  /* 8 */
+                       int16_t         accel_across;           /* 10 */
+                       int16_t         accel_along;            /* 12 */
+                       int16_t         accel_through;          /* 14 */
+               } sensor;                                       /* 16 */
+       } u;
+ };
  #define ao_log_pack24(dst,value) do {         \
                (dst)[0] = (value);             \
                (dst)[1] = (value) >> 8;        \
@@@ -516,37 -547,6 +547,37 @@@ struct ao_log_gps 
        } u;
  };
  
 +struct ao_log_motor {
 +      char                    type;                   /* 0 */
 +      uint8_t                 csum;                   /* 1 */
 +      uint16_t                tick;                   /* 2 */
 +      union {                                         /* 4 */
 +              /* AO_LOG_FLIGHT */
 +              struct {
 +                      uint16_t        flight;                 /* 4 */
 +                      int16_t         ground_accel;           /* 6 */
 +                      int16_t         ground_accel_along;     /* 8 */
 +                      int16_t         ground_accel_across;    /* 10 */
 +                      int16_t         ground_accel_through;   /* 12 */
 +                      int16_t         ground_motor_pressure;  /* 14 */
 +              } flight;                                       /* 16 */
 +              /* AO_LOG_STATE */
 +              struct {
 +                      uint16_t        state;                  /* 4 */
 +                      uint16_t        reason;                 /* 6 */
 +              } state;
 +              /* AO_LOG_SENSOR */
 +              struct {
 +                      uint16_t        pressure;               /* 4 */
 +                      uint16_t        v_batt;                 /* 6 */
 +                      int16_t         accel;                  /* 8 */
 +                      int16_t         accel_across;           /* 10 */
 +                      int16_t         accel_along;            /* 12 */
 +                      int16_t         accel_through;          /* 14 */
 +              } sensor;                                       /* 16 */
 +      } u;
 +};
 +
  struct ao_eeprom {
        struct ao_config        config;
        struct ao_ms5607_prom   ms5607_prom;
diff --combined src/Makefile
index f698d15d75f125fe6e525260c908a720cd8fdf41,31671e031819cbe11c1576465d0e7e2b33d69b98..5215ca70aadecc8fb47a96d4c5b8ab562006e35b
@@@ -20,6 -20,7 +20,7 @@@ ARMM3DIRS=
        easymega-v1.0 easymega-v1.0/flash-loader \
        easymega-v2.0 easymega-v2.0/flash-loader \
        easymotor-v2 easymotor-v2/flash-loader \
+       easymotor-v3 easymotor-v3/flash-loader \
        easytimer-v1 easytimer-v1/flash-loader \
        telemega-v0.1 telemega-v0.1/flash-loader \
        telemega-v1.0 telemega-v1.0/flash-loader \
@@@ -51,7 -52,6 +52,7 @@@ ARMM0DIRS=
        chaoskey-v1.0 chaoskey-v1.0/flash-loader \
        telemini-v3.0 telemini-v3.0/flash-loader \
        easymini-v2.0 easymini-v2.0/flash-loader \
 +      easymini-v3.0 easymini-v3.0/flash-loader \
        micropeak-v2.0
  
  AVRDIRS=\
diff --combined src/lpc/ao_beep_lpc.c
index 8cbd3ed2f8fadb407dd909471ee3ecbf8976716d,ae5caa26d88b76fee2f566f2d489776b12a6d4c1..32e108cd8a974a730f0c8a3c102abafe1b872b91
  
  #include "ao.h"
  
 -#define _cat(a,b) a##b
 -#define cat(a,b) _cat(a,b)
 +#define _cat2(a,b) a##b
 +#define cat2(a,b) _cat2(a,b)
  #define _cat4(a,b,c,d) a##b##c##d
  #define cat4(a,b,c,d) _cat4(a,b,c,d)
  #define _cat8(a,b,c,d,e,f,g,h) a##b##c##d##e##f##g##h
  #define cat8(a,b,c,d,e,f,g,h) _cat8(a,b,c,d,e,f,g,h)
  
 -#define AO_TIMER_CLKCTRL      cat(LPC_SCB_SYSAHBCLKCTRL_CT32B, BEEPER_TIMER)
 -#define AO_TIMER              cat(lpc_ct32b, BEEPER_TIMER)
 -#define AO_TIMER_EMC          cat(LPC_CT32B_EMR_EMC, BEEPER_OUTPUT)
 -#define AO_TIMER_PIO          cat4(pio, BEEPER_PORT, _, BEEPER_PIN)
 -/* LPC_IOCONF_FUNC_PIO0_14_CT32B1_MAT1 */
 -#define AO_TIMER_FUNC         cat8(LPC_IOCONF_FUNC_PIO, BEEPER_PORT, _, BEEPER_PIN, _CT32B, BEEPER_TIMER, _MAT, BEEPER_OUTPUT)
 -#define AO_TIMER_PWM          cat(LPC_CT32B_PWMC_PWMEN, BEEPER_OUTPUT)
 +#ifndef AO_LPC_BEEP_TIMER
 +#define AO_LPC_BEEP_TIMER 1
 +#define AO_LPC_BEEP_CHANNEL 1
 +#define AO_LPC_BEEP_PORT      0
 +#define AO_LPC_BEEP_PIN               14
 +#endif
 +
 +#define AO_LPC_CT_BEEP                cat2(lpc_ct32b, AO_LPC_BEEP_TIMER)
 +#define AO_LPC_CT_BEEP_CLKCTRL        cat2(LPC_SCB_SYSAHBCLKCTRL_CT32B, AO_LPC_BEEP_TIMER)
 +#define AO_LPC_CT_BEEP_EMR    cat2(LPC_CT32B_EMR_EMC, AO_LPC_BEEP_CHANNEL)
 +#define AO_LPC_CT_BEEP_MR     AO_LPC_BEEP_CHANNEL
 +#define AO_LPC_CT_BEEP_PWMC   cat2(LPC_CT32B_PWMC_PWMEN, AO_LPC_BEEP_CHANNEL)
 +#define AO_LPC_CT_BEEP_IOCONF cat4(pio,AO_LPC_BEEP_PORT,_,AO_LPC_BEEP_PIN)
 +#define AO_LPC_CT_BEEP_FUNC   cat8(LPC_IOCONF_FUNC_PIO,AO_LPC_BEEP_PORT,_,AO_LPC_BEEP_PIN,_CT32B,AO_LPC_BEEP_TIMER,_MAT,AO_LPC_BEEP_CHANNEL)
  
  void
  ao_beep(uint8_t beep)
  {
        if (beep == 0) {
 -              AO_TIMER.tcr = ((0 << LPC_CT32B_TCR_CEN) |
 +              AO_LPC_CT_BEEP.tcr = ((0 << LPC_CT32B_TCR_CEN) |
                                  (1 << LPC_CT32B_TCR_CRST));
 -              lpc_scb.sysahbclkctrl &= ~(1UL << AO_TIMER_CLKCTRL);
 +              lpc_scb.sysahbclkctrl &= ~(1UL << AO_LPC_CT_BEEP_CLKCTRL);
        } else {
 -              lpc_scb.sysahbclkctrl |= (1 << AO_TIMER_CLKCTRL);
 +              lpc_scb.sysahbclkctrl |= (1UL << AO_LPC_CT_BEEP_CLKCTRL);
  
                /* Set prescaler to match cc1111 clocks
                 */
 -              AO_TIMER.pr = AO_LPC_SYSCLK / 750000 - 1;
 +              AO_LPC_CT_BEEP.pr = AO_LPC_SYSCLK / 750000 - 1;
  
                /* Write the desired data in the match registers */
  
                /* Reset after two time units */
 -              AO_TIMER.mr[0] = beep << 1;
 +              AO_LPC_CT_BEEP.mr[0] = beep << 1;
  
                /* PWM width is half of that */
 -              AO_TIMER.mr[BEEPER_OUTPUT] = beep;
 +              AO_LPC_CT_BEEP.mr[AO_LPC_CT_BEEP_MR] = beep;
  
                /* Flip output on PWM match */
 -              AO_TIMER.emr = (LPC_CT32B_EMR_EMC_TOGGLE << AO_TIMER_EMC);
 +              AO_LPC_CT_BEEP.emr = (LPC_CT32B_EMR_EMC_TOGGLE << AO_LPC_CT_BEEP_EMR);
  
                /* Reset on match 0 */
 -              AO_TIMER.mcr = (1 << LPC_CT32B_MCR_MR0R);
 +              AO_LPC_CT_BEEP.mcr = (1 << LPC_CT32B_MCR_MR0R);
  
                /* PWM on match */
 -              AO_TIMER.pwmc = (1 << AO_TIMER_PWM);
 +              AO_LPC_CT_BEEP.pwmc = (1 << AO_LPC_CT_BEEP_PWMC);
  
                /* timer mode */
 -              AO_TIMER.ctcr = 0;
 +              AO_LPC_CT_BEEP.ctcr = 0;
  
                /* And turn the timer on */
 -              AO_TIMER.tcr = ((1 << LPC_CT32B_TCR_CEN) |
 +              AO_LPC_CT_BEEP.tcr = ((1 << LPC_CT32B_TCR_CEN) |
                                  (0 << LPC_CT32B_TCR_CRST));
        }
  }
  
  void
- ao_beep_for(uint8_t beep, AO_TICK_TYPE ticks) 
+ ao_beep_for(uint8_t beep, AO_TICK_TYPE ticks)
  {
        ao_beep(beep);
        ao_delay(ticks);
  void
  ao_beep_init(void)
  {
 -      lpc_ioconf.AO_TIMER_PIO = ((AO_TIMER_FUNC << LPC_IOCONF_FUNC) |
 +      /* Our beeper is on c32b1_mat1
 +       * which is on pin pio0_14
 +       */
 +
 +      lpc_ioconf.AO_LPC_CT_BEEP_IOCONF = ((AO_LPC_CT_BEEP_FUNC << LPC_IOCONF_FUNC) |
                              (LPC_IOCONF_MODE_INACTIVE << LPC_IOCONF_MODE) |
                              (0 << LPC_IOCONF_HYS) |
                              (0 << LPC_IOCONF_INV) |
                              (1 << LPC_IOCONF_ADMODE) |
                              (0 << LPC_IOCONF_OD));
 +
 +      lpc_scb.sysahbclkctrl |= (1 << AO_LPC_CT_BEEP_CLKCTRL);
 +
 +      /* Disable the counter and reset the value */
 +      AO_LPC_CT_BEEP.tcr = ((0 << LPC_CT32B_TCR_CEN) |
 +                        (1 << LPC_CT32B_TCR_CRST));
  }