Commit 1755d128 authored by jiri hubacek's avatar jiri hubacek
Browse files

Initial commit of template for semestral work

Please see https://cw.fel.cvut.cz/wiki/courses/b35apo/tutorials/10/start
parents
CC = arm-linux-gnueabihf-gcc
CXX = arm-linux-gnueabihf-g++
CPPFLAGS = -I .
CFLAGS =-g -std=gnu99 -O1 -Wall
CXXFLAGS = -g -std=gnu++11 -O1 -Wall
LDFLAGS = -lrt -lpthread
SOURCES = change_me.c mzapo_phys.c mzapo_parlcd.c
#SOURCES += font_prop14x16.c font_rom8x16.c
TARGET_EXE = change_me
TARGET_IP ?= 192.168.1.37
TARGET_DIR ?= /tmp/$(shell whoami)
TARGET_USER ?= root
OBJECTS += $(filter %.o,$(SOURCES:%.c=%.o))
OBJECTS += $(filter %.o,$(SOURCES:%.cpp=%.o))
#$(warning OBJECTS=$(OBJECTS))
ifeq ($(filter %.cpp,$(SOURCES)),)
LINKER = $(CC)
LDFLAGS += $(CFLAGS) $(CPPFLAGS)
else
LINKER = $(CXX)
LDFLAGS += $(CXXFLAGS) $(CPPFLAGS)
endif
%.o:%.c
$(CC) $(CFLAGS) -c $<
%.o:%.cpp
$(CXX) $(CXXFLAGS) -c $<
all: $(TARGET_EXE)
$(TARGET_EXE): $(OBJECTS)
$(LINKER) $(LDFLAGS) -L. $^ -o $@
.PHONY : dep all run
dep: depend
depend: $(SOURCES) *.h
echo '# autogenerated dependencies' > depend
ifneq ($(filter %.c,$(SOURCES)),)
$(CC) $(CFLAGS) $(CPPFLAGS) -w -E -M $(filter %.c,$(SOURCES)) \
>> depend
endif
ifneq ($(filter %.cpp,$(SOURCES)),)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -w -E -M $(filter %.cpp,$(SOURCES)) \
>> depend
endif
clean:
rm -f *.o *.a $(OBJECTS) $(TARGET_EXE) depend
run: $(TARGET_EXE)
ssh $(TARGET_USER)@$(TARGET_IP) mkdir -p $(TARGET_DIR)
scp $(TARGET_EXE) $(TARGET_USER)@$(TARGET_IP):$(TARGET_DIR)/$(TARGET_EXE)
ssh -t $(TARGET_USER)@$(TARGET_IP) $(TARGET_DIR)/$(TARGET_EXE)
-include depend
/*******************************************************************
Simple program to check LCD functionality on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
mzapo_lcdtest.c - main and only file
(C) Copyright 2004 - 2017 by Pavel Pisa
e-mail: pisa@cmp.felk.cvut.cz
homepage: http://cmp.felk.cvut.cz/~pisa
work: http://www.pikron.com/
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
#define _POSIX_C_SOURCE 200112L
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include "mzapo_parlcd.h"
#include "mzapo_phys.h"
#include "mzapo_regs.h"
int main(int argc, char *argv[])
{
printf("Hello world\n");
sleep(4);
printf("Goodbye world\n");
return 0;
}
This diff is collapsed.
This diff is collapsed.
/*******************************************************************
font_types.h - simple bitmap fonts type definition
Simplified font type descriptor based on
Microwindows/Nano-X library by Greg Haerr
https://github.com/ghaerr/microwindows
Copyright (c) 1999, 2000, 2001, 2002, 2003, 2005, 2010, 2011 Greg Haerr <greg@censoft.com>
Portions Copyright (c) 2002 by Koninklijke Philips Electronics N.V.
Simplification by Pavel Pisa for Czech Technical University
Computer Architectures course
*******************************************************************/
#ifndef MZAPO_PHYS_H
#define MZAPO_PHYS_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef uint16_t font_bits_t;
/* builtin C-based proportional/fixed font structure*/
typedef struct {
char * name; /* font name*/
int maxwidth; /* max width in pixels*/
unsigned int height; /* height in pixels*/
int ascent; /* ascent (baseline) height*/
int firstchar; /* first character in bitmap*/
int size; /* font size in characters*/
const font_bits_t *bits; /* 16-bit right-padded bitmap data*/
const uint32_t *offset; /* offsets into bitmap data*/
const unsigned char *width; /* character widths or 0 if fixed*/
int defaultchar;/* default char (not glyph index)*/
int32_t bits_size; /* # words of MWIMAGEBITS bits*/
} font_descriptor_t;
extern font_descriptor_t font_winFreeSystem14x16;
extern font_descriptor_t font_rom8x16;
#ifdef __cplusplus
} /* extern "C"*/
#endif
#endif /*MZAPO_PHYS_H*/
/*******************************************************************
Simple program to check LCD functionality on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
mzapo_parlcd.c - parallel connected LCD low level access
(C) Copyright 2017 by Pavel Pisa
e-mail: pisa@cmp.felk.cvut.cz
homepage: http://cmp.felk.cvut.cz/~pisa
company: http://www.pikron.com/
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
#define _POSIX_C_SOURCE 200112L
#include <stdint.h>
#include <time.h>
#include "mzapo_parlcd.h"
#include "mzapo_regs.h"
void parlcd_write_cmd(unsigned char *parlcd_mem_base, uint16_t cmd)
{
*(volatile uint16_t*)(parlcd_mem_base + PARLCD_REG_CMD_o) = cmd;
}
void parlcd_write_data(unsigned char *parlcd_mem_base, uint16_t data)
{
*(volatile uint16_t*)(parlcd_mem_base + PARLCD_REG_DATA_o) = data;
}
void parlcd_write_data2x(unsigned char *parlcd_mem_base, uint32_t data)
{
*(volatile uint32_t*)(parlcd_mem_base + PARLCD_REG_DATA_o) = data;
}
void parlcd_delay(int msec)
{
struct timespec wait_delay = {.tv_sec = msec / 1000,
.tv_nsec = (msec % 1000) * 1000 * 1000};
clock_nanosleep(CLOCK_MONOTONIC, 0, &wait_delay, NULL);
}
void parlcd_hx8357_init(unsigned char *parlcd_mem_base)
{
// toggle RST low to reset
/*
digitalWrite(_rst, HIGH);
parlcd_delay(50);
digitalWrite(_rst, LOW);
parlcd_delay(10);
digitalWrite(_rst, HIGH);
parlcd_delay(10);
*/
parlcd_write_cmd(parlcd_mem_base, 0x1);
parlcd_delay(30);
#ifdef HX8357_B
// Configure HX8357-B display
parlcd_write_cmd(parlcd_mem_base, 0x11);
parlcd_delay(20);
parlcd_write_cmd(parlcd_mem_base, 0xD0);
parlcd_write_data(parlcd_mem_base, 0x07);
parlcd_write_data(parlcd_mem_base, 0x42);
parlcd_write_data(parlcd_mem_base, 0x18);
parlcd_write_cmd(parlcd_mem_base, 0xD1);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x07);
parlcd_write_data(parlcd_mem_base, 0x10);
parlcd_write_cmd(parlcd_mem_base, 0xD2);
parlcd_write_data(parlcd_mem_base, 0x01);
parlcd_write_data(parlcd_mem_base, 0x02);
parlcd_write_cmd(parlcd_mem_base, 0xC0);
parlcd_write_data(parlcd_mem_base, 0x10);
parlcd_write_data(parlcd_mem_base, 0x3B);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x02);
parlcd_write_data(parlcd_mem_base, 0x11);
parlcd_write_cmd(parlcd_mem_base, 0xC5);
parlcd_write_data(parlcd_mem_base, 0x08);
parlcd_write_cmd(parlcd_mem_base, 0xC8);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x32);
parlcd_write_data(parlcd_mem_base, 0x36);
parlcd_write_data(parlcd_mem_base, 0x45);
parlcd_write_data(parlcd_mem_base, 0x06);
parlcd_write_data(parlcd_mem_base, 0x16);
parlcd_write_data(parlcd_mem_base, 0x37);
parlcd_write_data(parlcd_mem_base, 0x75);
parlcd_write_data(parlcd_mem_base, 0x77);
parlcd_write_data(parlcd_mem_base, 0x54);
parlcd_write_data(parlcd_mem_base, 0x0C);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_cmd(parlcd_mem_base, 0x36);
parlcd_write_data(parlcd_mem_base, 0x0a);
parlcd_write_cmd(parlcd_mem_base, 0x3A);
parlcd_write_data(parlcd_mem_base, 0x55);
parlcd_write_cmd(parlcd_mem_base, 0x2A);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x01);
parlcd_write_data(parlcd_mem_base, 0x3F);
parlcd_write_cmd(parlcd_mem_base, 0x2B);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x01);
parlcd_write_data(parlcd_mem_base, 0xDF);
parlcd_delay(120);
parlcd_write_cmd(parlcd_mem_base, 0x29);
parlcd_delay(25);
#else
// HX8357-C display initialisation
parlcd_write_cmd(parlcd_mem_base, 0xB9); // Enable extension command
parlcd_write_data(parlcd_mem_base, 0xFF);
parlcd_write_data(parlcd_mem_base, 0x83);
parlcd_write_data(parlcd_mem_base, 0x57);
parlcd_delay(50);
parlcd_write_cmd(parlcd_mem_base, 0xB6); //Set VCOM voltage
//parlcd_write_data(parlcd_mem_base, 0x2C); //0x52 for HSD 3.0"
parlcd_write_data(parlcd_mem_base, 0x52); //0x52 for HSD 3.0"
parlcd_write_cmd(parlcd_mem_base, 0x11); // Sleep off
parlcd_delay(200);
parlcd_write_cmd(parlcd_mem_base, 0x35); // Tearing effect on
parlcd_write_data(parlcd_mem_base, 0x00); // Added parameter
parlcd_write_cmd(parlcd_mem_base, 0x3A); // Interface pixel format
parlcd_write_data(parlcd_mem_base, 0x55); // 16 bits per pixel
//parlcd_write_cmd(parlcd_mem_base, 0xCC); // Set panel characteristic
//parlcd_write_data(parlcd_mem_base, 0x09); // S960>S1, G1>G480, R-G-B, normally black
//parlcd_write_cmd(parlcd_mem_base, 0xB3); // RGB interface
//parlcd_write_data(parlcd_mem_base, 0x43);
//parlcd_write_data(parlcd_mem_base, 0x00);
//parlcd_write_data(parlcd_mem_base, 0x06);
//parlcd_write_data(parlcd_mem_base, 0x06);
parlcd_write_cmd(parlcd_mem_base, 0xB1); // Power control
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x15);
parlcd_write_data(parlcd_mem_base, 0x0D);
parlcd_write_data(parlcd_mem_base, 0x0D);
parlcd_write_data(parlcd_mem_base, 0x83);
parlcd_write_data(parlcd_mem_base, 0x48);
parlcd_write_cmd(parlcd_mem_base, 0xC0); // Does this do anything?
parlcd_write_data(parlcd_mem_base, 0x24);
parlcd_write_data(parlcd_mem_base, 0x24);
parlcd_write_data(parlcd_mem_base, 0x01);
parlcd_write_data(parlcd_mem_base, 0x3C);
parlcd_write_data(parlcd_mem_base, 0xC8);
parlcd_write_data(parlcd_mem_base, 0x08);
parlcd_write_cmd(parlcd_mem_base, 0xB4); // Display cycle
parlcd_write_data(parlcd_mem_base, 0x02);
parlcd_write_data(parlcd_mem_base, 0x40);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x2A);
parlcd_write_data(parlcd_mem_base, 0x2A);
parlcd_write_data(parlcd_mem_base, 0x0D);
parlcd_write_data(parlcd_mem_base, 0x4F);
parlcd_write_cmd(parlcd_mem_base, 0xE0); // Gamma curve
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x15);
parlcd_write_data(parlcd_mem_base, 0x1D);
parlcd_write_data(parlcd_mem_base, 0x2A);
parlcd_write_data(parlcd_mem_base, 0x31);
parlcd_write_data(parlcd_mem_base, 0x42);
parlcd_write_data(parlcd_mem_base, 0x4C);
parlcd_write_data(parlcd_mem_base, 0x53);
parlcd_write_data(parlcd_mem_base, 0x45);
parlcd_write_data(parlcd_mem_base, 0x40);
parlcd_write_data(parlcd_mem_base, 0x3B);
parlcd_write_data(parlcd_mem_base, 0x32);
parlcd_write_data(parlcd_mem_base, 0x2E);
parlcd_write_data(parlcd_mem_base, 0x28);
parlcd_write_data(parlcd_mem_base, 0x24);
parlcd_write_data(parlcd_mem_base, 0x03);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x15);
parlcd_write_data(parlcd_mem_base, 0x1D);
parlcd_write_data(parlcd_mem_base, 0x2A);
parlcd_write_data(parlcd_mem_base, 0x31);
parlcd_write_data(parlcd_mem_base, 0x42);
parlcd_write_data(parlcd_mem_base, 0x4C);
parlcd_write_data(parlcd_mem_base, 0x53);
parlcd_write_data(parlcd_mem_base, 0x45);
parlcd_write_data(parlcd_mem_base, 0x40);
parlcd_write_data(parlcd_mem_base, 0x3B);
parlcd_write_data(parlcd_mem_base, 0x32);
parlcd_write_data(parlcd_mem_base, 0x2E);
parlcd_write_data(parlcd_mem_base, 0x28);
parlcd_write_data(parlcd_mem_base, 0x24);
parlcd_write_data(parlcd_mem_base, 0x03);
parlcd_write_data(parlcd_mem_base, 0x00);
parlcd_write_data(parlcd_mem_base, 0x01);
parlcd_write_cmd(parlcd_mem_base, 0x36); // MADCTL Memory access control
//parlcd_write_data(parlcd_mem_base, 0x48);
parlcd_write_data(parlcd_mem_base, 0xE8);
parlcd_delay(20);
parlcd_write_cmd(parlcd_mem_base, 0x21); //Display inversion on
parlcd_delay(20);
parlcd_write_cmd(parlcd_mem_base, 0x29); // Display on
parlcd_delay(120);
#endif
}
/*******************************************************************
Simple program to check LCD functionality on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
mzapo_parlcd.h - parallel connected LCD low level access
(C) Copyright 2017 by Pavel Pisa
e-mail: pisa@cmp.felk.cvut.cz
homepage: http://cmp.felk.cvut.cz/~pisa
company: http://www.pikron.com/
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
#ifndef MZAPO_PARLCD_H
#define MZAPO_PARLCD_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void parlcd_write_cmd(unsigned char *parlcd_mem_base, uint16_t cmd);
void parlcd_write_data(unsigned char *parlcd_mem_base, uint16_t data);
void parlcd_write_data2x(unsigned char *parlcd_mem_base, uint32_t data);
void parlcd_delay(int msec);
void parlcd_hx8357_init(unsigned char *parlcd_mem_base);
#ifdef __cplusplus
} /* extern "C"*/
#endif
#endif /*MZAPO_PARLCD_H*/
/*******************************************************************
Simple program to check LCD functionality on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
mzapo_phys.h - mapping of the physical address to process
(C) Copyright 2017 by Pavel Pisa
e-mail: pisa@cmp.felk.cvut.cz
homepage: http://cmp.felk.cvut.cz/~pisa
company: http://www.pikron.com/
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
#define _POSIX_C_SOURCE 200112L
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "mzapo_phys.h"
const char *map_phys_memdev="/dev/mem";
void *map_phys_address(off_t region_base, size_t region_size, int opt_cached)
{
unsigned long mem_window_size;
unsigned long pagesize;
unsigned char *mm;
unsigned char *mem;
int fd;
fd = open(map_phys_memdev, O_RDWR | (!opt_cached? O_SYNC: 0));
if (fd < 0) {
fprintf(stderr, "cannot open %s\n", map_phys_memdev);
return NULL;
}
pagesize=sysconf(_SC_PAGESIZE);
mem_window_size = ((region_base & (pagesize-1)) + region_size + pagesize-1) & ~(pagesize-1);
mm = (unsigned char *)mmap(NULL, mem_window_size, PROT_WRITE|PROT_READ,
MAP_SHARED, fd, region_base & ~(pagesize-1));
mem = mm + (region_base & (pagesize-1));
if (mm == MAP_FAILED) {
fprintf(stderr,"mmap error\n");
return NULL;
}
return (void *)mem;
}
/*******************************************************************
Simple program to check LCD functionality on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
mzapo_phys.h - mapping of the physical address to process
(C) Copyright 2017 by Pavel Pisa
e-mail: pisa@cmp.felk.cvut.cz
homepage: http://cmp.felk.cvut.cz/~pisa
company: http://www.pikron.com/
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
#ifndef MZAPO_PHYS_H
#define MZAPO_PHYS_H
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
void *map_phys_address(off_t region_base, size_t region_size, int opt_cached);
#ifdef __cplusplus
} /* extern "C"*/
#endif
#endif /*MZAPO_PHYS_H*/
/*******************************************************************
Simple program to check LCD functionality on MicroZed
based MZ_APO board designed by Petr Porazil at PiKRON
mzapo_regs.h - definition of the MZ_APO design registers
(C) Copyright 2017 by Pavel Pisa
e-mail: pisa@cmp.felk.cvut.cz
homepage: http://cmp.felk.cvut.cz/~pisa
company: http://www.pikron.com/
license: any combination of GPL, LGPL, MPL or BSD licenses
*******************************************************************/
#ifndef MZAPO_REGS_H
#define MZAPO_REGS_H
/*
Complete description of the educational MZ_APO design registers
can be found at
https://cw.fel.cvut.cz/wiki/courses/b35apo/documentation/mz_apo/start
The peripherals VHDL sources can be found in the repository
http://rtime.felk.cvut.cz/gitweb/fpga/zynq/canbench-sw.git/tree/refs/heads/microzed_apo:/system/ip
*/
/* SPI connected knobs and LEDs registers and keyboard */
#define SPILED_REG_BASE_PHYS 0x43c40000
#define SPILED_REG_SIZE 0x00004000
#define SPILED_REG_LED_LINE_o 0x004
#define SPILED_REG_LED_RGB1_o 0x010
#define SPILED_REG_LED_RGB2_o 0x014
#define SPILED_REG_LED_KBDWR_DIRECT_o 0x018
#define SPILED_REG_KBDRD_KNOBS_DIRECT_o 0x020
#define SPILED_REG_KNOBS_8BIT_o 0x024
/* Parallel LCD registers */
#define PARLCD_REG_BASE_PHYS 0x43c00000
#define PARLCD_REG_SIZE 0x00004000
#define PARLCD_REG_CMD_o 0x0008
#define PARLCD_REG_DATA_o 0x000C
/* RC model servos and optional PS2 peripheral */
#define SERVOPS2_REG_BASE_PHYS 0x43c50000
#define SERVOPS2_REG_SIZE 0x4000
#define SERVOPS2_REG_CR_o 0x0000
#define SERVOPS2_REG_PWMPER_o 0x000C
#define SERVOPS2_REG_PWM1_o 0x0010
#define SERVOPS2_REG_PWM2_o 0x0014
#define SERVOPS2_REG_PWM3_o 0x0018
#define SERVOPS2_REG_PWM4_o 0x001C
/* Simple audio PWM output */
#define AUDIOPWM_REG_BASE_PHYS 0x43c60008
#define AUDIOPWM_REG_SIZE 0x4000
#define AUDIOPWM_REG_CR_o 0x0000
#define AUDIOPWM_REG_PWMPER_o 0x0008
#define AUDIOPWM_REG_PWM_o 0x000C
#endif /*MZAPO_REGS_H*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment