little help with ADS7843

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: little help with ADS7843

Postby Tectu » Sat May 18, 2013 5:57 pm

The main stack size gets changed in the linker script:

Code: Select all

cat os/ports/GCC/ARMCMx/STM32F4xx/ld/STM32F407xG.ld
...
__main_stack_size__     = 0x0400;
__process_stack_size__  = 0x0400;

And here an important quote from giovanni:

The stack of the main() function can be changed in the linker script file. You need to copy the default linker script into your project directory then make the makefile use that one. Note that you have to change the PROCESS stack not the __main_stack_size__, the main stack is the stack for IRQs. Sorry for the confusion but it is how ARM named them.

There's currently no way to use gwinFillArea() with the background instead of the foreground color. This might be an interesting thing. I might add that!


~ Tectu

daviddawe1982
Posts: 94
Joined: Thu Apr 11, 2013 10:35 am

Re: little help with ADS7843

Postby daviddawe1982 » Sun May 19, 2013 4:00 am

Ok, that was not my problem.
When I use activate the SampleThread thread the Set button fails to work but the Clear button continues to work.
Without activating the SampleThread both buttons work fine, I have tried increasing the process stack size to 0x2000 and it will still not work properly.
I am a but stumped here..

Code: Select all

#include "ch.h"
#include "hal.h"
#include "gfx.h"
#include "stubs.c"
#include "syscalls.c"

static GButtonObject         gClear;
static GButtonObject         gSet;
static GListener         gl;
GHandle GW1, GW2;

#define ADC_GRP1_NUM_CHANNELS   1
#define ADC_GRP1_BUF_DEPTH      1
static adcsample_t BatterySamples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
static const ADCConversionGroup adcgrpcfg1 = {
      TRUE,
      ADC_GRP1_NUM_CHANNELS,
      NULL,
      NULL,
      0,                        /* CR1 */
      ADC_CR2_SWSTART,          /* CR2 */
      ADC_SMPR1_SMP_AN11(ADC_SAMPLE_112),
      0,                        /* SMPR2 */
      ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
      0,
      ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
    };

char BatteryLevel[5];//Buffer for battery test
float Pulse = 0;
char PulseBuffer[10000];
static msg_t SampleThread(void *arg) {
//Set Pad Mode's
palSetPadMode(GPIOC,15,PAL_MODE_OUTPUT_PUSHPULL);
adcStart(&ADCD1, NULL);
adcStartConversion(&ADCD1, &adcgrpcfg1, BatterySamples, ADC_GRP1_BUF_DEPTH);


gwinDrawString(GW1, 1, 1, "DaweTec Titan200");
gwinDrawString(GW1,1,15,"V 1.5");


  while (TRUE) {
   float BatteryVoltage = (((((adcsample_t)BatterySamples[0]*2.51)/4096)/2.51)*100);
   gwinSetColor(GW1, White);
   gwinFillArea(GW1,0, 50, 150, 10);
   gwinSetColor(GW1, Black);
   sprintf(BatteryLevel, "Battery Level: %.f %%", BatteryVoltage);
   gwinDrawString(GW1,1, 50, BatteryLevel);
   sprintf(PulseBuffer, "Frequency: %.f Hz", Pulse);
   gwinSetColor(GW1, White);
   gwinFillArea(GW1,0, 61, 150, 10);
   gwinSetColor(GW1, Black);
   gwinDrawString(GW1,1, 61,PulseBuffer);
   palSetPad(GPIOC,15);
   chThdSleepMilliseconds(500);
   palClearPad(GPIOC,15);
   chThdSleepMilliseconds(500);
   Pulse ++;
  }
  return 0;
}
int main(void) {
   GSourceHandle         gs, gsClear, gsSet;
   GEvent            *pe;
   GEventMouse         *pem;
   GEventGWinButton      *peb;
   coord_t            swidth, sheight;
   GHandle            ghc, ghClear, ghSet;
   font_t            font;

   /* initialize the hardware and the OS */
   halInit();
   chSysInit();
   //reset lcd
            palClearPad(GPIOB,1);
            chThdSleepMilliseconds(50);
            palSetPad(GPIOB,1);
   /* initialize the LCD */
   gdispInit();
   gdispClear(Black);

   /* Get the display dimensions */
   swidth = gdispGetWidth();
   sheight = gdispGetHeight();
   ghClear = ghSet = 0;

   /* choose our font */
   font = gdispOpenFont("Larger Double");

   /* Initialize the mouse */
   geventListenerInit(&gl);
   gs = ginputGetMouse(0);
    gdispClear(Black);
    font = gdispOpenFont("Larger");
    GW1 = gwinCreateWindow(NULL, 20, 10, 150, 460);
    GW2 = gwinCreateWindow(NULL, 200, 100, 400, 370);
    gwinSetColor(GW1, Black);
    gwinSetBgColor(GW1, White);
    gwinSetColor(GW2, White);
    gwinSetBgColor(GW2, Blue);
    gwinSetFont(GW1,font);
    gwinClear(GW1);
    gwinClear(GW2);
   /* create the "clear" button */
   ghClear = gwinCreateButton(&gClear, 670, 50, 100, 50, font, GBTN_NORMAL);
   gwinSetButtonText(ghClear, "Clear", FALSE);
   gsClear = gwinGetButtonSource(ghClear);
   geventAttachSource(&gl, gsClear, 0);
   gwinAttachButtonMouse(ghClear, 0);

   /* create the "set" button */
   ghSet = gwinCreateButton(&gSet, 670, 105, 100, 50, font, GBTN_NORMAL);
   gwinSetButtonText(ghSet, "Set", FALSE);
   gsSet = gwinGetButtonSource(ghSet);
   geventAttachSource(&gl, gsSet, 0);
   gwinAttachButtonMouse(ghSet, 0);

   /* draw the buttons */
   gwinButtonDraw(ghClear);
   gwinButtonDraw(ghSet);
     Thread *tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(650), NORMALPRIO+1,
                                      SampleThread, NULL);
     if (tp == NULL)
     while(TRUE) {
      pe = geventEventWait(&gl, TIME_INFINITE);

      /* button pressed... */
      if (pe->type == GEVENT_GWIN_BUTTON) {
         peb = (GEventGWinButton *)pe;
         if (peb->button == ghSet)
            palSetPad(GPIOD, 12);
         else if (peb->button == ghClear)
            palClearPad(GPIOD, 12);
      }
   }

   return 0;
}

daviddawe1982
Posts: 94
Joined: Thu Apr 11, 2013 10:35 am

Re: little help with ADS7843

Postby daviddawe1982 » Sun May 19, 2013 3:24 pm

I have moved the DrawButtons above the draw window commands and now thay at least go dark when pressed but the IF for the buttons does not appear to function..
Is there a different way to check weather a button is pressed?

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: little help with ADS7843

Postby Tectu » Sun May 19, 2013 10:19 pm

First about the GWIN thing. It is correct that you have to change the foreground color every time - that is the entire purpose behind it. When you work with other "big" libraries to draw on a real comuter, you do always select a pen/brush (shape) and then a color. Then you draw, change the shape and/or the color and draw the next thing. Try it: Take a piece of paper and some color pens. Draw a house and a sun. You will clearly always pick a color, draw something, pick the next color, draw the next thing, no? ;)

This might currently not make much sense for you but GWIN will become a real widget manager in the future. After that you will not have to bother with that anymore. Everything will be a widget and where you have to draw something, you will have a specialized widget with provides a specialized interface for this.

~ Tectu

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: little help with ADS7843

Postby Tectu » Sun May 19, 2013 10:29 pm

Now about the other issue... Can you please try to explain your problem in some better words? I do really hard understanding your posts...


~ Tectu

daviddawe1982
Posts: 94
Joined: Thu Apr 11, 2013 10:35 am

Re: little help with ADS7843

Postby daviddawe1982 » Mon May 20, 2013 1:38 am

Yes I understand what you mean I was only saying it would be nice if it was the same as
gdispDraw and please don't stir me about the use of pen's ... My mum only let's me use crayons. :D
My problem is pretty simple the example for GWIN Buttons works fine but if i add a thread (use multi thre ading) the buttons will no longer toggle the LED's even if the added thread is very simple it will still stop the buttons from working (see my code) Now I assume it's a memory issue but increasing the Main stack size and/or the Process stack size has no affect .
Is there a different method available to monitor the button state other than using IF as per example?
Or is there a better way to resolve my issue?
Please remember Techu I am only learning and you help is very appreciated .

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: little help with ADS7843

Postby Tectu » Mon May 20, 2013 1:52 am

I am only learing as well and part of that is trying to help other people :)

Do you see the buttons being pressed down and just the LED shows no reaction when you start the other thread, or don't the buttons respond at all anymore?


~ Tectu

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: little help with ADS7843

Postby Tectu » Mon May 20, 2013 2:16 am

I just took the button example and added a simple thread. It works very well. Did you define the multithread mode for the GDISP module? Also, what is your compiler optimization?


~ Tectu

daviddawe1982
Posts: 94
Joined: Thu Apr 11, 2013 10:35 am

Re: little help with ADS7843

Postby daviddawe1982 » Mon May 20, 2013 2:21 am

Buttons show that they get pressed (dark grey ) but the LED no longer works after starting the other thread .
I have completely pulled down the code and built it bit by bit and it is defiantly when i start the other thread .
I am using the GNU toolchain , ChibiStudio , and i have enabled multithreading
Thanks Techu ..

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: little help with ADS7843

Postby Tectu » Mon May 20, 2013 2:44 am

Can you please try running this code? Make sure you set LEDs matching your hardware setup. It runs fine here. The one LED is toggling and I can set or clear the other one using the buttons.

Code: Select all

#include "ch.h"
#include "hal.h"
#include "gfx.h"
 
static GButtonObject         gClear;
static GButtonObject         gSet;
static GListener         gl;

static WORKING_AREA(waThread1, 1024);
static msg_t Thread1(void *arg) {
 
  (void)arg;
  chRegSetThreadName("blinker");
  while (TRUE) {
    palTogglePad(GPIOD, GPIOD_LED3);
    chThdSleepMilliseconds(250);
  }
}
 
int main(void) {
   GSourceHandle         gs, gsClear, gsSet;
   GEvent            *pe;
   GEventMouse         *pem;
   GEventGWinButton      *peb;
   coord_t            swidth, sheight;
   GHandle            ghc, ghClear, ghSet;
   font_t            font;
 
   /* initialize the hardware and the OS */
   halInit();      
   chSysInit();
 
   /* initialize the LCD */
   gdispInit();
   gdispClear(Black);
 
   /* Get the display dimensions */
   swidth = gdispGetWidth();
   sheight = gdispGetHeight();
   ghClear = ghSet = 0;
 
   /* choose our font */
   font = gdispOpenFont("Larger Double");
 
   /* Initialize the mouse */
   geventListenerInit(&gl);
   gs = ginputGetMouse(0);
 
   /* create the "clear" button */
   ghClear = gwinCreateButton(&gClear, 10, 50, 100, 50, font, GBTN_NORMAL);
   gwinSetButtonText(ghClear, "Clear", FALSE);
   gsClear = gwinGetButtonSource(ghClear);
   geventAttachSource(&gl, gsClear, 0);
   gwinAttachButtonMouse(ghClear, 0);
 
   /* create the "set" button */
   ghSet = gwinCreateButton(&gSet, 130, 50, 100, 50, font, GBTN_NORMAL);
   gwinSetButtonText(ghSet, "Set", FALSE);
   gsSet = gwinGetButtonSource(ghSet);
   geventAttachSource(&gl, gsSet, 0);
   gwinAttachButtonMouse(ghSet, 0);

   gdispClear(Black);
 
   /* draw the buttons */
   gwinButtonDraw(ghClear);
   gwinButtonDraw(ghSet);

   chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
 
   while(TRUE) {
      pe = geventEventWait(&gl, TIME_INFINITE);
 
      /* button pressed... */
      if (pe->type == GEVENT_GWIN_BUTTON) {
         peb = (GEventGWinButton *)pe;
         if (peb->button == ghSet)
            palSetPad(GPIOD, GPIOD_LED4);   
         else if (peb->button == ghClear)
            palClearPad(GPIOD, GPIOD_LED4);
      }
   }
 
   return 0;
}



~ Tectu


Return to “LCD Driver and Graphic Framework”

Who is online

Users browsing this forum: No registered users and 13 guests