Initial: Übertrag der Tools/Scripte aus SVN

This commit is contained in:
Daniel Schick 2020-04-12 13:10:49 +02:00
commit e93e874748
21 changed files with 4315 additions and 0 deletions

6
imgFileUrlList.txt Normal file
View File

@ -0,0 +1,6 @@
https://www.dwd.de/DWD/warnungen/warnapp_gemeinden/json/warnungen_gemeinde_map_baw.png
https://www.dwd.de/DWD/wetter/aktuell/deutschland/bilder/wx_baw_akt.jpg
https://www.dwd.de/DWD/wetter/aktuell/deutschland/bilder/wx_shh_akt.jpg
https://www.dwd.de/DWD/wetter/aktuell/deutschland/bilder/wx_brd_akt.jpg
https://www.dwd.de/DWD/warnungen/warnapp_gemeinden/json/warnungen_gemeinde_map_de.png
https://www.dwd.de/DWD/wetter/radar/rad_baw_akt.jpg

23
readme.txt Normal file
View File

@ -0,0 +1,23 @@
Erster Idee:
Wir zeigen lediglich an BMP's aus einem Verzeichnis an, die bereits passend vorbereitet sind (hochkant gedreht, 240x320, 24bpp).
Diese werden "durchgeschaltet", irgendwann vielleicht auch mal gedreht.
CTRL-C / Beenden sollte abgefangen werden, damit das Display wieder zurückgesetzt werden kann (dunkel).
Datenquelle: Wetter Service URL's des DWD:
Warnkarte BW:
https://www.dwd.de/DWD/warnungen/warnapp_gemeinden/json/warnungen_gemeinde_map_baw.png
https://www.dwd.de/DWD/wetter/aktuell/deutschland/bilder/wx_baw_akt.jpg
https://www.dwd.de/DWD/wetter/aktuell/deutschland/bilder/wx_shh_akt.jpg
https://www.dwd.de/DWD/wetter/aktuell/deutschland/bilder/wx_brd_akt.jpg
https://www.dwd.de/DWD/warnungen/warnapp_gemeinden/json/warnungen_gemeinde_map_de.png
https://www.dwd.de/DWD/wetter/radar/rad_baw_akt.jpg
Weitere Hirngespinste:
- Fading / Übergangseffekt
- Wetteranzeige als Textdarstellung (selbst gezeichnet)
- andere Informationen (S-Bahn, RSS,..)
Zweite (auch umgesetzte Idee):
- Anzeige zufälliger Google Bilder. Das geht gut mit dem googlizer, einem passenden bash Script und
dem ebenfalls sehr mächtigen convert Tool von ImageMagick

15
script/googledl.sh Normal file
View File

@ -0,0 +1,15 @@
#! /bin/bash
OUTDIR="/home/pi/StatusBerry/img/"
DLDIR="/home/pi/StatusBerry/download/"
query=$(shuf -n1 /usr/share/dict/words)
rm -f $OUTDIR/*
rm -f $DLDIR/*
/home/pi/StatusBerry/script/googliser.sh -p $query -a tall -u 80000 -n 20 --no-gallery --output $DLDIR
for FILENAME in $DLDIR*; do
# BASEFILENAME="${FILENAME%.*}"
BASEFILENAME=$(basename "$FILENAME" | cut -d. -f1)
# image resize, rotate, draw text und so weiter :)
# CBerry ist etwas empfindlich was die BMP Parameter angeht! (exakte Größe, BMP3, 24bit)
# echo $BASEFILENAME
convert $FILENAME -resize 240x320! -gravity NorthEast -pointsize 18 -draw "text 0,4 '$query'" -rotate 90 -depth 24 -compress None -type truecolor -units PixelsPerInch -density 72 "BMP3:$OUTDIR$BASEFILENAME.bmp"
done

2110
script/googliser.sh Normal file

File diff suppressed because it is too large Load Diff

5
script/master.sh Normal file
View File

@ -0,0 +1,5 @@
#! /bin/bash
sudo /home/pi/StatusBerry/script/googledl.sh
sudo /home/pi/StatusBerry/src/bildercycle /home/pi/StatusBerry/img
# TFT wieder ausmachen
sudo /home/pi/C-Berry/SW/tft_init

35
script/wetterbilder.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/sh
# (c) schick Informatik
# Dieses Script lädt alle Bilder aus der angegebenen Textdatei herunter und konvertiert sie in
# C-Berry hochkant Format via convert (imagemagick)
# Achtung, die Bilder sollten alle unterschiedliche Namen haben (url)
#
IMGDIR="/home/pi/StatusBerry/download/"
OUTDIR="/home/pi/StatusBerry/img/"
IMGURLLIST="/home/pi/StatusBerry/imgFileUrlList.txt"
if [ ! -d "$IMGDIR" ]
then
echo "Directory $IMGDIR not found.."
exit 1
fi
if [ ! -f "$IMGURLLIST" ]
then
echo "Text file $IMGURLLIST with image url's not found.."
exit 1
fi
cat "$IMGURLLIST" | while read ANURL
do
# download image
wget -N -U Mozilla --directory-prefix=$IMGDIR "$ANURL"
FILENAME=$(basename $ANURL)
BASEFILENAME="${FILENAME%.*}"
# image resize and stuff
convert $IMGDIR$FILENAME -resize 240x320! -rotate 90 -depth 24 -compress None -type truecolor -units PixelsPerInch -density 72 "BMP3:$OUTDIR$BASEFILENAME.bmp"
done

342
src/RAIO8870.c Normal file
View File

@ -0,0 +1,342 @@
/*##############################################################*/
/* */
/* File : RAIO8870.c */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2013-11-22 last update: 2013-12-20 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* This file contain several functions to initialize and */
/* control the graphic controller RAIO8870. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#include <bcm2835.h>
#include "RAIO8870.h"
#include "tft.h"
uint16_t txc = 0x00; // character x position on screen
uint16_t tyc = 0x00; // character y position on screen
uint8_t char_higth = 15; // character hight depends on character set
#ifdef CM_4K
static uint8_t BankNo_WR=0, BankNo_RD=1;
#endif
// write command to a register
// ----------------------------------------------------------
void RAIO_SetRegister( uint8_t reg, uint8_t value )
{
TFT_RegWrite( (uint16_t)reg );
TFT_DataWrite( (uint16_t)value );
}
// set PWM value for backlight
// ----------------------------------------------------------
void RAIO_SetBacklightPWMValue( uint8_t BL_value )
{
RAIO_SetRegister( P1CR, 0x88 ); // Enable PWM1 output devider 256
RAIO_SetRegister( P1DCR, BL_value ); // -> BL_vaue = 0 (0% PWM) - 255 (100% PWM)
}
// initialization of RAIO8870
// ----------------------------------------------------------
void RAIO_init( void )
{
static uint8_t PLL_Initial_Flag = 0;
// *************** PLL settings (System Clock)
if ( !PLL_Initial_Flag ) // wait until PLL is ready
{
PLL_Initial_Flag = 1; // set Flag to avoid repeated PLL init
RAIO_SetRegister( PLLC1, 0x07 ); // set sys_clk
bcm2835_delayMicroseconds( 200 );
RAIO_SetRegister( PLLC2, 0x03 ); // set sys_clk
bcm2835_delayMicroseconds( 200 );
RAIO_SetRegister( PWRR, 0x01 ); // Raio software reset ( bit 0 ) set
RAIO_SetRegister( PWRR, 0x00 ); // Raio software reset ( bit 0 ) set to 0
delay( 100 );
// *************** color modes (color depths)
#ifdef CM_65K
// System Configuration Register
RAIO_SetRegister( SYSR, 0x0A ); // digital TFT
// parallel data out
// no external memory
// 8bit memory data bus
// 16bpp 65K color
// 16bit MCU-interface (data)
RAIO_SetRegister( DPCR, 0x00 ); // one layer
#elif defined(CM_4K)
// System Configuration Register
RAIO_SetRegister( SYSR, 0x06 ); // digital TFT
// parallel data out
// no external memory
// 8bit memory data bus
// 12bpp 4K color
// 16bit MCU-interface (data)
RAIO_SetRegister( DPCR, 0x80 ); // two layers
RAIO_SetRegister( MWCR1, BankNo_WR );
RAIO_SetRegister( LTPR0, BankNo_RD );
#else
#error "color_mode not defined"
#endif
}
// *************** horizontal settings
// 0x27+1 * 8 = 320 pixel
RAIO_SetRegister( HDWR , (DISPLAY_WIDTH / 8) - 1 );
RAIO_SetRegister( HNDFTR, 0x02 ); // Horizontal Non-Display Period Fine Tuning
// HNDR , Horizontal Non-Display Period Bit[4:0]
// Horizontal Non-Display Period (pixels) = (HNDR + 1)*8
RAIO_SetRegister( HNDR, 0x03 ); // 0x06
RAIO_SetRegister( HSTR, 0x04 ); //HSTR , HSYNC Start Position[4:0], HSYNC Start Position(PCLK) = (HSTR + 1)*8 0x02
// HPWR , HSYNC Polarity ,The period width of HSYNC.
// 1xxxxxxx activ high 0xxxxxxx activ low
// HSYNC Width [4:0] HSYNC Pulse width
// (PCLK) = (HPWR + 1)*8
RAIO_SetRegister( HPWR, 0x03 ); // 0x00
// ********************* vertical settings
// 0x0EF +1 = 240 pixel
RAIO_SetRegister( VDHR0 , ( (DISPLAY_HEIGHT-1) & 0xFF ) );
RAIO_SetRegister( VDHR1 , ( (DISPLAY_HEIGHT-1) >> 8) );
// VNDR0 , Vertical Non-Display Period Bit [7:0]
// Vertical Non-Display area = (VNDR + 1)
// VNDR1 , Vertical Non-Display Period Bit [8]
// Vertical Non-Display area = (VNDR + 1)
RAIO_SetRegister( VNDR0, 0x10 );
RAIO_SetRegister( VNDR1, 0x00 );
// VPWR , VSYNC Polarity ,VSYNC Pulse Width[6:0]
// VSYNC , Pulse Width(PCLK) = (VPWR + 1)
RAIO_SetRegister( VPWR, 0x00 );
// *************** miscellaneous settings
// active Window
Active_Window( 0, DISPLAY_WIDTH-1, 0, DISPLAY_HEIGHT-1 );
// PCLK fetch data on rising edge
RAIO_SetRegister( PCLK, 0x00 );
// Backlight dimming
RAIO_SetBacklightPWMValue(50);
Text_Background_Color( COLOR_WHITE );
// memory clear with background color
RAIO_SetRegister( MCLR, 0x81 );
TFT_wait_for_raio();
RAIO_SetRegister( IODR, 0x07 );
RAIO_SetRegister( PWRR, 0x80 );
}
// set coordinates for active window
// ----------------------------------------------------------
void Active_Window( uint16_t XL, uint16_t XR , uint16_t YT, uint16_t YB )
{
union my_union number;
//setting active window X
number.value = XL;
RAIO_SetRegister( HSAW0, number.split.low );
RAIO_SetRegister( HSAW1, number.split.high );
number.value = XR;
RAIO_SetRegister( HEAW0, number.split.low );
RAIO_SetRegister( HEAW1, number.split.high );
//setting active window Y
number.value = YT;
RAIO_SetRegister( VSAW0, number.split.low );
RAIO_SetRegister( VSAW1, number.split.high );
number.value = YB;
RAIO_SetRegister( VEAW0, number.split.low );
RAIO_SetRegister( VEAW1, number.split.high );
}
// show the BMP picture on the TFT screen
// ----------------------------------------------------------
void RAIO_Write_Picture( uint16_t *data, uint32_t count )
{
TFT_RegWrite( MRWC );
TFT_DataMultiWrite( data, count);
#ifdef CM_4K
if ( BankNo_WR==0 )
{
BankNo_WR=1;
BankNo_RD=0;
}
else
{
BankNo_WR=0;
BankNo_RD=1;
}
RAIO_SetRegister( MWCR1, BankNo_WR );
RAIO_SetRegister( LTPR0, BankNo_RD );
#endif
}
// set mode for BET (Block Transfer Engine)
// ----------------------------------------------------------
void BTE_mode( uint8_t bte_operation, uint8_t rop_function )
{
RAIO_SetRegister( BECR1, bte_operation | (rop_function<<4) );
}
// set color
// ----------------------------------------------------------
void Text_Background_Color( uint8_t color )
{
RAIO_SetRegister( TBCR, color );
}
void Text_Foreground_Color( uint8_t color)
{
RAIO_SetRegister( TFCR, color);
}
// set coordinates for drawing line and square
// ----------------------------------------------------------
void Set_Geometric_Coordinate(uint16_t X1, uint16_t Y1 ,uint16_t X2 ,uint16_t Y2 )
{
union my_union number;
number.value = X1;
RAIO_SetRegister( DLHSR0, number.split.low );
RAIO_SetRegister( DLHSR1, number.split.high );
number.value = Y1;
RAIO_SetRegister( DLVSR0, number.split.low );
RAIO_SetRegister( DLVSR1, number.split.high );
number.value = X2;
RAIO_SetRegister( DLHER0, number.split.low );
RAIO_SetRegister( DLHER1, number.split.high );
number.value = Y2;
RAIO_SetRegister( DLVER0, number.split.low );
RAIO_SetRegister( DLVER1, number.split.high );
}
// set coordinates for drawing circle
// ----------------------------------------------------------
void Set_Geometric_Coordinate_circle (uint16_t X1, uint16_t Y1 ,uint8_t rad )
{
union my_union number;
number.value = X1;
RAIO_SetRegister( DCHR0, number.split.low );
RAIO_SetRegister( DCHR1, number.split.high );
number.value = Y1;
RAIO_SetRegister( DCVR0, number.split.low );
RAIO_SetRegister( DCVR1, number.split.high );
RAIO_SetRegister( DCRR, rad );
}
// set draw mode
// ----------------------------------------------------------
void RAIO_StartDrawing( int16_t whattodraw )
{
switch( whattodraw ) // -> see DRAW_MODES
{
case CIRCLE_NONFILL: {RAIO_SetRegister( DCR, 0x40 ); break;}
case CIRCLE_FILL: {RAIO_SetRegister( DCR, 0x60 ); break;}
case SQUARE_NONFILL: {RAIO_SetRegister( DCR, 0x90 ); break;}
case SQUARE_FILL: {RAIO_SetRegister( DCR, 0xB0 ); break;}
case LINE: {RAIO_SetRegister( DCR, 0x80 ); break;}
default: break;
}
TFT_wait_for_raio();
}
// draw some basic geometrical forms
// ----------------------------------------------------------
void Draw_Line( uint16_t X1, uint16_t Y1 ,uint16_t X2 ,uint16_t Y2 )
{
Set_Geometric_Coordinate( X1, Y1, X2, Y2 );
RAIO_StartDrawing( LINE );
}
void Draw_Square( uint16_t X1, uint16_t Y1 ,uint16_t X2 ,uint16_t Y2 )
{
Set_Geometric_Coordinate( X1, Y1, X2, Y2 );
RAIO_StartDrawing( SQUARE_NONFILL );
}
void Draw_Circle( uint16_t X1, uint16_t Y1 ,uint8_t rad )
{
Set_Geometric_Coordinate_circle ( X1, Y1, rad );
RAIO_StartDrawing( CIRCLE_NONFILL );
}

337
src/RAIO8870.h Normal file
View File

@ -0,0 +1,337 @@
/*##############################################################*/
/* */
/* File : RAIO8870.h */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2013-11-22 last update: 2013-12-06 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* This file contains the defines of the RAIO register. */
/* Furthermore declared the file several functions to control */
/* the graphic controller RAIO8870. */
/* */
/* There can two different color depths to be set for the BMP */
/* output. It can be changed behind the line color modes. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#ifndef RAIO8870_H
#define RAIO8870_H
#include <stdint.h>
//color modes (color depths) { CM_4K=0, CM_65K };
#define CM_65K
// TFT dimensions
#define DISPLAY_WIDTH 320
#define DISPLAY_HEIGHT 240
#define PICTURE_PIXELS ( DISPLAY_WIDTH*DISPLAY_HEIGHT )
// RAIO register -> see datasheet RAIO8870
#define PCOD 0x00
#define PWRR 0x01
#define MRWC 0x02
#define PCLK 0x04
#define SYSR 0x10
#define DRGB 0x11
#define IOCR 0x12
#define IODR 0x13
#define HDWR 0x14
#define HNDFTR 0x15
#define HNDR 0x16
#define HSTR 0x17
#define HPWR 0x18
#define VDHR0 0x19
#define VDHR1 0x1a
#define VNDR0 0x1b
#define VNDR1 0x1c
#define VSTR0 0x1d
#define VSTR1 0x1e
#define VPWR 0x1f
#define DPCR 0x20
#define FNCR0 0x21
#define FNCR1 0x22
#define CGSR 0x23
#define HOFS0 0x24
#define HOFS1 0x25
#define VOFS0 0x26
#define VOFS1 0x27
#define ROMS 0x28
#define FLDR 0x29
#define HSAW0 0x30
#define HSAW1 0x31
#define VSAW0 0x32
#define VSAW1 0x33
#define HEAW0 0x34
#define HEAW1 0x35
#define VEAW0 0x36
#define VEAW1 0x37
#define HSSW0 0x38
#define HSSW1 0x39
#define VSSW0 0x3a
#define VSSW1 0x3b
#define HESW0 0x3c
#define HESW1 0x3d
#define VESW0 0x3e
#define VESW1 0x3f
#define MWCR0 0x40
#define MWCR1 0x41
#define TFCR 0x42
#define TBCR 0x43
#define BTCR 0x44
#define CURS 0x45
#define CURH0 0x46
#define CURH1 0x47
#define CURV0 0x48
#define CURV1 0x49
#define RCURH0 0x4a
#define RCURH01 0x4b
#define RCURV0 0x4c
#define RCURV1 0x4d
#define MRCD 0x4e
#define BECR0 0x50
#define BECR1 0x51
#define LTPR0 0x52
#define LTPR1 0x53
#define HSBE0 0x54
#define HSBE1 0x55
#define VSBE0 0x56
#define VSBE1 0x57
#define HDBE0 0x58
#define HDBE1 0x59
#define VDBE0 0x5a
#define VDBE1 0x5b
#define BEWR0 0x5c
#define BEWR1 0x5d
#define BEHR0 0x5e
#define BEHR1 0x5f
#define BGCR0 0x60
#define BGCR1 0x61
#define BGCR2 0x62
#define FGCR0 0x63
#define FGCR1 0x64
#define FGCR2 0x65
#define PTNO 0x66
#define BGTR 0x67
#define TPCR0 0x70
#define TPCR1 0x71
#define TPXH 0x72
#define TPYH 0x73
#define TPXYL 0x74
#define GCHP0 0x80
#define GCHP1 0x81
#define GCVP0 0x82
#define GCVP1 0x83
#define GCC0 0x84
#define GCC1 0x85
#define PLLC1 0x88
#define PLLC2 0x89
#define P1CR 0x8a
#define P1DCR 0x8b
#define P2CR 0x8c
#define P2DCR 0x8d
#define MCLR 0x8e
#define INTC 0x8f
#define DCR 0x90
#define DLHSR0 0x91
#define DLHSR1 0x92
#define DLVSR0 0x93
#define DLVSR1 0x94
#define DLHER0 0x95
#define DLHER1 0x96
#define DLVER0 0x97
#define DLVER1 0x98
#define DCHR0 0x99
#define DCHR1 0x9a
#define DCVR0 0x9b
#define DCVR1 0x9c
#define DCRR 0x9d
#define TCR1 0xa0
#define TCR2 0xa1
#define OEHTCR1 0xa2
#define OEHTCR2 0xa3
#define OEHTCR3 0xa4
#define OEHTCR4 0xa5
#define OEHTCR5 0xa6
#define OEHTCR6 0xa7
#define OEHTCR7 0xa8
#define OEHTCR8 0xa9
#define STHTCR1 0xaa
#define STHTCR2 0xab
#define STHTCR3 0xac
#define STHTCR4 0xad
#define Q1HCR1 0xae
#define Q1HCR2 0xaf
#define OEVTCR1 0xb0
#define OEVTCR2 0xb1
#define OEVTCR3 0xb2
#define OEVTCR4 0xb3
#define CKVTCR1 0xb4
#define CKVTCR2 0xb5
#define CKVTCR3 0xb6
#define CKVTCR4 0xb7
#define STVTCR1 0xb8
#define STVTCR2 0xb9
#define STVTCR3 0xba
#define STVTCR4 0xbb
#define STVTCR5 0xbc
#define STVTCR6 0xbd
#define STVTCR7 0xbe
#define STVTCR8 0xbf
#define COMTCR1 0xc0
#define COMTCR2 0xc1
#define RGBTCR1 0xc2
#define RGBTCR2 0xc3
// some colors RRRGGGBB
#define COLOR_RED 0xE0
#define COLOR_BLUE 0x03
#define COLOR_GREEN 0x1C
#define COLOR_BLACK 0x00
#define COLOR_WHITE 0xFF
#define COLOR_CYAN 0x1F
#define COLOR_YELLOW 0xFC
#define COLOR_MAGENTA 0xE3
#define COLOR_DARK_GREEN 0x0C
// ROP functions
#define ROP_SOURCE 0xC
// BTE operation functions
#define BTE_MOVE_POSITIVE 0x02
#define BTE_SOLID_FILL 0x0C
// declaration of a union (used in RAIO8870.c and tft.c)
// ----------------------------------------------------------
union my_union
{
uint32_t value;
struct
{
unsigned char low;
unsigned char high;
} split;
};
// enumeration of drawing modes
// ----------------------------------------------------------
enum DRAW_MODES { CIRCLE_NONFILL, CIRCLE_FILL, SQUARE_NONFILL, SQUARE_FILL, LINE};
// initialization of RAIO8870
// ----------------------------------------------------------
void RAIO_init( void );
// write command to a register
// ----------------------------------------------------------
void RAIO_SetRegister( uint8_t reg, uint8_t value );
// set PWM value for backlight -> 0 (0% PWM) - 255 (100% PWM)
// ----------------------------------------------------------
void RAIO_SetBacklightPWMValue( uint8_t BL_value );
// set coordinates for active window
// ----------------------------------------------------------
void Active_Window(uint16_t XL,uint16_t XR ,uint16_t YT ,uint16_t YB);
// set mode for BET (Block Transfer Engine)
// ----------------------------------------------------------
void BTE_mode( uint8_t bte_operation, uint8_t rop_function );
// set color
// ----------------------------------------------------------
void Text_Background_Color( uint8_t color );
void Text_Foreground_Color( uint8_t color );
// set coordinates for drawing
// ----------------------------------------------------------
void Set_Geometric_Coordinate( uint16_t X1, uint16_t Y1 ,uint16_t X2 ,uint16_t Y2 );
void Set_Geometric_Coordinate_circle (uint16_t X1, uint16_t Y1 ,uint8_t rad );
// show the BMP picture on the TFT screen
// ----------------------------------------------------------
void RAIO_Write_Picture( uint16_t *data, uint32_t count );
// set draw mode -> see DRAW_MODES
// ----------------------------------------------------------
void RAIO_StartDrawing( int16_t whattodraw );
// draw some basic geometrical forms
// ----------------------------------------------------------
void Draw_Line( uint16_t X1, uint16_t Y1 ,uint16_t X2 ,uint16_t Y2 );
void Draw_Square( uint16_t X1, uint16_t Y1 ,uint16_t X2 ,uint16_t Y2 );
#endif

194
src/ST7789.c Normal file
View File

@ -0,0 +1,194 @@
/*##############################################################*/
/* */
/* File : ST7789.c */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* This file contain several functions to initialize and */
/* control the tft controller ST7789. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#include <bcm2835.h>
#include <stdio.h>
#include <stdarg.h>
#include "ST7789.h"
#include "tft.h"
#include "bmp.h"
// initialization of ST7789
// ----------------------------------------------------------
void STcontroller_init( void )
{
// *************** wakeup display
STcontroller_SetRegister(SLPOUT, 0);
bcm2835_delay(120);
// *************** display and color format setting
// write data from top-left to bottom-right
STcontroller_SetRegister(MADCTL, 1, 0xA0); // 0x00
#ifdef CM_262K
// 18bit/pixel
// 262K-colors (RGB 6-6-6)
STcontroller_SetRegister(COLMOD, 1, 0x06);
#elif defined(CM_65K)
// 16bit/pixel
// 65K-colors (RGB 5-6-5)
STcontroller_SetRegister(COLMOD, 1, 0x05);
#else
#error "color_mode not defined"
#endif
// *************** ST7789 porch setting
// seperate porch control = disabled
// front porch in normal mode = 13 CLK pulse
// back porch in normal mode = 13 CLK pulse
// front porch in idle mode = 3 CLK pulse
// back porch in idle mode = 3 CLK pulse
// front porch in partial mode = 3 CLK pulse
// back porch in partial mode = 3 CLK pulse
STcontroller_SetRegister(PORCTRL, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33);
// *************** ST7789 Power setting
// VGH = 13.26V=0x03
// VGL = -10.43V=0x05
STcontroller_SetRegister( GCTRL, 1, 0x35 );
// VDV and VRH register value comes from command line
STcontroller_SetRegister( VDVVRHEN, 2, 0x01, 0xFF );
// VAP = 4.7 + Vcom + Vcom_offset + 0.5*VDV//0x17h
STcontroller_SetRegister( VRHS, 1, 0x17 );
// VDV = 0V //VDVS[5:0]=20h
STcontroller_SetRegister( VDVSET, 1, 0x20 );
// Vcom = 0.675V
STcontroller_SetRegister( VCOMS, 1, 0x17 );
// Vcom_offset = 0V
STcontroller_SetRegister( VCMOFSET, 1, 0x20 );
// AVDD = 6.8V
// AVCL = -4.8V//0x02
// VDS = 2.3V//0x01
STcontroller_SetRegister(PWCTRL1, 2, 0xA4, 0xA1);
// *************** ST7789 gamma setting
STcontroller_SetRegister(PVGAMCTRL, 14, 0xD0, 0x00, 0x14, 0x15, 0x13, 0x2C, 0x42, 0x43, 0x4E, 0x09, 0x16, 0x14, 0x18, 0x21);
STcontroller_SetRegister(NVGAMCTRL, 14, 0xD0, 0x00, 0x14, 0x15, 0x13, 0x0B, 0x43, 0x55, 0x53, 0x0C, 0x17, 0x14, 0x23, 0x20);
// *************** miscellaneous settings
// define area (start row, end row, start column, end column) of frame memory where MCU can access
set_row( 0, DISPLAY_HEIGHT - 1 );
set_column( 0, DISPLAY_WIDTH - 1 );
// *************** display on
STcontroller_SetRegister(DISPON, 0);
}
// write command to a register
// ----------------------------------------------------------
void STcontroller_SetRegister( int reg, int count, ... )
{
int i;
va_list args;
va_start(args, count);
TFT_RegWrite ( reg );
for( i=count; i > 0; i-- )
{
TFT_DataWrite ( (uint8_t)va_arg(args, int) );
}
va_end(args);
}
// show the BMP picture on the TFT screen
// ----------------------------------------------------------
#ifdef CM_262K
void STcontroller_Write_Picture( uint32_t *data, uint32_t count )
#else
void STcontroller_Write_Picture( uint16_t *data, uint32_t count )
#endif
{
TFT_RegWrite( RAMWR );
TFT_DataMultiWrite( data, count );
}
// define area of frame memory where MCU can access
// ----------------------------------------------------------
void set_row( uint16_t row_start, uint16_t row_end )
{
union my_union start;
union my_union end;
start.value = row_start;
end.value = row_end;
STcontroller_SetRegister( RASET, 4, start.split.high, start.split.low, end.split.high, end.split.low );
}
void set_column( uint16_t col_start, uint16_t col_end )
{
union my_union start;
union my_union end;
start.value = col_start;
end.value = col_end;
STcontroller_SetRegister( CASET, 4, start.split.high, start.split.low, end.split.high, end.split.low );
}

187
src/ST7789.h Normal file
View File

@ -0,0 +1,187 @@
/*##############################################################*/
/* */
/* File : ST7789.h */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* This file contains the defines of the ST register. */
/* Furthermore declared the file several functions to control */
/* the tft controller ST7789. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#ifndef ST7789_H
#define ST7789_H
#include <stdint.h>
#include <stdarg.h>
//color modes (color depths) { CM_262K, CM_65K };
#define CM_65K
// TFT dimensions
#define DISPLAY_WIDTH 320
#define DISPLAY_HEIGHT 240
#define PICTURE_PIXELS ( DISPLAY_WIDTH*DISPLAY_HEIGHT )
// ST register -> see datasheet ST7789
#define NOP 0x00
#define SWRESET 0x01
#define RDDID 0x04
#define RDDST 0x09
#define RDDPM 0x0A
#define RDDMADCTL 0x0B
#define RDDCOLMOD 0x0C
#define RDDIM 0x0D
#define RDDSM 0x0E
#define RDDSDR 0x0F
#define SLPIN 0x10
#define SLPOUT 0x11
#define PTLON 0x12
#define NORON 0x13
#define INVOFF 0x20
#define INVON 0x21
#define GAMSET 0x26
#define DISPOFF 0x28
#define DISPON 0x29
#define CASET 0x2A
#define RASET 0x2B
#define RAMWR 0x2C
#define RAMRD 0x2E
#define PTLAR 0x30
#define VSCRDEF 0x33
#define TEOFF 0x34
#define TEON 0x35
#define MADCTL 0x36
#define VSCRSADD 0x37
#define IDMOFF 0x38
#define IDMON 0x39
#define COLMOD 0x3A
#define RAMWRC 0x3C
#define RAMRDC 0x3E
#define TESCAN 0x44
#define RDTESCAN 0x45
#define WRDISBV 0x51
#define RDDISBV 0x52
#define WRCTRLD 0x53
#define RDCTRLD 0x54
#define WRCACE 0x55
#define RDCABC 0x56
#define WRCABCMB 0x5E
#define RDCABCMB 0x5F
#define RDID1 0xDA
#define RDID2 0xDB
#define RDID3 0xDC
#define RAMCTRL 0xB0
#define RGBCTRL 0xB1
#define PORCTRL 0xB2
#define FRCTRL1 0xB3
#define GCTRL 0xB7
#define DGMEN 0xBA
#define VCOMS 0xBB
#define LCMCTRL 0xC0
#define IDSET 0xC1
#define VDVVRHEN 0xC2
#define VRHS 0xC3
#define VDVSET 0xC4
#define VCMOFSET 0xC5
#define FRCTRL2 0xC6
#define CABCCTRL 0xC7
#define REGSEL1 0xC8
#define REGSEL2 0xCA
#define PWCTRL1 0xD0
#define VAPVANEN 0xD2
#define PVGAMCTRL 0xE0
#define NVGAMCTRL 0xE1
#define DGMLUTR 0xE2
#define DGMLUTB 0xE3
#define GATECTRL 0xE4
#define PWCTRL2 0xE8
#define EQCTRL 0xE9
#define PROMCTRL 0xEC
#define PROMEN 0xFA
#define NVMSET 0xFC
#define PROMACT 0xFE
// declaration of a union (used in ST7789.c and tft.c)
// ----------------------------------------------------------
/*
union my_union
{
uint16_t value;
struct
{
unsigned char low;
unsigned char high;
} split;
};
*/
// initialization of ST7789
// ----------------------------------------------------------
void STcontroller_init( void );
// write command to a register
// ----------------------------------------------------------
void STcontroller_SetRegister( int reg, int count, ... );
// show the BMP picture on the TFT screen
// ----------------------------------------------------------
#ifdef CM_262K
void STcontroller_Write_Picture( uint32_t *data, uint32_t count );
#else
void STcontroller_Write_Picture( uint16_t *data, uint32_t count );
#endif
// define area of frame memory where MCU can access
// ----------------------------------------------------------
void set_row( uint16_t row_start, uint16_t row_end );
void set_column( uint16_t col_start, uint16_t col_end );
#endif

147
src/bildercycle.c Normal file
View File

@ -0,0 +1,147 @@
/* ------------------------------------------------------------------
* (c) schick Informatik 2017
* Hilfsprogramm, um Bilder aus einem Verzeichnis auf dem TFT CBerry
* anzuzeigen.
* ------------------------------------------------------------------ */
#include <bcm2835.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include "tft.h"
#include "ST7789.h"
#include "bmp.h"
#include "examples.h"
#ifdef CM_262K
uint32_t** imageList;
#else
uint16_t** imageList;
#endif
#define INTERVAL 15
int MAXCNT = 256;
int numImages = 0;
int main( int argc, char **argv )
{
if(argc < 2) {
printf("Usage: bildercycle <path>\n");
return 1;
}
char *sourcePath = argv[1];
#ifdef CM_262K
imageList = calloc(MAXCNT, sizeof(uint32_t*));
#else
imageList = calloc(MAXCNT, sizeof(uint16_t*));
#endif
if(ReadFromDirectory(sourcePath)) {
fprintf(stderr, "Error reading images from source path %s\n", sourcePath);
return 1;
}
printf("%d images read\n", numImages);
if (!bcm2835_init()) {
fprintf(stderr, "Error initializing TFT (bcm2835_init)\n");
return 1;
}
TFT_init_board();
TFT_hard_reset();
STcontroller_init();
TFT_SetBacklightPWMValue( 20 );
// depict a BMP file
// ---------------------------------------------
//example_DepictBMP( &my_filename[0] );
int i;
for(i=0;i<numImages;i++)
{
STcontroller_Write_Picture ( imageList[i], PICTURE_PIXELS );
//printf("[%d]", i);
//fflush(stdout);
sleep(INTERVAL);
}
bcm2835_close();
return 0;
}
int ReadFromDirectory(char *in_dir)
{
DIR* FD;
struct dirent* in_file;
FILE *entry_file;
char buffer[BUFSIZ];
int32_t result = 1;
fprintf(stderr, "reading %s\n", in_dir);
/* Scanning the in directory */
if (NULL == (FD = opendir (in_dir)))
{
fprintf(stderr, "Error : Failed to open input directory - %s\n", strerror(errno));
return 1;
}
while ((in_file = readdir(FD)))
{
/* On linux/Unix we don't want current and parent directories
* On windows machine too, thanks Greg Hewgill
*/
if (!strcmp (in_file->d_name, ".")) continue;
if (!strcmp (in_file->d_name, "..")) continue;
/* Open directory entry file for common operation */
/* TODO : change permissions to meet your need! */
char *bmpFileName = calloc(strlen(in_file->d_name) + strlen(in_dir) + 2, sizeof(char *));
sprintf(bmpFileName, "%s/%s", in_dir, in_file->d_name);
// fprintf(stderr, "reading %s..\n", bmpFileName);
#ifdef CM_262K
imageList[numImages] = calloc(PICTURE_PIXELS, sizeof(uint32_t));
// Achtung Funktion liest von hinten nach vorn, daher den Bilderzeiger auf das letzte Pixel setzen
result = Read_bmp2memory ( bmpFileName, &imageList[numImages][PICTURE_PIXELS - 1] );
#else
imageList[numImages] = calloc(PICTURE_PIXELS, sizeof(uint16_t));
result = Read_bmp2memory ( bmpFileName, &imageList[numImages][PICTURE_PIXELS - 1] );
#endif
if(result) {
fprintf(stderr,"reading BMP %s failed\n", in_file->d_name);
} else {
result = 0; // at least one! successful
numImages++;
}
/*
entry_file = fopen(in_file->d_name, "r");
if (entry_file == NULL)
{
fprintf(stderr, "Error : Failed to open entry file - %s\n", strerror(errno));
fclose(common_file);
return 1;
}
*/
}
return result;
}

0
src/bildercycle.h Normal file
View File

206
src/bmp.c Normal file
View File

@ -0,0 +1,206 @@
/*##############################################################*/
/* */
/* File : bmp.c */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* The current software can display BMP files on the C-Berry. */
/* The BMP file must have a dimension of 320 x 240 pixel and */
/* a color depth of 24Bit. */
/* The picture(s) will be stored into a memory. The function */
/* returns back a pointer with the address of the memory. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "bmp.h"
#include "ST7789.h"
#include <bcm2835.h>
// store BMP files in memory
// ----------------------------------------------------------
#ifdef CM_262K
int32_t Read_bmp2memory ( char const *file_name, uint32_t *picture_pointer )
#else
int32_t Read_bmp2memory ( char const *file_name, uint16_t *picture_pointer )
#endif
{
FILE *my_file;
// bmp_header_t bmp_header;
uint8_t bmp_header_buffer[54];
uint8_t bmp_line_buffer[ DISPLAY_WIDTH * 3 ];
uint16_t bfType;
uint32_t bfOffBits;
uint32_t biSize;
int32_t biWidth;
int32_t biHeight;
uint16_t biBitCount;
uint32_t y,x;
uint8_t red, green, blue;
uint32_t color;
// check for file
// printf( "Opening input file...%s ", file_name );
if( ( my_file = fopen( file_name, "rb" ) ) == NULL )
{
printf( "ERROR: Could not open input file for reading: %s\n", strerror(errno) );
return( -1 );
}
//printf( "OK\n" );
// read header
fread( &bmp_header_buffer, 1, 54, my_file );
// check for "BM"
//printf( "Checking magic number... " );
bfType = bmp_header_buffer[1];
bfType = (bfType << 8) | bmp_header_buffer[0];
if( bfType != 0x4D42)
{
printf( "ERROR: Not a bitmap file.\n" );
fclose( my_file );
return( -1 );
}
//printf( "OK\n" );
//printf( "Checking header size... " );
biSize = bmp_header_buffer[17];
biSize = (biSize << 8) | bmp_header_buffer[16];
biSize = (biSize << 8) | bmp_header_buffer[15];
biSize = (biSize << 8) | bmp_header_buffer[14];
//printf( "%d ", biSize);
if( biSize != 40 )
{
printf( "ERROR: Not Windows V3\n" );
fclose( my_file );
return( -1 );
}
//printf( "OK\n" );
//printf( "Checking dimensions... " );
biWidth = bmp_header_buffer[21];
biWidth = (biWidth << 8) | bmp_header_buffer[20];
biWidth = (biWidth << 8) | bmp_header_buffer[19];
biWidth = (biWidth << 8) | bmp_header_buffer[18];
biHeight = bmp_header_buffer[25];
biHeight = (biHeight << 8) | bmp_header_buffer[24];
biHeight = (biHeight << 8) | bmp_header_buffer[23];
biHeight = (biHeight << 8) | bmp_header_buffer[22];
biBitCount = bmp_header_buffer[29];
biBitCount = (biBitCount << 8) | bmp_header_buffer[28];
//printf( "%dx%dx%dbbp. ", biWidth, biHeight, biBitCount );
if( (biWidth != DISPLAY_WIDTH) || (biHeight != DISPLAY_HEIGHT) || (biBitCount != 24) )
{
printf( "ERROR. %dx%dx%d required.\n", DISPLAY_WIDTH, DISPLAY_HEIGHT, 24 );
fclose( my_file );
return( -1 );
}
//printf( "OK\n\n" );
bfOffBits = bmp_header_buffer[13];
bfOffBits = (bfOffBits << 8) | bmp_header_buffer[12];
bfOffBits = (bfOffBits << 8) | bmp_header_buffer[11];
bfOffBits = (bfOffBits << 8) | bmp_header_buffer[10];
//printf( "biOffBits = %d\n", bfOffBits );
fseek( my_file, bfOffBits, SEEK_SET );
//printf( "Filling picture buffer... \n" );
for (y=DISPLAY_HEIGHT; y>0; y--)
{
fread( &bmp_line_buffer[0], sizeof(bmp_line_buffer), 1, my_file );
for (x=DISPLAY_WIDTH; x>0; x--)
{
blue = bmp_line_buffer[(x-1)*3 +0];
green = bmp_line_buffer[(x-1)*3 +1];
red = bmp_line_buffer[(x-1)*3 +2];
#ifdef CM_262K
color = (red >> 2);
color = color << 8;
color = color | (green >> 2);
color = color << 8;
color = color | (blue >> 2);
color = color << 2;
#elif defined(CM_65K)
color = (red >> 3);
color = color << 6;
color = color | (green >> 2);
color = color << 5;
color = color | (blue >> 3);
#else
#error "color_mode not defined"
#endif
*picture_pointer = color;
picture_pointer--;
}
}
fclose( my_file );
return ( 0 );
}

70
src/bmp.h Normal file
View File

@ -0,0 +1,70 @@
/*##############################################################*/
/* */
/* File : bmp.h */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* The current software can display BMP files on the C-Berry. */
/* The BMP file must have a dimension of 320 x 240 pixel and */
/* a color depth of 24Bit. */
/* The picture(s) will be stored into a memory. The function */
/* returns back a pointer with the address of the memory. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#ifndef BMP_H
#define BMP_H
#include <stdint.h>
#include "ST7789.h"
// store BMP files in memory
// ----------------------------------------------------------
#ifdef CM_262K
int32_t Read_bmp2memory ( char const *file_name, uint32_t *picture_pointer );
#else
int32_t Read_bmp2memory ( char const *file_name, uint16_t *picture_pointer );
#endif
#endif

71
src/examples.c Normal file
View File

@ -0,0 +1,71 @@
/*##############################################################*/
/* */
/* File : examples.c */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* Exmples.c includes the following functions to demonstrate */
/* some opportunities: */
/* - depict one BMP file on the TFT */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#include <stdio.h>
#include <stdint.h>
#include "ST7789.h"
#include "bmp.h"
#include "examples.h"
// load and depict a BMP file
// ---------------------------------------------
void example_DepictBMP( char const *file_name )
{
#ifdef CM_262K
uint32_t picture[1][ PICTURE_PIXELS ];
#else
uint16_t picture[1][ PICTURE_PIXELS ];
#endif
Read_bmp2memory ( file_name, &picture[0][ PICTURE_PIXELS-1 ] );
STcontroller_Write_Picture ( &picture[0][0], PICTURE_PIXELS );
}

59
src/examples.h Normal file
View File

@ -0,0 +1,59 @@
/*##############################################################*/
/* */
/* File : examples.h */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* This file declared functions for the different examples in */
/* example.c */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#ifndef EXAMPLES_H
#define EXAMPLES_H
#include <stdint.h>
// load and depict a BMP file
// ---------------------------------------------
void example_DepictBMP( char const *file_name );
#endif

20
src/makefile Normal file
View File

@ -0,0 +1,20 @@
all: bildercycle
bildercycle: bildercycle.o ST7789.o bmp.o tft.o
gcc -g bildercycle.o tft.o ST7789.o bmp.o -lbcm2835 -lrt -lm -o bildercycle
tft.o: tft.c tft.h ST7789.h
gcc -g -c tft.c
ST7789.o: ST7789.c ST7789.h
gcc -g -c ST7789.c
bmp.o: bmp.c bmp.h ST7789.h
gcc -g -c bmp.c
examples.o: examples.c examples.h ST7789.h bmp.h
gcc -Os -c examples.c
clean:
rm -rf *o bildercycle

193
src/tft.c Normal file
View File

@ -0,0 +1,193 @@
/*##############################################################*/
/* */
/* File : tft.c */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* This file controlls the communications between the */
/* Raspberry Pi and the TFT. The file initialized also the */
/* GPIO Pins of the Raspberry Pi. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#include <stdint.h>
#include <stdarg.h>
#include <stdio.h>
#include <bcm2835.h>
#include "ST7789.h"
#include "tft.h"
// initialization of GPIO and SPI
// ----------------------------------------------------------
void TFT_init_board ( void )
{
// *************** set the pins to be an output and turn them on
bcm2835_gpio_fsel( ST_RS, BCM2835_GPIO_FSEL_OUTP );
bcm2835_gpio_write( ST_RS, HIGH );
bcm2835_gpio_fsel( ST_RST, BCM2835_GPIO_FSEL_OUTP );
bcm2835_gpio_write( ST_RST, HIGH );
// *************** set pins for PWM
bcm2835_gpio_fsel( BL_PWM, BCM2835_GPIO_FSEL_ALT5 );
// Clock divider is set to 16.
// 1.2MHz/1024 = 1171.875Hz
bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_16);
bcm2835_pwm_set_mode(PWM_CHANNEL, 1, 1);
bcm2835_pwm_set_range(PWM_CHANNEL, PWM_RANGE);
// *************** set pins for SPI
bcm2835_gpio_fsel(MOSI, BCM2835_GPIO_FSEL_ALT0);
bcm2835_gpio_fsel(SCLK, BCM2835_GPIO_FSEL_ALT0);
bcm2835_gpio_fsel(SPI_CE0, BCM2835_GPIO_FSEL_ALT0);
// set the SPI CS register to the some sensible defaults
volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/8;
bcm2835_peri_write( paddr, 0 ); // All 0s
// clear TX and RX fifos
bcm2835_peri_write_nb( paddr, BCM2835_SPI0_CS_CLEAR );
bcm2835_spi_setBitOrder( BCM2835_SPI_BIT_ORDER_MSBFIRST );
bcm2835_spi_setDataMode( BCM2835_SPI_MODE0 );
bcm2835_spi_setClockDivider( BCM2835_SPI_CLOCK_DIVIDER_2 );
bcm2835_spi_chipSelect( BCM2835_SPI_CS0 );
bcm2835_spi_setChipSelectPolarity( BCM2835_SPI_CS0, LOW );
}
// hard reset of the tft controller
// ----------------------------------------------------------
void TFT_hard_reset( void )
{
bcm2835_delay( 1 );
bcm2835_gpio_write( ST_RST, LOW );
bcm2835_delay( 10 );
bcm2835_gpio_write( ST_RST, HIGH );
bcm2835_delay( 120 );
}
// write byte to register
// ----------------------------------------------------------
void TFT_RegWrite( uint8_t reg )
{
bcm2835_gpio_write( ST_RS, LOW );
TFT_SPI_data_out ( reg );
}
// write byte to tft
// ----------------------------------------------------------
void TFT_DataWrite( uint8_t value )
{
bcm2835_gpio_write( ST_RS, HIGH );
TFT_SPI_data_out ( value );
}
// write 3 * 'count'-bytes to tft
// ----------------------------------------------------------
#ifdef CM_262K
void TFT_DataMultiWrite( uint32_t *data, uint32_t count )
#else
void TFT_DataMultiWrite( uint16_t *data, uint32_t count )
#endif
{
volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4;
volatile uint32_t* fifo = bcm2835_spi0 + BCM2835_SPI0_FIFO/4;
volatile uint32_t* gpio_set = bcm2835_gpio + BCM2835_GPSET0/4;
volatile uint32_t* gpio_clear = bcm2835_gpio + BCM2835_GPCLR0/4;
uint32_t i;
bcm2835_gpio_write( ST_RS, HIGH );
for( i=0; i<count; i++ )
{
// activate SPI transfer
*paddr |= BCM2835_SPI0_CS_TA;
// fill the FIFO
#ifdef CM_262K
*fifo = (uint8_t)(data[i] >> 16);
#endif
*fifo = (uint8_t)(data[i] >> 8);
*fifo = (uint8_t)(data[i] & 0xFF);
// write fifo data to SPI TX buffer
while (!(*paddr & BCM2835_SPI0_CS_DONE))
{
// clear SPI RX buffer
*paddr |=BCM2835_SPI0_CS_CLEAR_RX;
};
// deactivate SPI transfer
*paddr &= ~BCM2835_SPI0_CS_TA;
// if(i>3) { while(1); }
}
}
// write data via SPI to tft
// ----------------------------------------------------------
void TFT_SPI_data_out ( uint8_t data )
{
bcm2835_spi_writenb( &data, 1 );
}
// set PWM value for backlight -> 0 (0% PWM) - 1024 (100% PWM)
// ----------------------------------------------------------
void TFT_SetBacklightPWMValue( uint8_t BL_value )
{
bcm2835_pwm_set_data( PWM_CHANNEL, BL_value );
}

111
src/tft.h Normal file
View File

@ -0,0 +1,111 @@
/*##############################################################*/
/* */
/* File : tft.h */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* This file declared functions for the SPI communications */
/* between the Raspberry Pi and the TFT and for the */
/* initialization of the GPIO Pins of the Raspberry Pi. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#ifndef TFT_H
#define TFT_H
#include <stdint.h>
#include "ST7789.h"
#define MOSI RPI_V2_GPIO_P1_19
#define SCLK RPI_V2_GPIO_P1_23
#define SPI_CE0 RPI_V2_GPIO_P1_24
#define ST_RST RPI_V2_GPIO_P1_22
#define ST_RS RPI_V2_GPIO_P1_15
#define BL_PWM RPI_V2_GPIO_P1_12
// PWM settings
#define PWM_CHANNEL 0
#define PWM_RANGE 255
// initialization of GPIO and SPI
// ----------------------------------------------------------
void TFT_init_board( void );
// hard reset of the graphic controller and the tft
// ----------------------------------------------------------
void TFT_hard_reset( void );
// write byte to register
// ----------------------------------------------------------
void TFT_RegWrite( uint8_t reg );
// write byte to tft
// ----------------------------------------------------------
void TFT_DataWrite( uint8_t value );
// write 'count'-bytes to tft
// ----------------------------------------------------------
#ifdef CM_262K
void TFT_DataMultiWrite( uint32_t *data, uint32_t count );
#else
void TFT_DataMultiWrite( uint16_t *data, uint32_t count );
#endif
// write data via SPI to tft
// ----------------------------------------------------------
void TFT_SPI_data_out ( uint8_t data );
// set PWM value for backlight -> 0 (0% PWM) - PWM_RANGE (100% PWM)
// PWM channel 0
// MARKSPACE mode
// ----------------------------------------------------------
void TFT_SetBacklightPWMValue( uint8_t BL_value );
#endif

98
src/tft_string.c Normal file
View File

@ -0,0 +1,98 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "RAIO8870.h"
#include <string.h>
int main( int argc, char *argv[] )
{
if( argc !=9 ){
printf("\ntft_string: Error! Use 'tft_string fontsize pos_x pos_y textcolor backgroundcolor transparenz bold textstring'\n");
exit(1);
}
char text[255];
strcpy(text,argv[8]);
int fsf=atoi(argv[1]);
int px=atoi(argv[2]);
int py=atoi(argv[3]);
int col_fg=atoi(argv[4]);
int col_bg=atoi(argv[5]);
int transparent=atoi(argv[6]);
int bold=atoi(argv[7]);
if (!bcm2835_init()){
printf("tft_string: Error, check your display! \n");
exit(1);
}
if( strlen(text) > 255){
printf("tft_string: Error, string too long! Limit: 255 chars \n");
exit(1);
}
if( col_fg < 0 || col_fg > 255){
printf("tft_string: Error, foregroundcolor out of range! Use 0...255! \n");
exit(1);
}
if(col_bg < 0 || col_bg > 255){
printf("tft_string: Error, backgroundcolor out oft range! Use 0...255!\n");
exit(1);
}
if( px < 0 || px > 319){
printf("tft_string: Error, pos_x out of range! pos_x: 0...319!\n");
exit(1);
}
if ( py < 0 || py > 239){
printf("tft_string: Error, pos_y out of range! pos_y: 0...239!\n");
exit(1);
}
if ( fsf < 0 || fsf > 15){
printf("tft_string: Error, bad fontsize! fs: 0...15!\n");
exit(1);
}
if (transparent < 0 || transparent > 1){
printf("Error! Tansparenz muss 0 oder 1 sein!");
exit(1);
}
if (bold != 0 && bold !=1) {
printf("Error! Bold muss 0 oder 1 sein!");
exit(1);
}
//RAIO_SetFontSizeFactor ( fsf );
if(transparent == 0) {
fsf=fsf | 0x80;
}
else{
fsf=fsf | 0xC0;
}
if( bold == 1 ){
fsf=fsf | 0x20;
}
else {
fsf=fsf & 0xDF;
}
RAIO_SetRegister( FNCR1, fsf);
RAIO_print_text ( px, py, text, col_bg ,col_fg);
return 0;
}

86
src/tft_test.c Normal file
View File

@ -0,0 +1,86 @@
/*##############################################################*/
/* */
/* File : tft_test.c */
/* */
/* Project : TFT for Raspberry Pi Revision 2 */
/* */
/* Date : 2014-08-13 last update: 2014-08-13 */
/* */
/* Author : Hagen Ploog */
/* Kai Gillmann */
/* Timo Pfander */
/* */
/* IDE : Geany 1.22 */
/* Compiler : gcc (Debian 4.6.3-14+rpi1) 4.6.3 */
/* */
/* Copyright (C) 2013 admatec GmbH */
/* */
/* */
/* Description : */
/* */
/* This file contains the main loop. The main loop uses the */
/* functions from examples.h to demonstrate different kind */
/* of opportunities. */
/* */
/* */
/* License: */
/* */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will */
/* be useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, */
/* see <http://www.gnu.org/licenses/>. */
/* */
/* */
/* Revision History: */
/* */
/* Version 1.0 - Initial release */
/* */
/* */
/* */
/*##############################################################*/
#include <bcm2835.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include "tft.h"
#include "ST7789.h"
#include "bmp.h"
#include "examples.h"
int main( int argc, char **argv )
{
char my_filename[] = "../bmp/admatec.bmp";
if (!bcm2835_init())
return 1;
TFT_init_board();
TFT_hard_reset();
STcontroller_init();
TFT_SetBacklightPWMValue( 255 );
// depict a BMP file
// ---------------------------------------------
example_DepictBMP( &my_filename[0] );
bcm2835_close();
return 0;
}