![]() |
MSPM0_ValvanoWare
1.0
ECE445L starter code
|
I2C and MKII boosterpack sensors. More...
Files | |
| file | I2C.h |
| Software driver functions for I2C and MKII boosterpack. | |
| file | LCD.h |
| LCD on MKII boosterpack. | |
Macros | |
| #define | LCD_BLACK 0x0000 |
| The following constants are possible colors for the LCD in RGB format. | |
| #define | LCD_BLUE 0x001F |
| #define | LCD_DARKBLUE 0x34BF |
| #define | LCD_RED 0xF800 |
| #define | LCD_GREEN 0x07E0 |
| #define | LCD_LIGHTGREEN 0x07EF |
| #define | LCD_ORANGE 0xFD60 |
| #define | LCD_CYAN 0x07FF |
| #define | LCD_MAGENTA 0xF81F |
| #define | LCD_YELLOW 0xFFE0 |
| #define | LCD_WHITE 0xFFFF |
| #define | LCD_GREY 0x8410 |
| #define | STANDARD_GALACTIC_ALPHABET 0 |
| Set STANDARD_GALACTIC_ALPHABET to 1 for Commander Keen alphabet. | |
Functions | |
| void | I2C_Init (void) |
| Initialize I2C. More... | |
| uint8_t | I2C_Recv1 (int8_t slave) |
| Receive one byte. More... | |
| uint16_t | I2C_Recv2 (int8_t slave) |
| Receive two bytes. More... | |
| int | I2C_Send (uint8_t slave, uint8_t *pData, uint32_t count) |
| write 1 to 8 bytes to I2C. More... | |
| int | I2C_SendData (uint8_t slave, uint8_t *pData, uint32_t count) |
| send large buffer to I2C. More... | |
| int | I2C_Send1 (int8_t slave, uint8_t data) |
| Send one byte. More... | |
| int | I2C_Send2 (int8_t slave, uint8_t data1, uint8_t data2) |
| Send two bytes. More... | |
| int | I2C_Send3 (int8_t slave, uint8_t data1, uint8_t data2, uint8_t data3) |
| Send three bytes. More... | |
| void | I2C_LightSensor_Init (void) |
| Initialize OPT3001. More... | |
| uint32_t | I2C_LightSensor_Input (void) |
| Input from OPT3001. More... | |
| void | I2C_LightSensor_Start (void) |
| Start OPT3001. More... | |
| int | I2C_LightSensor_End (uint32_t *light) |
| Finish OPT3001. More... | |
| void | I2C_TempSensor_Init (void) |
| Initialize TMP006. More... | |
| void | I2C_TempSensor_Input (int32_t *sensorV, int32_t *localT) |
| Input from TMP006. More... | |
| void | I2C_TempSensor_Start (void) |
| Start TMP006. More... | |
| int | I2C_TempSensor_End (int32_t *sensorV, int32_t *localT) |
| Finish TMP006. More... | |
| void | LCD_Init (void) |
| Initialize MKII LCD. More... | |
| void | LCD_DrawPixel (int16_t x, int16_t y, uint16_t color) |
| Color one pixel. More... | |
| void | LCD_DrawFastVLine (int16_t x, int16_t y, int16_t h, uint16_t color) |
| Draw a vertical line. More... | |
| void | LCD_DrawFastHLine (int16_t x, int16_t y, int16_t w, uint16_t color) |
| Draw a horizontal line. More... | |
| void | LCD_FillScreen (uint16_t color) |
| Fill the screen. More... | |
| void | LCD_FillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) |
| Draw a filled rectangle. More... | |
| uint16_t | LCD_Color565 (uint8_t r, uint8_t g, uint8_t b) |
| RGB to color creation. More... | |
| uint16_t | LCD_SwapColor (uint16_t x) |
| Swaps red and blue. More... | |
| void | LCD_DrawBitmap (int16_t x, int16_t y, const uint16_t *image, int16_t w, int16_t h) |
| Displays a BMP image. More... | |
| void | LCD_DrawCharS (int16_t x, int16_t y, char c, int16_t textColor, int16_t bgColor, uint8_t size) |
| Draw a character. More... | |
| void | LCD_DrawChar (int16_t x, int16_t y, char c, int16_t textColor, int16_t bgColor, uint8_t size) |
| Draw a character. More... | |
| uint32_t | LCD_DrawString (uint16_t x, uint16_t y, char *pt, int16_t textColor) |
| Draw a string. More... | |
| void | LCD_SetCursor (uint32_t newX, uint32_t newY) |
| Move the cursor. More... | |
| void | LCD_OutUDec (uint32_t n, int16_t textColor) |
| Output an unsigned decimal. More... | |
| void | LCD_OutUDec4 (uint32_t n, int16_t textColor) |
| Output a 4-digit unsigned decimal. More... | |
| void | LCD_OutUDec5 (uint32_t n, int16_t textColor) |
| Output a 5-digit unsigned decimal. More... | |
| void | LCD_OutUFix2_1 (uint32_t n, int16_t textColor) |
| Output a 2-digit fixed-point decimal. More... | |
| void | LCD_OutUHex2 (uint32_t n, int16_t textColor) |
| Output a 2-digit hexadecimal number. More... | |
| void | LCD_OutChar (char ch) |
| Output a character. More... | |
| void | LCD_OutString (char *ptr) |
| Output a string. More... | |
| void | LCD_SetTextColor (uint16_t color) |
| sets the text color More... | |
| void | LCD_Drawaxes (uint16_t axisColor, uint16_t bgColor, char *xLabel, char *yLabel1, uint16_t label1Color, char *yLabel2, uint16_t label2Color, int32_t ymax, int32_t ymin) |
| Initializes a plot. More... | |
| void | LCD_PlotPoint (int32_t data1, uint16_t color1) |
| Plot one point. More... | |
| void | LCD_PlotIncrement (void) |
| Moves the plot cursor in time. More... | |
I2C and MKII boosterpack sensors.
MKII boosterpack LCD.
| Pin | Function | Description |
|---|---|---|
| PA27 | GPIO | J1.8 ambient light (OPT3001) interrupt (digital) |
| PB2 | I2C1-SCL | J1.9 ambient light (OPT3001) and temperature sensor (TMP006) |
| PB3 | I2C1-SDA | J1.10 ambient light (OPT3001) and temperature sensor (TMP006) |
| PB16 | GPIO | J2.11 temperature sensor (TMP006) interrupt (digital) |
| Pin | Function | Description |
|---|---|---|
| PB9 | SPI1 SCLK | J1.7 LCD SPI clock (SPI) |
| PB6 | SPI1 CS0 | J2.13 LCD SPI CS (SPI) |
| PB8 | SPI1 PICO | J2.15 LCD SPI data (SPI) |
| PB15 | GPIO | J2.17 LCD !RST (digital) |
| PA13 | GPIO | J4.31 LCD RS (digital) |
| void I2C_Init | ( | void | ) |
Initialize I2C.
Initialize PB2 and PB3 for I2C for 400kHz clock. Uses busy-wait synchronization
| none |
| int I2C_LightSensor_End | ( | uint32_t * | light | ) |
Finish OPT3001.
Finish a measurement using the OPT3001. Query the OPT3001 light sensor for a measurement. If no measurement is currently in progress, start one and return zero immediately. If the measurement is not yet complete, return zero immediately. If the measurement is complete, store the result in the pointer provided and return one.
| light | pointer to a place to return data |
| void I2C_LightSensor_Init | ( | void | ) |
Initialize OPT3001.
Initialize OPT3001 on MKII boosterpack. PA27 is GPIO pin for input, which corresponds with BoosterPack pins J1.8 (Light Sensor interrupt). Initialize PB2 and PB3 for I2C pins, which correspond with BoosterPack pins J1.9 (SCL) and J1.10 (SDA)
| none |
| uint32_t I2C_LightSensor_Input | ( | void | ) |
Input from OPT3001.
Query the OPT3001 light sensor for a measurement. Wait until the measurement is ready, which may take 800 ms
| none |
| void I2C_LightSensor_Start | ( | void | ) |
Start OPT3001.
Start a measurement using the OPT3001. If a measurement is currently in progress, return without starting another measurement
| none |
| uint8_t I2C_Recv1 | ( | int8_t | slave | ) |
Receive one byte.
Receive one byte from specified slave. Uses busy-wait synchronization
[send address][read data]
| slave | is slave address |
| uint16_t I2C_Recv2 | ( | int8_t | slave | ) |
Receive two bytes.
Receive two bytes from specified slave. Uses busy-wait synchronization
[send address][read data][read data]
| slave | is slave address |
| int I2C_Send | ( | uint8_t | slave, |
| uint8_t * | pData, | ||
| uint32_t | count | ||
| ) |
| int I2C_Send1 | ( | int8_t | slave, |
| uint8_t | data | ||
| ) |
Send one byte.
Send one byte to specified slave. Uses busy-wait synchronization
[send address][send data]
| slave | slave address |
| data | byte to be sent |
| int I2C_Send2 | ( | int8_t | slave, |
| uint8_t | data1, | ||
| uint8_t | data2 | ||
| ) |
Send two bytes.
Send two bytes to specified slave. Uses busy-wait synchronization
[send address][send data1][send data2]
| slave | is slave address |
| data1 | is first byte to be sent |
| data2 | is second byte to be sent |
| int I2C_Send3 | ( | int8_t | slave, |
| uint8_t | data1, | ||
| uint8_t | data2, | ||
| uint8_t | data3 | ||
| ) |
Send three bytes.
Send three bytes to specified slave. Uses busy-wait synchronization
[send address][send data1][send data2][send data3]
| slave | is slave address |
| data1 | is first byte to be sent |
| data2 | is second byte to be sent |
| data3 | is third byte to be sent |
| int I2C_SendData | ( | uint8_t | slave, |
| uint8_t * | pData, | ||
| uint32_t | count | ||
| ) |
| int I2C_TempSensor_End | ( | int32_t * | sensorV, |
| int32_t * | localT | ||
| ) |
Finish TMP006.
Finish a measurement using the OPT3001. Query the TMP006 temperature sensor for a measurement. If no measurement is currently in progress, start one and return zero immediately. If the measurement is not yet complete, return zero immediately. If the measurement is complete, store the result in the pointers provided and return one.
| sensorV | is signed pointer to store sensor voltage (units 100*nV) |
| localT | is signed pointer to store local temperature (units 100,000*C) |
| void I2C_TempSensor_Init | ( | void | ) |
Initialize TMP006.
Initialize TMP006 on MKII boosterpack. PB16 is GPIO pin for input, which corresponds with BoosterPack pins J1.8 (Light Sensor interrupt). Initialize PB2 and PB3 for I2C pins, which correspond with BoosterPack pins J1.9 (SCL) and J1.10 (SDA)
| none |
| void I2C_TempSensor_Input | ( | int32_t * | sensorV, |
| int32_t * | localT | ||
| ) |
Input from TMP006.
Query the TMP006 temperature sensor for a measurement. Wait until the measurement is ready, which may take 4 seconds
| sensorV | is signed pointer to store sensor voltage (units 100*nV) |
| localT | is signed pointer to store local temperature (units 100,000*C) |
| void I2C_TempSensor_Start | ( | void | ) |
Start TMP006.
Start a measurement using the TMP006. If a measurement is currently in progress, return without starting another measurement
| none |
| uint16_t LCD_Color565 | ( | uint8_t | r, |
| uint8_t | g, | ||
| uint8_t | b | ||
| ) |
RGB to color creation.
Pass 8-bit (each) R,G,B and get back 16-bit packed color.
| r | red value |
| g | green value |
| b | blue value |
| void LCD_Drawaxes | ( | uint16_t | axisColor, |
| uint16_t | bgColor, | ||
| char * | xLabel, | ||
| char * | yLabel1, | ||
| uint16_t | label1Color, | ||
| char * | yLabel2, | ||
| uint16_t | label2Color, | ||
| int32_t | ymax, | ||
| int32_t | ymin | ||
| ) |
Initializes a plot.
Set up the axes, labels, and other variables to allow data to be plotted in a chart using the functions LCD_PlotPoint() and LCD_PlotIncrement(). If yLabel2 is empty string, no yLabel2 is printed, and yLabel1 is centered
| axisColor | 16-bit color for axes, which can be produced by LCD_Color565() |
| bgColor | 16-bit color for plot background, which can be produced by LCD_Color565() |
| xLabel | pointer to a null terminated string for x-axis (~4 character space) |
| yLabel1 | pointer to a null terminated string for top of y-axis (~3-5 character space) |
| label1Color | 16-bit color for y-axis label1, which can be produced by LCD_Color565() |
| yLabel2 | pointer to a null terminated string for bottom of y-axis (~3 character space) |
| label2Color | 16-bit color for y-axis label2, which can be produced by LCD_Color565() |
| ymax | maximum value to be printed |
| ymin | minimum value to be printed |
| void LCD_DrawBitmap | ( | int16_t | x, |
| int16_t | y, | ||
| const uint16_t * | image, | ||
| int16_t | w, | ||
| int16_t | h | ||
| ) |
Displays a BMP image.
Displays a 16-bit color BMP image. A bitmap file that is created by a PC image processing program has a header and may be padded with dummy columns so the data have four byte alignment. This function assumes that all of that has been stripped out, and the array image[] has one 16-bit halfword for each pixel to be displayed on the screen (encoded in reverse order, which is standard for bitmap files). An array can be created in this format from a 24-bit-per-pixel .bmp file using the associated BmpConvert16.exe converter program. (x,y) is the screen location of the lower left corner of BMP image
Requires (11 + 2*w*h) bytes of transmission (assuming image fully on screen)
| x | horizontal position of the bottom left corner of the image, columns from the left edge |
| y | vertical position of the bottom left corner of the image, rows from the top edge |
| image | pointer to a 16-bit color BMP image |
| w | number of pixels wide |
| h | number of pixels tall |
| void LCD_DrawChar | ( | int16_t | x, |
| int16_t | y, | ||
| char | c, | ||
| int16_t | textColor, | ||
| int16_t | bgColor, | ||
| uint8_t | size | ||
| ) |
Draw a character.
Advanced character draw function. This is similar to the function from Adafruit_GFX.c but adapted for this processor. However, this function only uses one call to setAddrWindow(), which allows it to run at least twice as fast.
Requires (11 + size*size*6*8) bytes of transmission (assuming image fully on screen)
| x | horizontal position of the top left corner of the character, columns from the left edge |
| y | vertical position of the top left corner of the character, rows from the top edge |
| c | character to be printed |
| textColor | 16-bit color of the character |
| bgColor | 16-bit color of the background |
| size | number of pixels per character pixel (e.g. size==2 prints each pixel of font as 2x2 square) |
| void LCD_DrawCharS | ( | int16_t | x, |
| int16_t | y, | ||
| char | c, | ||
| int16_t | textColor, | ||
| int16_t | bgColor, | ||
| uint8_t | size | ||
| ) |
Draw a character.
Simple character draw function. This is the same function from Adafruit_GFX.c but adapted for this processor. However, each call to LCD_DrawPixel() calls setAddrWindow(), which needs to send many extra data and commands. If the background color is the same as the text color, no background will be printed, and text can be drawn right over existing images without covering them with a box.
Requires (11 + 2*size*size)*6*8 bytes of transmission (image fully on screen; textcolor != bgColor)
| x | horizontal position of the top left corner of the character, columns from the left edge |
| y | vertical position of the top left corner of the character, rows from the top edge |
| c | character to be printed |
| textColor | 16-bit color of the character |
| bgColor | 16-bit color of the background |
| size | number of pixels per character pixel (e.g. size==2 prints each pixel of font as 2x2 square) |
| void LCD_DrawFastHLine | ( | int16_t | x, |
| int16_t | y, | ||
| int16_t | w, | ||
| uint16_t | color | ||
| ) |
Draw a horizontal line.
Draw a horizontal line at the given coordinates with the given width and color. A horizontal line is parallel to the shorter side of the rectangular display
Requires (11 + 2*w) bytes of transmission (assuming image fully on screen)
| x | horizontal position of the start of the line, columns from the left edge |
| y | vertical position of the start of the line, rows from the top edge |
| w | horizontal width of the line |
| color | 16-bit color, which can be produced by LCD_Color565() |
| void LCD_DrawFastVLine | ( | int16_t | x, |
| int16_t | y, | ||
| int16_t | h, | ||
| uint16_t | color | ||
| ) |
Draw a vertical line.
Draw a vertical line at the given coordinates with the given height and color.
A vertical line is parallel to the longer side of the rectangular display
Requires (11 + 2*h) bytes of transmission (assuming image fully on screen)
| x | horizontal position of the start of the line, columns from the left edge |
| y | vertical position of the start of the line, rows from the top edge |
| h | vertical height of the line |
| color | 16-bit color, which can be produced by LCD_Color565() |
| void LCD_DrawPixel | ( | int16_t | x, |
| int16_t | y, | ||
| uint16_t | color | ||
| ) |
Color one pixel.
Color the pixel at the given coordinates with the given color.
Requires 13 bytes of transmission
x must be less than 128
x 0 is on the left, 126 is near the right
y must be less than 128 y 126 is near the wires, 0 is the side opposite the wires
| x | horizontal position of the pixel, columns from the left edge |
| y | vertical position of the pixel, rows from the top edge |
| color | 16-bit color, which can be produced by LCD_Color565() |
| uint32_t LCD_DrawString | ( | uint16_t | x, |
| uint16_t | y, | ||
| char * | pt, | ||
| int16_t | textColor | ||
| ) |
Draw a string.
String draw function. 13 rows (0 to 12) and 21 characters (0 to 20)
Requires (11 + size*size*6*8) bytes of transmission for each character
| x | columns from the left edge (0 to 20) |
| y | rows from the top edge (0 to 12) |
| pt | pointer to a null terminated string to be printed |
| textColor | 16-bit color of the characters |
| void LCD_FillRect | ( | int16_t | x, |
| int16_t | y, | ||
| int16_t | w, | ||
| int16_t | h, | ||
| uint16_t | color | ||
| ) |
Draw a filled rectangle.
Draw a filled rectangle at the given coordinates with the given width, height, and color.
Requires (11 + 2*w*h) bytes of transmission (assuming image fully on screen)
| x | horizontal position of the top left corner of the rectangle, columns from the left edge |
| y | vertical position of the top left corner of the rectangle, rows from the top edge |
| w | horizontal width of the rectangle |
| h | vertical height of the rectangle |
| color | 16-bit color, which can be produced by LCD_Color565() |
| void LCD_FillScreen | ( | uint16_t | color | ) |
Fill the screen.
Fill the screen with the given color.
Requires 33,293 bytes of transmission
| color | 16-bit color, which can be produced by LCD_Color565() |
| void LCD_Init | ( | void | ) |
Initialize MKII LCD.
Initialize Crystalfontz CFAF128128B-0145T color 128x128-pixel TFT LCD BoosterPack pins
| none |
| void LCD_OutChar | ( | char | ch | ) |
Output a character.
Output one character to the LCD Position determined by LCD_SetCursor command Color set by LCD_SetTextColor
| ch | 8-bit ASCII character |
| void LCD_OutString | ( | char * | ptr | ) |
Output a string.
Print a string of characters to the ST7735 LCD. Position determined by LCD_SetCursor command Color set by LCD_SetTextColor The string will not automatically wrap.
| ptr | pointer to NULL-terminated ASCII string |
| void LCD_OutUDec | ( | uint32_t | n, |
| int16_t | textColor | ||
| ) |
Output an unsigned decimal.
Output a 32-bit number in unsigned decimal format Position determined by LCD_SetCursor command
| n | 32-bit number to be transferred |
| textColor | 16-bit color of the numbers |
| void LCD_OutUDec4 | ( | uint32_t | n, |
| int16_t | textColor | ||
| ) |
Output a 4-digit unsigned decimal.
Output a 32-bit number in unsigned 4-digit decimal format with no space before or after. Position determined by LCD_SetCursor command
| n | 32-bit number to be transferred |
| textColor | 16-bit color of the numbers |
| void LCD_OutUDec5 | ( | uint32_t | n, |
| int16_t | textColor | ||
| ) |
Output a 5-digit unsigned decimal.
Output a 32-bit number in unsigned 5-digit decimal format Position determined by LCD_SetCursor command
| n | 32-bit number to be transferred |
| textColor | 16-bit color of the numbers |
| void LCD_OutUFix2_1 | ( | uint32_t | n, |
| int16_t | textColor | ||
| ) |
Output a 2-digit fixed-point decimal.
Output a 32-bit number in unsigned 3-digit fixed point, 0.1 resolution numbers 0 to 999 printed as " 0.0" to "99.9" Position determined by LCD_SetCursor command
| n | 32-bit number to be transferred |
| textColor | 16-bit color of the numbers |
| void LCD_OutUHex2 | ( | uint32_t | n, |
| int16_t | textColor | ||
| ) |
Output a 2-digit hexadecimal number.
Output a 32-bit number in unsigned 2-digit hexadecimal format numbers 0 to 255 printed as "00," to "FF," Position determined by LCD_SetCursor command
| n | 32-bit number to be transferred |
| textColor | 16-bit color of the numbers |
| void LCD_PlotIncrement | ( | void | ) |
Moves the plot cursor in time.
Increment the plot between subsequent calls to LCD_PlotPoint(). Automatically wrap and clear the column to be printed to.
| none |
| void LCD_PlotPoint | ( | int32_t | data1, |
| uint16_t | color1 | ||
| ) |
Plot one point.
Plot a point on the chart. To plot several points in the same column, call this function repeatedly before calling LCD_PlotIncrement(). The units of the data are the same as the ymax and ymin values specified in the initialization function.
| data1 | value to be plotted (units not specified) |
| color1 | 16-bit color for the point, which can be produced by LCD_Color565() |
| void LCD_SetCursor | ( | uint32_t | newX, |
| uint32_t | newY | ||
| ) |
Move the cursor.
Move the cursor to the desired X- and Y-position. The next character of the next unsigned decimal will be printed here. X=0 is the leftmost column. Y=0 is the top row. The cursor is used by the "Out" functions, but not the "Draw" functions
| newX | new X-position of the cursor (0<=newX<=20) |
| newY | new Y-position of the cursor (0<=newY<=12) |
| void LCD_SetTextColor | ( | uint16_t | color | ) |
sets the text color
Sets the color in which the characters will be printed Background color is fixed at black
| color | 16-bit packed color |
| uint16_t LCD_SwapColor | ( | uint16_t | x | ) |
Swaps red and blue.
Swaps the red and blue values of the given 16-bit packed color; green is unchanged.
| x | 16-bit color in format B, G, R |