From b99fcc6c8c180d0632560f1ba5c314f187f94c3f Mon Sep 17 00:00:00 2001 From: Serge Vakulenko Date: Thu, 8 Oct 2015 14:01:49 -0700 Subject: [PATCH] Use GPANEL_CLEAR ioctl to switch the display orientation. Enable gpio driver for Picadillo board. --- src/libgpanel/clear.c | 13 +++++++++++-- sys/include/gpanel.h | 9 +++++++-- sys/pic32/hx8357.c | 18 +++++++++++++++--- sys/pic32/picadillo/Config | 11 +++++++++++ sys/pic32/picadillo/Config-rambo | 31 ++++++++++++++----------------- sys/pic32/picadillo/Makefile | 19 +++++++++++++++---- 6 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/libgpanel/clear.c b/src/libgpanel/clear.c index 0f00f1a..6fdc12f 100644 --- a/src/libgpanel/clear.c +++ b/src/libgpanel/clear.c @@ -24,7 +24,16 @@ #include #include -void gpanel_clear(int color) +void gpanel_clear(int color, int *xsize, int *ysize) { - ioctl(_gpanel_fd, GPANEL_CLEAR, color); + struct gpanel_clear_t param; + + param.color = color; + param.xsize = xsize ? *xsize : 0; + param.ysize = ysize ? *ysize : 0; + ioctl(_gpanel_fd, GPANEL_CLEAR, ¶m); + if (xsize) + *xsize = param.xsize; + if (ysize) + *ysize = param.ysize; } diff --git a/sys/include/gpanel.h b/sys/include/gpanel.h index d6a6fb2..6c0de02 100644 --- a/sys/include/gpanel.h +++ b/sys/include/gpanel.h @@ -46,6 +46,11 @@ struct gpanel_pixel_t { int x, y; /* pixel position */ }; +struct gpanel_clear_t { + int color; /* pixel color */ + int xsize, ysize; /* screen size */ +}; + struct gpanel_line_t { int color; /* line color */ int x0, y0; /* start point */ @@ -86,7 +91,7 @@ struct gpanel_text_t { const char *text; /* UTF-8 text */ }; -#define GPANEL_CLEAR _IOW('g', 1, int) +#define GPANEL_CLEAR _IOW('g', 1, struct gpanel_clear_t) #define GPANEL_PIXEL _IOW('g', 2, struct gpanel_pixel_t) #define GPANEL_LINE _IOW('g', 3, struct gpanel_line_t) #define GPANEL_RECT _IOW('g', 4, struct gpanel_rect_t) @@ -102,7 +107,7 @@ struct gpanel_text_t { */ int gpanel_open(const char *devname); void gpanel_close(void); -void gpanel_clear(int color); +void gpanel_clear(int color, int *xsize, int *ysize); void gpanel_pixel(int color, int x, int y); void gpanel_line(int color, int x0, int y0, int x1, int y1); void gpanel_rect(int color, int x0, int y0, int x1, int y1); diff --git a/sys/pic32/hx8357.c b/sys/pic32/hx8357.c index aa0115f..fcf7ed6 100644 --- a/sys/pic32/hx8357.c +++ b/sys/pic32/hx8357.c @@ -207,7 +207,7 @@ static void setAddrWindow(int x0, int y0, int x1, int y1) writeCommand(HX8357_WRITE_MEMORY_START); //Write SRAM Data } -static inline void setRotation(int rotation) +static void setRotation(int rotation) { writeCommand(HX8357_SET_ADDRESS_MODE); switch (rotation & 3) { @@ -554,9 +554,21 @@ int hx8357_ioctl(dev_t dev, register u_int cmd, caddr_t addr, int flag) * Clear the whole screen with a given color. */ case GPANEL_CLEAR: { - int color = (int) addr; + struct gpanel_clear_t *param = (struct gpanel_clear_t*) addr; - fillRectangle(0, 0, _width, _height, color); + if (param->xsize != _width || param->ysize != _height) { + /* Change the screen orientation. */ + if (param->xsize > param->ysize) { + /* Landscape */ + setRotation(1); + } else if (param->xsize < param->ysize) { + /* Portrait */ + setRotation(0); + } + } + fillRectangle(0, 0, _width, _height, param->color); + param->xsize = _width; + param->ysize = _height; break; } diff --git a/sys/pic32/picadillo/Config b/sys/pic32/picadillo/Config index 790c72c..59ece06 100644 --- a/sys/pic32/picadillo/Config +++ b/sys/pic32/picadillo/Config @@ -36,11 +36,22 @@ options "CONS_MINOR=0" # /dev/tty0 # SPI ports controller spi2 # SD card +controller spi4 # SPI header # microSD card device sd0 at spi2 pin RG9 # select pin options "SD_MHZ=10" # speed 10 MHz +# General purpose I/O ports +# Flags define a mask of available pins +device gpio0 flags 0xc6fd # port A +device gpio1 flags 0x4fff # port B +device gpio2 flags 0x0010 # port C +device gpio3 flags 0xcf0f # port D +device gpio4 flags 0x0300 # port E +device gpio5 flags 0x110c # port F +device gpio6 flags 0xf000 # port G + # ADC driver device adc diff --git a/sys/pic32/picadillo/Config-rambo b/sys/pic32/picadillo/Config-rambo index 8b1b9f8..375c9ae 100644 --- a/sys/pic32/picadillo/Config-rambo +++ b/sys/pic32/picadillo/Config-rambo @@ -41,6 +41,16 @@ controller spi4 # RAM disk: spirams device sd0 at spi2 pin RG9 # select pin options "SD0_MHZ=10" # speed 10 MHz +# General purpose I/O ports +# Flags define a mask of available pins +device gpio0 flags 0xc608 # port A +device gpio1 flags 0x0fff # port B +device gpio2 flags 0x0010 # port C +device gpio3 flags 0x8e09 # port D +device gpio4 flags 0x0300 # port E +device gpio5 flags 0x110c # port F +device gpio6 flags 0x8000 # port G + # ADC driver device adc @@ -52,22 +62,9 @@ device hxtft # spirams - SPI block device device sr0 at spi4 -options "SPIRAMS_PORT=SPI4CON" # TODO: delete this option + pins RA0, RA1, RA4, RA5, # chip select signals + RA2, RD1, RD2, RB14, + RD14, RD8, RA6, RA7, + RG14, RG12, RG13, RF5 options "SPIRAMS_CHIPSIZE=128" # chip size in kbytes options "SPIRAMS_CHIPS=16" # number of chips -signal "SPIRAMS_CS0" pin RA0 -signal "SPIRAMS_CS1" pin RA1 -signal "SPIRAMS_CS2" pin RA4 -signal "SPIRAMS_CS3" pin RA5 -signal "SPIRAMS_CS4" pin RA2 -signal "SPIRAMS_CS5" pin RD1 -signal "SPIRAMS_CS6" pin RD2 -signal "SPIRAMS_CS7" pin RB14 -signal "SPIRAMS_CS8" pin RD14 -signal "SPIRAMS_CS9" pin RD8 -signal "SPIRAMS_CS10" pin RA6 -signal "SPIRAMS_CS11" pin RA7 -signal "SPIRAMS_CS12" pin RG14 -signal "SPIRAMS_CS13" pin RG12 -signal "SPIRAMS_CS14" pin RG13 -signal "SPIRAMS_CS15" pin RF5 diff --git a/sys/pic32/picadillo/Makefile b/sys/pic32/picadillo/Makefile index 2ee4a4e..09c6c9e 100644 --- a/sys/pic32/picadillo/Makefile +++ b/sys/pic32/picadillo/Makefile @@ -2,7 +2,15 @@ PARAM = -DPICADILLO_35T PARAM += -DPIC32MX7 PARAM += -DUART1_ENABLED PARAM += -DSPI2_ENABLED +PARAM += -DSPI4_ENABLED PARAM += -DSD_ENABLED +PARAM += -DGPIO_ENABLED +PARAM += -DGPIO1_ENABLED +PARAM += -DGPIO2_ENABLED +PARAM += -DGPIO3_ENABLED +PARAM += -DGPIO4_ENABLED +PARAM += -DGPIO5_ENABLED +PARAM += -DGPIO6_ENABLED PARAM += -DADC_ENABLED PARAM += -DPWM_ENABLED PARAM += -DHXTFT_ENABLED @@ -57,7 +65,7 @@ OBJS = exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o \ ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o \ vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o clock.o cons.o devsw.o \ exception.o machdep.o mem.o signal.o swap.o sysctl.o adc.o \ - hx8357.o pwm.o sd.o spi.o spi_bus.o uart.o + gpio.o hx8357.o pwm.o sd.o spi.o spi_bus.o uart.o CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ $S/kernel/exec_script.c $S/kernel/exec_subr.c \ @@ -82,9 +90,9 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \ $S/kernel/vm_swp.c $S/pic32/clock.c $S/pic32/cons.c \ $S/pic32/devsw.c $S/pic32/exception.c $S/pic32/machdep.c \ $S/pic32/mem.c $S/pic32/signal.c $S/pic32/swap.c \ - $S/pic32/sysctl.c $S/pic32/adc.c $S/pic32/hx8357.c \ - $S/pic32/pwm.c $S/pic32/sd.c $S/pic32/spi.c $S/pic32/spi_bus.c \ - $S/pic32/uart.c swapunix.c + $S/pic32/sysctl.c $S/pic32/adc.c $S/pic32/gpio.c \ + $S/pic32/hx8357.c $S/pic32/pwm.c $S/pic32/sd.c $S/pic32/spi.c \ + $S/pic32/spi_bus.c $S/pic32/uart.c swapunix.c # load lines for config "xxx" will be emitted as: # xxx: ${SYSTEM_DEP} swapxxx.o @@ -319,6 +327,9 @@ sysctl.o: $S/pic32/sysctl.c adc.o: $S/pic32/adc.c ${COMPILE_C} +gpio.o: $S/pic32/gpio.c + ${COMPILE_C} + hx8357.o: $S/pic32/hx8357.c ${COMPILE_C}