Menu

Hi
I am trying to use menu for selecting from list samples, case 1 to 5.

#include "LiquidCrystal.h"
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
// ============================================================
int SAMPLES;
byte buttons[] = {PB11, PB12, PB13};
const byte nrButtons = 3;
int menusize = 5;
String menu[] = {
  "SAMPLES 66 ",
  "SAMPLES 67 ",
  "SAMPLES 68 ",
  "SAMPLES 69 ",
  "SAMPLES 70 ",
};

//List 1 to 5
/*
  ///////////////////////////
  #define SAMPLES 66      //1
  #define SAMPLES 67      //2
  #define SAMPLES 68 .    //3
  #define SAMPLES 69      //4
  #define SAMPLES 70      //5
  ///////////////////////////
*/
// . =========================================================
///////////////////////////

#define SAMPLES 88
///////////////////////////

#include <libmaple/dma.h>

dma_tube_config dma_cfg;

int flag1 = 0;
int out1 = PB7;
int val1[SAMPLES];

int amp = 50;
int cnt = 0;
int time_track = 0;
float stp = 6.2831 / SAMPLES;
//float stp = 7.8539/SAMPLES;
int ret = 17;

timer_dev *dev1 = PIN_MAP[out1].timer_device;

uint8 cc_channel1 = PIN_MAP[out1].timer_channel;


void fun()
{
  flag1++;
}

void timer_conf()
{

  timer_dma_set_base_addr(dev1, TIMER_DMA_BASE_CCR2);
  timer_dma_set_burst_len(dev1, 1);
  timer_dma_enable_req(dev1, cc_channel1);
  timer_set_reload(dev1, 102);
  timer_set_prescaler(dev1, 0);

}

void dma_conf()
{
  dma_init(DMA1);
  /* T4C2 DMA C4 */
  dma_cfg.tube_dst = &(dev1->regs.gen->DMAR);
  dma_cfg.tube_dst_size = DMA_SIZE_32BITS;
  dma_cfg.tube_src = val1;
  dma_cfg.tube_src_size = DMA_SIZE_32BITS;

  dma_cfg.tube_nr_xfers = SAMPLES;
  dma_cfg.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;

  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH2;
  dma_cfg.target_data = 0;

  ret = dma_tube_cfg(DMA1, DMA_CH4, &dma_cfg);

}

void dma_start()
{
  dma_attach_interrupt(DMA1, DMA_CH4, fun);

  dma_enable(DMA1, DMA_CH4);
  timer_resume(dev1);


  dma_enable(DMA1, DMA_CH2);//
  //  timer_resume(dev2);
}

void init_wave()
{
  int i;
  for (i = 0; i < SAMPLES; i++)
  {
    val1[i] = 50 + amp * sin(stp * i);

  }
}


void setup() {


  lcd.begin(16, 2);



  pinMode(out1, PWM);
  pinMode(PB13, INPUT_PULLUP);
  pinMode(PB12, INPUT_PULLUP);
  pinMode(PB12, INPUT_PULLUP);


  timer_conf();
  dma_conf();
  dma_start();

  init_wave();
}

void loop()
{

  lcd.setCursor(0, 1);
  lcd.print("SAMPLES = ");
  lcd.setCursor(4, 1);
  lcd.print(SAMPLES);

  delay(100);
}

So far I have this.
Looking for simple menu examples, all google examples are very long.

Just describe the desired user experience:

Does the user see a single screen image something like:

Make Choice 1-5
12345

and has to move the cursor over the selected number and hit enter, or what do you want to present to the user ?

since SAMPLE is not defined at compile time, there is an error allocating val1.

assuming you want to be able to change the number of samples defining the sine wave in val1, val1 needs to be defined as large as any run time selectable size. SAMPLE needs to define that value

a variable, "samples", could be selected during run time and used in init_wave to define new values in val1 as well as reconfigure the DMA for the new number of transfers.

the configuration routines called in setup() may need to be re-invoked every time "samples" changes. presumably the DMA needs to be stopped before re-configuring

6v6gt:
Just describe the desired user experience:

Does the user see a single screen image something like:

Make Choice 1-5
12345

Not yet, I never worked with MENU , I just start to learn it .

You have int SAMPLES; Then, later, this

#define SAMPLES 88

i'm also wondering about the DMA dst and tube_src_sizes vs the size of val1. since it's not clear which processor this is for, is int, 32-bits?

i thought it was mentioned in the other thread that the sine wave only appeared one time. i wonder if the thoughts of a menu are premature. shouldn't there be code that doesn't have any obvious compiler issues and can generate a stable sine wave repeatedly.

i'm curious if the DMA transfer rate is a constant or controllable via the timer. if it's a constant, then there are a fixed number of possible frequencies that can be generated.

gcjr:
i'm also wondering about the DMA dst and tube_src_sizes vs the size of val1. since it's not clear which processor this is for, is int, 32-bits?

it is stm32f103

There seems to be no easy way to do this, no problem, I can do it manually.

In principle, it is better to get the main application logic working first, which in your case appears to be some sort of function generator, then work out later how it is all going to be integrated into a slick user interface.
Of course, you can do it with an LCD1602 display but the code samples you find generally try to map multi level hierarchical menu structures onto a 2 line display and the results are quite grim, not only for the programmer but also for the end user.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.