📄 osram96x16.c
字号:
//
// The string has been displayed.
//
return;
}
//
// Advance to the next character.
//
pcStr++;
//
// Increment the X coordinate by the six columns that were just
// written.
//
ulX += 6;
}
}
//*****************************************************************************
//
//! Displays an image on the OLED display.
//!
//! \param pucImage is a pointer to the image data.
//! \param ulX is the horizontal position to display this image, specified in
//! columns from the left edge of the display.
//! \param ulY is the vertical position to display this image, specified in
//! eight scan line blocks from the top of the display (i.e. only 0 and 1 are
//! valid).
//! \param ulWidth is the width of the image, specified in columns.
//! \param ulHeight is the height of the image, specified in eight row blocks
//! (i.e. only 1 and 2 are valid).
//!
//! This function will display a bitmap graphic on the display. The image to
//! be displayed must be a multiple of eight scan lines high (i.e. one row) and
//! will be drawn at a vertical position that is a multiple of eight scan lines
//! (i.e. scan line zero or scan line eight, corresponding to row zero or row
//! one).
//!
//! The image data is organized with the first row of image data appearing left
//! to right, followed immediately by the second row of image data. Each byte
//! contains the data for the eight scan lines of the column, with the top scan
//! line being in the least significant bit of the byte and the bottom scan
//! line being in the most significant bit of the byte.
//!
//! For example, an image four columns wide and sixteen scan lines tall would
//! be arranged as follows (showing how the eight bytes of the image would
//! appear on the display):
//!
//! \verbatim
//! +-------+ +-------+ +-------+ +-------+
//! | | 0 | | | 0 | | | 0 | | | 0 |
//! | B | 1 | | B | 1 | | B | 1 | | B | 1 |
//! | y | 2 | | y | 2 | | y | 2 | | y | 2 |
//! | t | 3 | | t | 3 | | t | 3 | | t | 3 |
//! | e | 4 | | e | 4 | | e | 4 | | e | 4 |
//! | | 5 | | | 5 | | | 5 | | | 5 |
//! | 0 | 6 | | 1 | 6 | | 2 | 6 | | 3 | 6 |
//! | | 7 | | | 7 | | | 7 | | | 7 |
//! +-------+ +-------+ +-------+ +-------+
//!
//! +-------+ +-------+ +-------+ +-------+
//! | | 0 | | | 0 | | | 0 | | | 0 |
//! | B | 1 | | B | 1 | | B | 1 | | B | 1 |
//! | y | 2 | | y | 2 | | y | 2 | | y | 2 |
//! | t | 3 | | t | 3 | | t | 3 | | t | 3 |
//! | e | 4 | | e | 4 | | e | 4 | | e | 4 |
//! | | 5 | | | 5 | | | 5 | | | 5 |
//! | 4 | 6 | | 5 | 6 | | 6 | 6 | | 7 | 6 |
//! | | 7 | | | 7 | | | 7 | | | 7 |
//! +-------+ +-------+ +-------+ +-------+
//! \endverbatim
//!
//! This function is contained in <tt>osram96x16.c</tt>, with
//! <tt>osram96x16.h</tt> containing the API definition for use by
//! applications.
//!
//! \return None.
//
//*****************************************************************************
void
OSRAMImageDraw(const unsigned char *pucImage, unsigned long ulX,
unsigned long ulY, unsigned long ulWidth,
unsigned long ulHeight)
{
//
// Check the arguments.
//
ASSERT(ulX < 96);
ASSERT(ulY < 2);
ASSERT((ulX + ulWidth) <= 96);
ASSERT((ulY + ulHeight) <= 2);
//
// The first 36 columns of the LCD buffer are not displayed, so increment
// the X coorddinate by 36 to account for the non-displayed frame buffer
// memory.
//
ulX += 36;
//
// Loop while there are more rows to display.
//
while(ulHeight--)
{
//
// Write the starting address within this row.
//
OSRAMWriteFirst(0x80);
OSRAMWriteByte((ulY == 0) ? 0xb0 : 0xb1);
OSRAMWriteByte(0x80);
OSRAMWriteByte(ulX & 0x0f);
OSRAMWriteByte(0x80);
OSRAMWriteByte(0x10 | ((ulX >> 4) & 0x0f));
OSRAMWriteByte(0x40);
//
// Write this row of image data.
//
OSRAMWriteArray(pucImage, ulWidth - 1);
OSRAMWriteFinal(pucImage[ulWidth - 1]);
//
// Advance to the next row of the image.
//
pucImage += ulWidth;
ulY++;
}
}
//*****************************************************************************
//
//! Initialize the OLED display.
//!
//! \param bFast is a boolean that is \e true if the I2C interface should be
//! run at 400 kbps and \e false if it should be run at 100 kbps.
//!
//! This function initializes the I2C interface to the OLED display and
//! configures the SSD0303 controller on the panel.
//!
//! This function is contained in <tt>osram96x16.c</tt>, with
//! <tt>osram96x16.h</tt> containing the API definition for use by
//! applications.
//!
//! \return None.
//
//*****************************************************************************
void
OSRAMInit(tBoolean bFast)
{
unsigned long ulIdx;
//
// Enable the I2C and GPIO port B blocks as they are needed by this driver.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Configure the I2C SCL and SDA pins for I2C operation.
//
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
//
// Initialize the I2C master.
//
I2CMasterInit(I2C_MASTER_BASE, bFast);
//
// Compute the inter-byte delay for the SSD0303 controller. This delay is
// dependent upon the I2C bus clock rate; the slower the clock the longer
// the delay required.
//
// The derivation of this formula is based on a measured delay of
// OSRAMDelay(1700) for a 100 kHz I2C bus with the CPU running at 50 MHz
// (referred to as C). To scale this to the delay for a different CPU
// speed (since this is just a CPU-based delay loop) is:
//
// f(CPU)
// C * ----------
// 50,000,000
//
// To then scale this to the actual I2C rate (since it won't always be
// precisely 100 kHz):
//
// f(CPU) 100,000
// C * ---------- * -------
// 50,000,000 f(I2C)
//
// This equation will give the inter-byte delay required for any
// configuration of the I2C master. But, as arranged it is impossible to
// directly compute in 32-bit arithmetic (without loosing a lot of
// accuracy). So, the equation is simplified.
//
// Since f(I2C) is generated by dividing down from f(CPU), replace it with
// the equivalent (where TPR is the value programmed into the Master Timer
// Period Register of the I2C master, with the 1 added back):
//
// 100,000
// f(CPU) -------
// C * ---------- * f(CPU)
// 50,000,000 ------------
// 2 * 10 * TPR
//
// Inverting the dividend in the last term:
//
// f(CPU) 100,000 * 2 * 10 * TPR
// C * ---------- * ----------------------
// 50,000,000 f(CPU)
//
// The f(CPU) now cancels out.
//
// 100,000 * 2 * 10 * TPR
// C * ----------------------
// 50,000,000
//
// Since there are no clock frequencies left in the equation, this equation
// also works for 400 kHz bus operation as well, since the 100,000 in the
// numerator becomes 400,000 but C is 1/4, which cancel out each other.
// Reducing the constants gives:
//
// TPR TPR TPR
// C * --- = 1700 * --- = 340 * --- = 68 * TPR
// 25 25 5
//
// Note that the constant C is actually a bit larger than it needs to be in
// order to provide some safety margin.
//
// When the panel is being initialized, the value of C actually needs to be
// a bit longer (3400 instead of 1700). So, set the larger value for now.
//
g_ulDelay = 136 * (HWREG(I2C_MASTER_BASE + I2C_MASTER_O_TPR) + 1);
//
// Initialize the SSD0303 controller. Loop through the initialization
// sequence doing a single I2C transfer for each command.
//
for(ulIdx = 0; ulIdx < sizeof(g_pucOSRAMInit);
ulIdx += g_pucOSRAMInit[ulIdx] + 1)
{
//
// Send this command.
//
OSRAMWriteFirst(g_pucOSRAMInit[ulIdx + 1]);
OSRAMWriteArray(g_pucOSRAMInit + ulIdx + 2, g_pucOSRAMInit[ulIdx] - 2);
OSRAMWriteFinal(g_pucOSRAMInit[ulIdx + g_pucOSRAMInit[ulIdx]]);
}
//
// Now, switch to the actual value of C.
//
g_ulDelay = 68 * (HWREG(I2C_MASTER_BASE + I2C_MASTER_O_TPR) + 1);
//
// Clear the frame buffer.
//
OSRAMClear();
}
//*****************************************************************************
//
//! Turns on the OLED display.
//!
//! This function will turn on the OLED display, causing it to display the
//! contents of its internal frame buffer.
//!
//! This function is contained in <tt>osram96x16.c</tt>, with
//! <tt>osram96x16.h</tt> containing the API definition for use by
//! applications.
//!
//! \return None.
//
//*****************************************************************************
void
OSRAMDisplayOn(void)
{
//
// Turn on the DC-DC converter and the display.
//
OSRAMWriteFirst(0x80);
OSRAMWriteByte(0xad);
OSRAMWriteByte(0x80);
OSRAMWriteByte(0x8b);
OSRAMWriteByte(0x80);
OSRAMWriteFinal(0xaf);
}
//*****************************************************************************
//
//! Turns off the OLED display.
//!
//! This function will turn off the OLED display. This will stop the scanning
//! of the panel and turn off the on-chip DC-DC converter, preventing damage to
//! the panel due to burn-in (it has similar characters to a CRT in this
//! respect).
//!
//! This function is contained in <tt>osram96x16.c</tt>, with
//! <tt>osram96x16.h</tt> containing the API definition for use by
//! applications.
//!
//! \return None.
//
//*****************************************************************************
void
OSRAMDisplayOff(void)
{
//
// Turn off the DC-DC converter and the display.
//
OSRAMWriteFirst(0x80);
OSRAMWriteByte(0xad);
OSRAMWriteByte(0x80);
OSRAMWriteByte(0x8a);
OSRAMWriteByte(0x80);
OSRAMWriteFinal(0xae);
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -