Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <avr/io.h>
- typedef unsigned char u8;
- typedef unsigned short u16;
- #include "SPI.h"
- #include "Adafruit_GFX.h"
- #include "Adafruit_ILI9340.h"
- #if defined(__SAM3X8E__)
- #undef __FlashStringHelper::F(string_literal)
- #define F(string_literal) string_literal
- #endif
- int numsteps = 300; //4800
- //RAM
- //SRAM opcodes
- #define RDSR 5
- #define WRSR 1
- #define READ 3
- #define WRITE 2
- uint8_t SpiRAMRead8(uint16_t address) {
- uint8_t read_byte;
- PORTB &= ~(1<<PORTB2); //set SPI_SS low
- SPI.transfer(READ);
- SPI.transfer((char)(address >> 8));
- SPI.transfer((char)address);
- read_byte = SPI.transfer(0xFF);
- PORTB |= (1<<PORTB2); //set SPI_SS high
- return read_byte;
- }
- void SpiRAMWrite8(uint16_t address, uint8_t data_byte) {
- PORTB &= ~(1<<PORTB2); //set SPI_SS low
- SPI.transfer(WRITE);
- SPI.transfer((char)(address >> 8));
- SPI.transfer((char)address);
- SPI.transfer(data_byte);
- PORTB |= (1<<PORTB2); //set SPI_SS high
- }
- void writetestset(){
- int8_t num = -128;
- for(int i = 0; i < numsteps;i++){
- // SpiRAMWrite8(i,(uint8_t)i);
- SpiRAMWrite8(i,(int8_t)num);
- if(num+1 <128)
- num++;
- else
- num = -127;
- }
- }
- void readtestset(){
- uint8_t data;
- for(int i = 0; i < numsteps;i++){
- data = SpiRAMRead8(i);
- Serial.print("DATA : ");
- Serial.print((uint8_t)i);
- Serial.print(" ");
- Serial.print((int8_t)data);
- Serial.println("");
- }
- }
- u8 framebuf[164];
- #define CSBIT 1<<7; // chip select bit
- static void recvspiblock()
- {
- u16 len = 164;
- u8 *buf = framebuf;
- PORTB &= ~CSBIT;
- if( SPSR & 1 ) {
- u8 t;
- SPDR = 0xff;
- while(--len) {
- asm( " .rept 9\n nop\n .endr" );
- t = SPDR;
- SPDR = 0xff;
- // there is actuallya race condition if an interrupt occurs here.
- *buf++ = t; // double buffered
- }
- while (!(SPSR & 0x80));
- SPSR &= 0x7f;
- *buf = SPDR;
- }
- while (len--) {
- SPDR = 0xff;
- while (!(SPSR & 0x80));
- SPSR &= 0x7f;
- *buf++ = SPDR;
- SpiRAMWrite8(164-len,(int8_t)*buf);
- }
- PORTB |= CSBIT;
- asm( " .rept 9\n nop\n .endr" );
- }
- static void spihwinit()
- {
- DDRB |= CSBIT; // set port for SPI
- PORTB |= CSBIT;
- SPCR = 0x53; // Slowest possible for init
- SPSR = 1;
- SPI.setDataMode(SPI_MODE3);
- SPI.setClockDivider(0);
- SPI.begin();
- delay(3000);
- Serial.println(SPCR,HEX);
- Serial.println(SPSR,HEX);
- SPSR = 1;
- }
- char img[17] = " .:;\"-!|+=&*$%@#";
- char image[31][41];
- void setup()
- {
- Serial.begin(115200);
- spihwinit();
- memset(image, '^', sizeof(image));
- }
- void print_lepton_frame(void)
- {
- char *c;
- int i,j;
- image[30][0] = 0;
- recvspiblock();
- return;
- do {
- do {
- recvspiblock();
- } while( framebuf[0] & 0xf == 0x0f );
- j = framebuf[1];
- if( j > 59 )
- continue;
- if( !(j & 1) )
- continue;
- j >>= 1;
- c = image[j];
- for( i = 5; i < 164; i += 4 ) {
- j = framebuf[i+1]<<8;
- j += framebuf[i];
- j -= 7950;
- if( j < 0 ) j = 0;
- j >>= 5;
- if( j > 15 ) j = 15;
- *c++ = img[j];
- }
- *c = '\n';
- } while( framebuf[1] != 59 );
- // c = image[0];
- //Serial.println(c);
- for(u8 i = 0; i < 164;i++){
- //Serial.print(i);
- //Serial.print(" ");
- // Serial.println((u8)framebuf[i]);
- SpiRAMWrite8(i,(int8_t)framebuf[i]);
- }
- }
- bool runonce = 0;
- void loop()
- {
- //Serial.println("LEPTON FRAME");
- if(runonce == 0){
- print_lepton_frame();
- runonce = 1;
- for(u8 i = 0; i < 164;i++){
- int8_t data = SpiRAMRead8(i);
- Serial.print("DATA: ");
- Serial.print(i);
- Serial.print(" ");
- Serial.print(data);
- Serial.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement