Go Down

Topic: Arduino.h and wiring_digital.c problem. (Read 7 times) previous topic - next topic

alvesjc

Hi Amolinero.

The latest IDE version fixes the problems with SBI and CBI Macros. You don't need to set OWER registers anymore.

I've also modified the communication with ports to work with due at a very reasonable speed.

I run now the DEMO code from Henning in 32s now.

I've modified UTFT::LCD_Writ_Bus function switch this way:

Code: [Select]
case 16:

                //Clear port registers
                REG_PIOA_CODR=0xc080; //PA7,PA14,PA15
                REG_PIOB_CODR=0x4000000; //PB26
                REG_PIOC_CODR=0x3e; //PC1 - PC5
                REG_PIOD_CODR=0x64f; //PD0-3,PD6,PD9-10
               
//DB00 on PIN37 -> PIO_PC5
                REG_PIOC_SODR=(VL<<5) & 0x20;
                //DB01 on PIN36 -> PIO_PC4
                REG_PIOC_SODR=(VL<<3) & 0x10;
                //DB02 on PIN35 -> PIO_PC3
                REG_PIOC_SODR=(VL<<1) & 0x08;
                //DB03 on PIN34 -> PIO_PC2
                REG_PIOC_SODR=(VL>>1) & 0x04;
                //DB04 on PIN33 -> PIO_PC1
                REG_PIOC_SODR=(VL>>3) & 0x02;
                //DB05 on PIN32 -> PIO_PD10
                REG_PIOD_SODR=(VL<<5) & 0x400;
                //DB06 on PIN31 -> PIO_PA7
                REG_PIOA_SODR=(VL<<1) & 0x80;
                //DB07 on PIN30 -> PIO_PD9
                REG_PIOD_SODR=(VL<<2) & 0x200;
                //DB08 on PIN22 -> PIO_PB26
                REG_PIOB_SODR=(VH<<26) & 0x4000000;
                //DB09 on PIN23 -> PIO_PA14
                REG_PIOA_SODR=(VH<<13) & 0x4000;
                //DB10 on PIN24 -> PIO_PA15
                REG_PIOA_SODR=(VH<<13) & 0x8000;
                //DB11 on PIN25 -> PIO_PD0
                REG_PIOD_SODR=(VH>>3) & 0x01;
                //DB12 on PIN26 -> PIO_PD1
                REG_PIOD_SODR=(VH>>3) & 0x02;
                //DB13 on PIN27 -> PIO_PD2
                REG_PIOD_SODR=(VH>>3) & 0x04;
                //DB14 on PIN28 -> PIO_PD3
                REG_PIOD_SODR=(VH>>3) & 0x08;
                //DB15 on PIN29 -> PIO_PD6
                REG_PIOD_SODR=(VH>>1) & 0x40;

#endif
                pulse_low(P_WR, B_WR);

                break;


And the UTFT::_set_direction_registers Function this way:

Code: [Select]
if (mode==16)
{

REG_PIOA_OER=0xc080; //PA7,PA14,PA15 enable
REG_PIOB_OER=0x4000000; //PB26 enable
REG_PIOC_OER=0x3e; //PC1 - PC5 enable
REG_PIOD_OER=0x64f; //PD0-3,PD6,PD9-10 enable
}


I've only cared with 16 bit part, my display is 16bit version.

Hope this helps.

amolinero


jake1981

#22
Dec 04, 2012, 10:29 pm Last Edit: Dec 05, 2012, 07:55 am by jake1981 Reason: 1
Can't get utft library to work even how hard I try. I just end up with empty white screen backlit..

I added cbi and sbi defines to beginning of UTFT.cpp and HW_AVR.h - removed all
other mode stuff than mode 16 from HW_AVR.h and changed regtype's type definition to volatile rwreg..

Also, I grabbed pgmspace.h from another thread and included it whenever AVR/pgmspace.h is requested.
Code compiles without problems. Shield is at 3.3v setting and mega pins is selected in demo 320x240.

Nothing happens. What am I doing wrong?
I have itdb32s and mega shield for it from
Iteadstudios..

jake1981

alvesjc - what display you are having? (and how is connected, with shield? what shield? or by wires, how did you wire it?)

amolinero

In the first define, change UTFT.c by this

Code: [Select]
#if defined(__AVR__)
#include <avr/pgmspace.h>
#include "HW_AVR.h"
#elif defined(__SAM3X8E__)
#include "Arduino.h"
#include "HW_SAM.h"
#else
#include "HW_PIC32.h"
#endif


In the define __AVR__ of file UTFT.h change by this

Code: [Select]
#if defined(__AVR__)
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "HW_AVR_defines.h"
#elif defined(__SAM3X8E__)
#include "Arduino.h"
#include "HW_SAM_defines.h"
#else
#include "WProgram.h"
#include "HW_PIC32_defines.h"
#endif


copy HW_AVR_defines.h to HW_SAM_defines.h
copy HW_AVR.h to HW_SAM.h
Changes HW_SAM_defines.h by this

Code: [Select]
#define cbi(reg, bitmask) *reg &= ~bitmask
#define sbi(reg, bitmask) *reg |= bitmask
#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask);
#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask);

#define pgm_read_word(data) *data
#define pgm_read_byte(data) *data

#define cport(port, data) port &= data
#define sport(port, data) port |= data

#define swap(type, i, j) {type t = i; i = j; j = t;}

#define fontbyte(x) cfont.font[x] 

#define regtype volatile uint32_t
#define regsize uint32_t
#define bitmapdatatype unsigned uint16_t


Changes HW_SAM.h by this

Code: [Select]
// *** Hardwarespecific functions ***
void UTFT::LCD_Writ_Bus(char VH,char VL, byte mode)
{   
switch (mode)
{
case 1:
if (display_serial_mode==SERIAL_4PIN)
{
if (VH==1)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
}
else
{
if (VH==1)
sbi(P_RS, B_RS);
else
cbi(P_RS, B_RS);
}

if (VL & 0x80)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x40)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x20)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x10)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x08)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x04)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x02)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x01)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
break;
case 8:
// NOT IMPLEMENTED
break;
case 16:
//Clear port registers
REG_PIOA_CODR=0xc080; //PA7,PA14,PA15
REG_PIOB_CODR=0x4000000; //PB26
REG_PIOC_CODR=0x3e; //PC1 - PC5
REG_PIOD_CODR=0x64f; //PD0-3,PD6,PD9-10
               
//DB00 on PIN37 -> PIO_PC5
REG_PIOC_SODR=(VL<<5) & 0x20;
//DB01 on PIN36 -> PIO_PC4
REG_PIOC_SODR=(VL<<3) & 0x10;
//DB02 on PIN35 -> PIO_PC3
REG_PIOC_SODR=(VL<<1) & 0x08;
//DB03 on PIN34 -> PIO_PC2
REG_PIOC_SODR=(VL>>1) & 0x04;
//DB04 on PIN33 -> PIO_PC1
REG_PIOC_SODR=(VL>>3) & 0x02;
//DB05 on PIN32 -> PIO_PD10
REG_PIOD_SODR=(VL<<5) & 0x400;
//DB06 on PIN31 -> PIO_PA7
REG_PIOA_SODR=(VL<<1) & 0x80;
//DB07 on PIN30 -> PIO_PD9
REG_PIOD_SODR=(VL<<2) & 0x200;
//DB08 on PIN22 -> PIO_PB26
REG_PIOB_SODR=(VH<<26) & 0x4000000;
//DB09 on PIN23 -> PIO_PA14
REG_PIOA_SODR=(VH<<13) & 0x4000;
//DB10 on PIN24 -> PIO_PA15
REG_PIOA_SODR=(VH<<13) & 0x8000;
//DB11 on PIN25 -> PIO_PD0
REG_PIOD_SODR=(VH>>3) & 0x01;
//DB12 on PIN26 -> PIO_PD1
REG_PIOD_SODR=(VH>>3) & 0x02;
//DB13 on PIN27 -> PIO_PD2
REG_PIOD_SODR=(VH>>3) & 0x04;
//DB14 on PIN28 -> PIO_PD3
REG_PIOD_SODR=(VH>>3) & 0x08;
//DB15 on PIN29 -> PIO_PD6
REG_PIOD_SODR=(VH>>1) & 0x40;

pulse_low(P_WR, B_WR);
break;
}
}

void UTFT::_set_direction_registers(byte mode)
{
if (mode==16)
{
REG_PIOA_OER=0xc080; //PA7,PA14,PA15 enable
REG_PIOB_OER=0x4000000; //PB26 enable
REG_PIOC_OER=0x3e; //PC1 - PC5 enable
REG_PIOD_OER=0x64f; //PD0-3,PD6,PD9-10 enable
}
}


If it works, let me know and I use it, I have not tried.

If winds are going to send him UTFT developer to implement it.

regards


Go Up