]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/board/diag/oled_display/src/oled_display.c
9f9fa5b29c1816d35fe9b71478fca39d0f629a49
[processor-sdk/pdk.git] / packages / ti / board / diag / oled_display / src / oled_display.c
1 /*
2  * Copyright (c) 2016-2020, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
34 /**
35  *
36  * \file  oled_display_test.c
37  *
38  * \brief This file contains oled display test functions.
39  *
40  *  Supported SoCs : K2G & AM64X
41  *
42  *  Supported Platforms: k2g_ice & am64x_evm.
43  *
44  ******************************************************************************/
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
50 #if !defined(SOC_AM64X)
51 #include <ti/drv/gpio/GPIO.h>
52 #include <ti/drv/gpio/soc/GPIO_soc.h>
53 #endif
55 #include <ti/drv/i2c/I2C.h>
56 #include <ti/drv/i2c/soc/I2C_soc.h>
57 #include <ti/drv/uart/UART_stdio.h>
59 #if defined(SOC_K2G) || defined(SOC_AM64X)
60 #include "diag_common_cfg.h"
61 #endif
63 #include "board.h"
64 #include "board_cfg.h"
65 #include "oled_display.h"
66 #include "icek2g_oled.h"
68 #if defined(SOC_AM64X)
69 #include <ti/drv/i2c/I2C.h>
70 #include <ti/drv/i2c/soc/I2C_soc.h>
71 #include "board_internal.h"
72 #include "board_i2c_io_exp.h"
74 /* Platform test return codes */
75 #define TEST_PASS     (0)
76 #define TEST_FAIL     (-1)
78 #endif
80 #if !defined(SOC_AM64X)
81 /* GPIO pin value definitions */
82 #define GPIO_PIN_VAL_LOW     (0U)
83 #define GPIO_PIN_VAL_HIGH    (1U)
85 #define GPIO_INDEX           (0U)
87 /* Port and pin number mask for LCD GPIO.
88    Bits 7-0: Pin number  and Bits 15-8: Port number */
89 #define LCD_BST_CONV_CTL_GPIO    0x002D
90 #define LCD_RESET                0x0134
91 #endif
93 extern I2C_config_list I2C_config;
95 #if !defined(SOC_AM64X)
96 extern void BOARD_delay(uint32_t usecs);
98 /* GPIO Driver board specific pin configuration structure */
99 GPIO_PinConfig gpioPinConfigs[] = {
100     LCD_BST_CONV_CTL_GPIO | GPIO_CFG_OUTPUT,
101     LCD_RESET | GPIO_CFG_OUTPUT,
102 };
104 /* GPIO Driver call back functions */
105 GPIO_CallbackFxn gpioCallbackFunctions[] = {
106     NULL
107 };
109 GPIO_v0_Config GPIO_v0_config = {
110     gpioPinConfigs,
111     gpioCallbackFunctions,
112     sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
113     sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
114     0,
115 };
117 #endif
118 /**
119  *  \brief    This function executes oled display detection test
120  *
121  *  \param    void
122  *
123  * \return
124  * \n         TEST_PASS  - Test Passed
125  * \n         TEST_FAIL  - Test Failed
126  */
127 static TEST_STATUS oled_display_detect_test(void)
129         uint32_t index;
130         I2C_Params i2cParams;
131     I2C_Handle handle = NULL;
132         uint8_t tx;
133         uint8_t rx;
134         I2C_Transaction i2cTransaction;
136         for (index=0; I2C_config[index].fxnTablePtr != NULL; index++)
137         {
138                 ((I2C_HwAttrs *)I2C_config[index].hwAttrs)->enableIntr = false;
139         }
141         I2C_init();
143     I2C_Params_init(&i2cParams);
145     handle = I2C_open(BOARD_OLED_DISPLAY_INSTANCE, &i2cParams);
146         if(handle == NULL)
147         {
148                 UART_printf("I2C Handle open failed");
149                 return(TEST_FAIL);
150         }
152     I2C_transactionInit(&i2cTransaction);
153         i2cTransaction.slaveAddress = OLED_SLAVE_ADDR;
154         i2cTransaction.writeBuf = &tx;
155         i2cTransaction.writeCount = 1;
156         i2cTransaction.readBuf = &rx;
157         i2cTransaction.readCount = 0;
158         tx = 0x81;
159         rx = 0x0;
160         I2C_transfer(handle, &i2cTransaction);
161         BOARD_delay(1000);
162         i2cTransaction.writeCount = 0;
163         i2cTransaction.readCount = 1;
165         I2C_transfer(handle, &i2cTransaction);
166         if(rx == 0x0)
167     {
168         UART_printf ("Oled display Detection Failed!\n");
169         return(TEST_FAIL);
170     }
172     UART_printf ("\nOled display Detection Successful!\n");
174         I2C_close(handle);
175     return (TEST_PASS);
178 #if !defined(SOC_AM64X)
179 /**
180  * \brief       This function configures voltage regulator gpio's for lcd
181  *
182  * \param       void
183  *
184  * \return
185  * \n      TEST_PASS  - Test Passed
186  * \n      TEST_FAIL  - Test Failed
187  *
188  */
189 static TEST_STATUS lcd_gpio_config(void)
191     GPIO_write(GPIO_INDEX, GPIO_PIN_VAL_HIGH);
192     BOARD_delay(1000);
193     GPIO_write(GPIO_INDEX, GPIO_PIN_VAL_LOW);
195     GPIO_write(1, GPIO_PIN_VAL_LOW);
196     BOARD_delay(1000);
197     GPIO_write(1, GPIO_PIN_VAL_HIGH);
199         return (TEST_PASS);
201 #endif
203 /**
204  *  \brief    This function is used to perform Oled display detection
205  *            test and Oled display position test
206  *
207  *  \param    void
208  *
209  * \return
210  * \n         TEST_PASS  - Test Passed
211  * \n         TEST_FAIL  - Test Failed
212  */
213 static TEST_STATUS run_oled_display_test(void)
215         OLED_RET retVal;
216         TEST_STATUS testStatus;
218 #if !defined(SOC_AM64X)
219         GPIO_init();
221         testStatus = lcd_gpio_config();
222         if(testStatus != TEST_PASS)
223         {
224                 UART_printf("\n gpio_config Failed\n");
225                 return (testStatus);
226         }
227 #endif
229     UART_printf("\nRunning Oled display Detect Test\n");
231     testStatus = oled_display_detect_test();
232     if(testStatus != TEST_PASS)
233         {
234                 UART_printf("\nOled display Detect Test Failed!!\n");
235                 return (testStatus);
236         }
237         else
238         {
239                 UART_printf("\nOled display Detect Test Passed!\n");
240         }
242     retVal = oledInit();
243         if (retVal != OLED_SUCCESS)
244         {
245                 UART_printf("oledInit: oled module init Failed\n");
246                 return (TEST_FAIL);
247         }
248         retVal = clear();
249         if (retVal != OLED_SUCCESS)
250         {
251                 UART_printf("clear: oled screen clear Failed\n");
252                 return (TEST_FAIL);
253         }
254         retVal = setline(0);
255         if (retVal != OLED_SUCCESS)
256         {
257                 UART_printf("setline: line setting to first Failed\n");
258                 return (TEST_FAIL);
259         }
260         retVal = setOrientation(1);
261         if (retVal != OLED_SUCCESS)
262         {
263                 UART_printf("setOrientation: Horizontal orientation Failed\n");
264                 return (TEST_FAIL);
265         }
266         retVal = printstr((int8_t *)"Welcome");
267         if (retVal != OLED_SUCCESS)
268         {
269                 UART_printf("printstr: Oled print Failed\n");
270                 return (TEST_FAIL);
271         }
272         BOARD_delay(2000);
273         retVal = clear();
274         if (retVal != OLED_SUCCESS)
275         {
276                 UART_printf("clear: oled screen clear Failed\n");
277                 return (TEST_FAIL);
278         }
279         retVal = setline(1);
280         if (retVal != OLED_SUCCESS)
281         {
282                 UART_printf("setline: line setting to second Failed\n");
283                 return (TEST_FAIL);
284         }
285         retVal = setOrientation(1);
286         if (retVal != OLED_SUCCESS)
287         {
288                 UART_printf("setOrientation: Horizontal orientation Failed\n");
289                 return (TEST_FAIL);
290         }
291         retVal = printstr((int8_t *)"K2G ICE EVM");
292         if (retVal != OLED_SUCCESS)
293         {
294                 UART_printf("printstr: Oled print Failed\n");
295                 return (TEST_FAIL);
296         }
297         BOARD_delay(500000);
298         retVal = clear();
299         if (retVal != OLED_SUCCESS)
300         {
301                 UART_printf("clear: oled screen clear Failed\n");
302                 return (TEST_FAIL);
303         }
304         //print two lines
305         retVal = setline(0);
306         if (retVal != OLED_SUCCESS)
307         {
308                 UART_printf("setline: line setting to first Failed\n");
309                 return (TEST_FAIL);
310         }
311         retVal = setOrientation(1);
312         if (retVal != OLED_SUCCESS)
313         {
314                 UART_printf("setOrientation: Horizontal orientation Failed\n");
315                 return (TEST_FAIL);
316         }
317         retVal = printstr((int8_t *)"Welcome");
318         if (retVal != OLED_SUCCESS)
319         {
320                 UART_printf("printstr: Oled print Failed\n");
321                 return (TEST_FAIL);
322         }
323         retVal = setline(1);
324         if (retVal != OLED_SUCCESS)
325         {
326                 UART_printf("setline: line setting to second Failed\n");
327                 return (TEST_FAIL);
328         }
329         retVal = printstr((int8_t *)"K2G ICE EVM");
330         if (retVal != OLED_SUCCESS)
331         {
332                 UART_printf("printstr: Oled print Failed\n");
333                 return (TEST_FAIL);
334         }
335         BOARD_delay(500000);
336         retVal = scrollDisplayLeft();
337         if (retVal != OLED_SUCCESS)
338         {
339                 UART_printf("scrollDisplayLeft: Left scroll Failed\n");
340                 return (TEST_FAIL);
341         }
342         BOARD_delay(2000000);
343         retVal = scrollDisplayRight();
344         if (retVal != OLED_SUCCESS)
345         {
346                 UART_printf("scrollDisplayRight: Right scroll Failed\n");
347                 return (TEST_FAIL);
348         }
349         BOARD_delay(1000000);
351         if (retVal == OLED_SUCCESS)
352         {
353                 UART_printf("OLED LCD Display test PASS\n");
354                 return TEST_PASS;
355         }
356         else
357         {
358                 UART_printf("OLED LCD Display test FAIL\n");
359                 return TEST_FAIL;
360         }
362 #if !defined(SOC_AM64X)
363     return (testStatus);
364 #endif
368 /**
369  * \brief This function performs Oled display test
370  *
371  * \param void
372  *
373  * \return
374  * \n      TEST_PASS  - Test Passed
375  * \n      TEST_FAIL  - Test Failed
376  *
377  */
378 TEST_STATUS oledTest(void)
380         TEST_STATUS testStatus = 0;
382         UART_printf("\n********************************\n");
383         UART_printf(  "        OLED DISPLAY Test       \n");
384         UART_printf(  "********************************\n");
386         //Release OLED reset
387 #if defined(SOC_AM64X)
388     Board_I2cInitCfg_t i2cCfg;
390 #if !defined (__aarch64__)
391     /* MCU I2C instance will be active by default for R5 core.
392      * Need update HW attrs to enable MAIN I2C instance.
393      */
394     enableMAINI2C(1, CSL_I2C1_CFG_BASE);
395 #endif
397     i2cCfg.i2cInst   = BOARD_I2C_IOEXP_DEVICE1_INSTANCE;
398     i2cCfg.socDomain = BOARD_SOC_DOMAIN_MAIN;
399     Board_setI2cInitConfig(&i2cCfg);
401     Board_i2cIoExpInit();
402         Board_i2cIoExpSetPinDirection(BOARD_I2C_IOEXP_DEVICE1_ADDR,
403                                   THREE_PORT_IOEXP,
404                                   PORTNUM_1,
405                                   PIN_NUM_6,
406                                   PIN_DIRECTION_OUTPUT);
408     /* Pulling GPIO_OLED_RESETn pin to high for accessing the INA devices */
409     Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE1_ADDR,
410                               THREE_PORT_IOEXP,
411                               PORTNUM_1,
412                               PIN_NUM_6,
413                               (i2cIoExpSignalLevel_t) GPIO_SIGNAL_LEVEL_HIGH);
415 #else
416         GPIO_init();
417         GPIO_write(0, 1);
418 #endif
420         testStatus = run_oled_display_test();
421         if(testStatus != 0)
422         {
423                 UART_printf("\nOled display Test Failed!\n");
424         }
425         else
426         {
427                 UART_printf("\nOled display Test Passed!\n");
428         }
430         UART_printf("\nOled Tests Completed!!\n");
431         UART_printf("\n-----------------X-----------------\n\n\n");
433 #if defined(SOC_AM64X)
434     Board_i2cIoExpDeInit();
435 #endif
437         return (testStatus);
439 } // oledTest
441 /**
442  * \brief Invokes oled test functions
443  *
444  */
445 int main(void)
447     TEST_STATUS      testStatus;
448     Board_initCfg    boardCfg;
450 #ifdef SOC_K2G
451     DIAG_IntrInit();
452 #endif
454 #ifdef PDK_RAW_BOOT
455     boardCfg = BOARD_INIT_PINMUX_CONFIG |
456         BOARD_INIT_UART_STDIO;
457 #else
458     boardCfg = BOARD_INIT_UART_STDIO;
459 #endif
460     Board_init(boardCfg);
462     /* Invoke oled Test */
463     testStatus = oledTest();
464     if(testStatus != TEST_PASS)
465     {
466         return (-1);
467     }
469     return (0);