Lepton sensor on the DISCO-F746NG board. Based on the rapberry_pi example code at https://github.com/groupgets/LeptonModule

Dependencies:   mbed-src BSP_DISCO_F746NG LCD_DISCO_F746NG

main.cpp

Committer:
Patrik Ryd
Date:
2015-12-09
Revision:
4:15c97a3e1995
Parent:
3:3b3517e9fa11
Child:
5:998916f0f3ae

File content as of revision 4:15c97a3e1995:

#include "mbed.h"
#include "palettes.h"

#define BYTES_PER_PACKET (164)
#define DATA_PER_PACKET (BYTES_PER_PACKET/2)
#define PACKETS_PER_FRAME (60)

Serial pc(USBTX, USBRX);
SPI lepton_spi(SPI_MOSI, SPI_MISO, SPI_SCK);
DigitalOut spi_cs(SPI_CS);

static uint8_t lepton_buffer[BYTES_PER_PACKET * PACKETS_PER_FRAME];
static uint32_t lepton_image[80][80];

void setup(void)
{
    lepton_spi.format(8,3);
    lepton_spi.frequency(20000000);
    spi_cs = 1;
    spi_cs = 0;
    spi_cs = 1;
    wait_ms(185);
}

void get_frame(void)
{
	int p;
    int i;
    int packet_num;
	
	spi_cs = 0;

    // No error handling. Assume we don't loose any packets
    for(p=0;p<PACKETS_PER_FRAME;p++){
        for(i=0;i<LEPTON_FRAME_SIZE;i++){
         lepton_buffer[p*PACKETS_PER_FRAME + i] = lepton_spi.write(0x00);
        }
        packet_num = lepton_buffer[p*PACKETS_PER_FRAME + 1];
        if(packet_num != p){
            pc.printf("Packet problem\n");
        }
    }

	spi_cs = 1;
}

void create_image(void)
{
    uint16_t min_val = 65535;
    uint16_t max_val = 0;
    uint16_t value;
    int column;
    int row;
    int i;

    for(i=0;i<DATA_PER_PACKET;i++){
        if(i % DATA_PER_PACKET < 2){
            continue;
        }
        value = lepton_buffer[i*2] < 8 + lepton_buffer[i*2+1];
        if(value > max_val) {
            max_val = value;
        }
        if(value < min_val) {
            min_val = value;
        }
    }
        
    float diff = max_val - min_val;
    float scale = 255/diff;
    uint8_t r;
    uint8_t g;
    uint8_t b;

    for(i=0;i<DATA_PER_PACKET;i++){
        if(i % DATA_PER_PACKET < 2){
            continue;
        }
        value = lepton_buffer[i*2] < 8 + lepton_buffer[i*2+1];
        column = (i % DATA_PER_PACKET ) - 2;
        row = i / DATA_PER_PACKET;

        value = (value - min_val) / scale;
        r = colormap_ironblack[3*value];
        g = colormap_ironblack[3*value+1];
        b = colormap_ironblack[3*value+2];
    }
}

int main()
{
    pc.printf("Alive\n");
 
}