Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: azonenberg/starshipraider
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 87d75b807be3
Choose a base ref
...
head repository: azonenberg/starshipraider
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8891f0495d34
Choose a head ref
  • 1 commit
  • 6 files changed
  • 1 contributor

Commits on Jul 5, 2020

  1. Copy the full SHA
    8891f04 View commit details
Showing with 293 additions and 28 deletions.
  1. +97 −0 firmware/MEAD/AMG240160P.cpp
  2. +58 −0 firmware/MEAD/AMG240160P.h
  3. +52 −0 firmware/MEAD/AT30TS74.cpp
  4. +50 −0 firmware/MEAD/AT30TS74.h
  5. +35 −27 firmware/MEAD/main.cpp
  6. +1 −1 firmware/stm32-cpp
97 changes: 97 additions & 0 deletions firmware/MEAD/AMG240160P.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/***********************************************************************************************************************
* *
* STARSHIPRAIDER v0.1 *
* *
* Copyright (c) 2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#include <stm32fxxx.h>
#include "AMG240160P.h"

AMG240160P::AMG240160P(SPI* spi, GPIOPin* csn, GPIOPin* rstn, GPIOPin* ctlData, Timer* usTimer)
: m_spi(spi)
, m_csn(csn)
, m_rstn(rstn)
, m_ctlData(ctlData)
, m_usTimer(usTimer)
{
//Initialize pins
csn->Set(1);
rstn->Set(1);
ctlData->Set(0);

//Reset LCD. 10ms low, 10ms high before sending writes
rstn->Set(0);
usTimer->Sleep(10000, true);
rstn->Set(1);
usTimer->Sleep(10000, true);
}

void AMG240160P::Initialize()
{
SendCommand(0xe2); //Soft reset
SendCommand(0x2b); //Power control
SendCommand(0x25); //Temp compensation
SendCommand(0xc2); //LCD mapping control
SendCommand(0x8b); //RAM control
SendCommand(0xd0); //Color pattern
SendCommand(0xd6); //Color mode
SendCommand(0xdd); //COM scan function
SendCommand(0xa1); //Line rate
SendCommand(0xeb); //Bias ratio 1/12

SendCommand(0x81); //VBIAS pot
SendCommand(35);

SendCommand(0xf1); //COM End
SendCommand(159);

SendCommand(0xC8); //N-line inversion
SendCommand(0);

SendCommand(0x84); //No partial display
SendCommand(0xa6); //No inverse display
SendCommand(0xad); //Enable display
}

void AMG240160P::SendCommand(uint8_t cmd)
{
m_ctlData->Set(0);

m_csn->Set(0);
m_spi->BlockingWrite(cmd);
m_spi->WaitForWrites();
m_csn->Set(1);
}

void AMG240160P::SendData(uint8_t data)
{
m_ctlData->Set(1);

m_csn->Set(0);
m_spi->BlockingWrite(cmd);
m_spi->WaitForWrites();
m_csn->Set(1);
}
58 changes: 58 additions & 0 deletions firmware/MEAD/AMG240160P.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/***********************************************************************************************************************
* *
* STARSHIPRAIDER v0.1 *
* *
* Copyright (c) 2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#ifndef AMG240160P_h
#define AMG240160P_h

#include <peripheral/SPI.h>
#include <peripheral/GPIO.h>
#include <peripheral/Timer.h>

/**
@brief Driver for an AMG240160P-W6WFDW LCD
*/
class AMG240160P
{
public:
AMG240160P(SPI* spi, GPIOPin* csn, GPIOPin* rstn, GPIOPin* ctlData, Timer* usTimer);
void Initialize();

void SendCommand(uint8_t cmd);
void SendData(uint8_t data);

protected:

SPI* m_spi;
GPIOPin* m_csn;
GPIOPin* m_rstn;
GPIOPin* m_ctlData;
Timer* m_usTimer;
};

#endif
52 changes: 52 additions & 0 deletions firmware/MEAD/AT30TS74.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/***********************************************************************************************************************
* *
* STARSHIPRAIDER v0.1 *
* *
* Copyright (c) 2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#include <stm32fxxx.h>
#include "AT30TS74.h"

AT30TS74::AT30TS74(I2C* i2c, uint8_t addr)
: m_i2c(i2c)
, m_addr(addr)
{
//12 bit resolution, active high alert output
uint8_t temp_config[3] = {0x01, 0x64, 0x00};
m_i2c->BlockingWrite(m_addr, temp_config, sizeof(temp_config));

//Select temperature register now so we can just do a read in the future to get the temp
//without any address overhead
m_i2c->BlockingWrite8(m_addr, 0x00);
}

void AT30TS74::GetTemperature(uint8_t& temp, uint8_t& temp_frac)
{
uint8_t reply[2];
m_i2c->BlockingRead(m_addr, reply, 2);
temp = reply[0];
temp_frac = reply[1];
}
50 changes: 50 additions & 0 deletions firmware/MEAD/AT30TS74.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/***********************************************************************************************************************
* *
* STARSHIPRAIDER v0.1 *
* *
* Copyright (c) 2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#ifndef AT30TS74_h
#define AT30TS74_h

#include <peripheral/I2C.h>

/**
@brief Driver for an AT30TS74 temperature sensor
*/
class AT30TS74
{
public:
AT30TS74(I2C* i2c, uint8_t addr);

void GetTemperature(uint8_t& temp, uint8_t& temp_frac);

protected:
I2C* m_i2c;
uint8_t m_addr;
};

#endif
62 changes: 35 additions & 27 deletions firmware/MEAD/main.cpp
Original file line number Diff line number Diff line change
@@ -31,11 +31,10 @@
#include <peripheral/UART.h>
#include <peripheral/GPIO.h>
#include <peripheral/SPI.h>
/*
#include "SCPIParser.h"
#include "LTC2664.h"
#include "ADL5205.h"
*/
#include <peripheral/I2C.h>
#include <peripheral/Timer.h>
#include "AT30TS74.h"
#include "AMG240160P.h"

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Entry point
@@ -45,7 +44,6 @@ UART* g_uart;

//When possible, long-lived stuff here should be declared static.
//This puts them in .bss instead of stack, and enables better accounting of memory usage
//on the (heavily limited) STM32F031 on the characterization board.
int main()
{
//Initialize the PLL
@@ -63,39 +61,49 @@ int main()
volatile uint32_t* NVIC_ISER0 = (volatile uint32_t*)(0xe000e100);
*NVIC_ISER0 = 0x8000000;


//Set up SPI bus at 12 MHz (APB/4)
static GPIOPin spi_sck( &GPIOB, 3, GPIOPin::MODE_PERIPHERAL, 0);
static GPIOPin spi_sck( &GPIOB, 3, GPIOPin::MODE_PERIPHERAL, 0);
static GPIOPin spi_miso(&GPIOB, 4, GPIOPin::MODE_PERIPHERAL, 0);
static GPIOPin spi_mosi(&GPIOB, 5, GPIOPin::MODE_PERIPHERAL, 0);
static SPI spi(&SPI1, true, 4);

//Set up timer
//Set up timer with 1us ticks
static Timer timer(&TIM1, Timer::FEATURE_ADVANCED, 48);

//Set up DAC
static GPIOPin dac_cs_n(&GPIOA, 15, GPIOPin::MODE_OUTPUT);
dac_cs_n.Set(1);

//Set up I2C.
//Prescale divide by 8 (6 MHz, 166.6 ns/tick)
//Divide I2C clock by 16 after that to get 375 kHz
static GPIOPin i2c_sda( &GPIOB, 7, GPIOPin::MODE_PERIPHERAL, 1);
static GPIOPin i2c_scl( &GPIOB, 6, GPIOPin::MODE_PERIPHERAL, 1);
static I2C i2c(&I2C1, 8, 8);

//Set up temperature sensors
AT30TS74 temp_right(&i2c, 0x90);
AT30TS74 temp_left(&i2c, 0x92);

//Set up LCD
/*
g_uart->Printf("Turning on LCD\n");
static GPIOPin lcd_cs(&GPIOA, 0, GPIOPin::MODE_OUTPUT);
static GPIOPin lcd_rst(&GPIOA, 2, GPIOPin::MODE_OUTPUT);
static GPIOPin lcd_cs_n(&GPIOA, 0, GPIOPin::MODE_OUTPUT);
static GPIOPin lcd_rst_n(&GPIOA, 2, GPIOPin::MODE_OUTPUT);
static GPIOPin lcd_ctl_data(&GPIOA, 3, GPIOPin::MODE_OUTPUT);
lcd_cs.Set(1);
*/
AMG240160P lcd(&spi, &lcd_cs_n, &lcd_rst_n, &lcd_ctl_data, &timer);
g_uart->Printf("a");
lcd.Initialize();


/*
//Reset LCD
lcd_rst.Set(0);
for(int i=0; i<50; i++)
lcd_rst.Set(0);
for(int i=0; i<50; i++)
lcd_rst.Set(1);
//Set everything on
lcd_cs.Set(0);
spi.BlockingWrite(0xa4);
spi.WaitForWrites();
lcd_cs.Set(1);
//Read the current temperatures
uint8_t temp;
uint8_t temp_frac;
temp_left.GetTemperature(temp, temp_frac);
g_uart->Printf("Left: %d.%02d C\n", temp, temp_frac * 100 / 256);
temp_right.GetTemperature(temp, temp_frac);
g_uart->Printf("Right: %d.%02d C\n", temp, temp_frac * 100 / 256);
*/

//Wait forever
while(1)
{}