modify parallel epd run file

This commit is contained in:
aceisace
2022-04-10 02:27:44 +02:00
parent 414f3d0ccf
commit 1f7ef37da1
104 changed files with 37256 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
// spiram.c
//
// Little library for accessing SPI RAM such as 23K256-I/P
// using bcm2835 library on Raspberry Pi
//
// Author: Mike McCauley
// Copyright (C) 2018 Mike McCauley
// This software is part of the bcm2835 library and is licensed under the same conditions
// $Id: $
#include <bcm2835.h>
#include <string.h> // memcpy
#include "spiram.h"
static uint8_t _mode = SPIRAM_MODE_INVALID;
uint8_t spiram_read_sr()
{
uint8_t command[] = { SPIRAM_OPCODE_READ_SR, 0};
bcm2835_spi_transfern(command, sizeof(command));
return command[1];
}
bool spiram_write_sr(uint8_t value)
{
uint8_t command[] = { SPIRAM_OPCODE_WRITE_SR, value};
bcm2835_spi_transfern(command, sizeof(command));
return true;
}
bool spiram_set_mode(uint8_t mode)
{
if (mode != _mode)
{
spiram_write_sr(mode);
_mode = mode;
}
return true;
}
bool spiram_begin()
{
_mode = SPIRAM_MODE_BYTE;
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default
bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default
return true;
}
bool spiram_end()
{
bcm2835_spi_end();
return true;
}
uint8_t spiram_read_byte(uint16_t address)
{
spiram_set_mode(SPIRAM_MODE_BYTE);
uint8_t command[] = { SPIRAM_OPCODE_READ, (address >> 8) & 0xff, address & 0xff, 0xff };
bcm2835_spi_transfern(command, sizeof(command));
uint8_t ret = command[3];
}
bool spiram_write_byte(uint16_t address, uint8_t value)
{
spiram_set_mode(SPIRAM_MODE_BYTE);
uint8_t command[] = { SPIRAM_OPCODE_WRITE, (address >> 8) & 0xff, address & 0xff, value };
bcm2835_spi_writenb(command, sizeof(command));
return true;
}
bool spiram_read_page(uint16_t address, uint8_t *buf)
{
spiram_set_mode(SPIRAM_MODE_PAGE);
uint8_t command[3 + SPIRAM_PAGE_SIZE] = { SPIRAM_OPCODE_READ, (address >> 8) & 0xff, address & 0xff };
bcm2835_spi_transfern(command, sizeof(command));
memcpy(buf, command + 3, SPIRAM_PAGE_SIZE);
return true;
}
bool spiram_write_page(uint16_t address, uint8_t *buf)
{
spiram_set_mode(SPIRAM_MODE_PAGE);
uint8_t command[3 + SPIRAM_PAGE_SIZE] = { SPIRAM_OPCODE_WRITE, (address >> 8) & 0xff, address & 0xff };
memcpy(command + 3, buf, SPIRAM_PAGE_SIZE);;
bcm2835_spi_writenb(command, sizeof(command));
return true;
}

View File

@@ -0,0 +1,102 @@
// spiram.h
//
// Header for a Little Library for accessing SPI RAM chips such as 23K256-I/P
// using bcm2835 library on Raspberry Pi
//
// Author: Mike McCauley
// Copyright (C) 2018 Mike McCauley
// This software is part of the bcm2835 library and is licensed under the same conditions
// $Id: $
#include <stdbool.h> // bool, true, false
#ifndef SPIRAM_h
#define SPIRAM_h
#define SPIRAM_HOLD_DISABLE 0x1
#define SPIRAM_MODE_BYTE (0x00 | SPIRAM_HOLD_DISABLE)
#define SPIRAM_MODE_PAGE (0x80 | SPIRAM_HOLD_DISABLE)
#define SPIRAM_MODE_STREAM (0x40 | SPIRAM_HOLD_DISABLE)
#define SPIRAM_MODE_INVALID 0xff
#define SPIRAM_OPCODE_READ_SR 0x05
#define SPIRAM_OPCODE_WRITE_SR 0x01
#define SPIRAM_OPCODE_READ 0x03
#define SPIRAM_OPCODE_WRITE 0x02
/* Size of a page in 23K256 */
#define SPIRAM_PAGE_SIZE 32
/*
* This library allows you to read and write data from an external SPI interfaced static ram (SRAM)
* such as 23K256 (256kbit = 32kByte)
* Byte and POage modes are supported.
* Valid addresses are from 0x0000 to 0x7fff
* Tested on RPI 3 Model B, Raspbian Jessie
*/
/*
* Initialise the spiram library, enables SPI with default divider of
* BCM2835_SPI_CLOCK_DIVIDER_65536 = 6.1035156kHz on RPI3.
* You can change the SPI speed after calling this by calling bcm2835_spi_setClockDivider()
* Returns true on success, false otherwise
*/
bool spiram_begin();
/*
* Stops using the RPI SPI functions and returns the GPIO pins to their default behaviour.
* Call this when you have finished using SPI forever, or at the end of your program
* Returns true on success, false otherwise
*/
bool spiram_end();
/*
* Read and returns the current value of the SRAM status register
*/
uint8_t spiram_read_sr();
/*
* Write a new value to the SRAM status register,
* usually one of SPIRAM_MODE_*
* You should never need to call this directly. Used internally.
* Returns true on success, false otherwise
*/
bool spiram_write_sr(uint8_t value);
/*
* Set the operating mode of the SRAM.
* Mode is one of SPIRAM_MODE_*. THis is done automatically
* by the spiram_write_* and spiram_read_* functions, so you would not normally
* need to call this directly.
* Returns true on success, false otherwise
*/
bool spiram_set_mode(uint8_t mode);
/*
* Reads a single byte from the given address and returns it.
*/
uint8_t spiram_read_byte(uint16_t address);
/*
* Writes a single byte to the given address.
* Returns true on success, false otherwise
*/
bool spiram_write_byte(uint16_t address, uint8_t value);
/*
* Reads a whole page of data (32 bytes) from the page starting at the given address.
* The read data is placed in buf. Be sure that there is enough rom there for it.
* Caution: if the starting address is not on a page boundary,
* it will wrap back to the beginning of the page.
* Returns true on success, false otherwise
*/
bool spiram_read_page(uint16_t address, uint8_t *buf);
/*
* Writes a whole page of data (32 bytes) to the page starting at the given address.
* Caution: if the starting address is not on a page boundary,
* it will wrap back to the beginning of the page.
* Returns true on success, false otherwise
*/
bool spiram_write_page(uint16_t address, uint8_t *buf);
#endif

View File

@@ -0,0 +1,99 @@
// spiram_test.c
//
// Example program for bcm2835
// Shows how to interface with SPI RAM such as 23K256-I/P
// using the spiram little library
//
// Tested on RPI 3 Model B, Raspbian Jessie
// Tested at full speed over many hours with no errors.
//
// Connect RPi 3 B to 23K256-I/P like this:
// RPi pin Function 23K256-I/P pin (name)
// J1-6 GND 4 (VSS)
// J1-1 3.3V 8 (VCC)
// and 7 (/HOLD)
// J1-19 SPI0_MOSI 5 (SI)
// J1-21 SPI0_MISO 2 (SO)
// J1-23 SPI0_SCLK 6 (SCK)
// J1-24 SPI0_CE0_N 1 (/CS)
//
// After installing bcm2835, you can build this
// with something like:
// gcc -o spiram_test spiram.c spiram_test.c -l bcm2835
// sudo ./spiram_test
//
// Or you can test it before installing with:
// gcc -o spiram_test -I ../../src ../../src/bcm2835.c spiram.c spiram_test.c
// sudo ./spiram_test
//
// Author: Mike McCauley
// Copyright (C) 2018 Mike McCauley
// $Id: $
#include <bcm2835.h>
#include <stdio.h>
#include <string.h> // memcmp
#include "spiram.h"
int main(int argc, char **argv)
{
if (!bcm2835_init())
{
printf("bcm2835_init failed. Are you running as root??\n");
return 1;
}
if (!bcm2835_spi_begin())
{
printf("bcm2835_spi_begin failed. Are you running as root??\n");
return 1;
}
if (!spiram_begin())
{
printf("spiram_begin failed.\n");
return 1;
}
/* You can speed things up by selecting a faster SPI speed
// after spiram_begin, which defaults to BCM2835_SPI_CLOCK_DIVIDER_65536 = 6.1035156kHz on RPI3
*/
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64); // 6.25MHz on RPI3
uint8_t value = 0;
uint16_t address = 0x0000;
while (1)
{
uint8_t ret;
/* ret = spiram_read_sr();*/
spiram_write_byte(address, value);
ret = spiram_read_byte(address);
if (ret != value)
printf("ERROR: spiram_read_byte address %04x got %02x, expected %02x\n", address, ret, value);
#if 0
printf("spiram_read_byte at address %04x got %02x\n", address, ret);
#endif
uint8_t write_page_buf[SPIRAM_PAGE_SIZE] = { 0, value, value, value };
uint8_t read_page_buf[SPIRAM_PAGE_SIZE];
spiram_write_page(address, write_page_buf);
spiram_read_page(address, read_page_buf);
if (memcmp(write_page_buf, read_page_buf, SPIRAM_PAGE_SIZE) != 0)
printf("ERROR: spiram_read_page at address %04x\n", address);
#if 0
printf("spiram_read_page address %04x got ", address);
int i;
for (i = 0; i < SPIRAM_PAGE_SIZE; i++)
printf("%02x ", read_page_buf[i]);
printf("\n");
#endif
/* sleep(1); */
value++;
address++;
}
spiram_end();
bcm2835_close();
return 0;
}