GR-MANGO sample using mbed-os library from my repository.
sample_programs/sample_15_ceu_lcd_pwm.cpp@0:b4c1e32627f2, 2020-10-12 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Mon Oct 12 02:25:49 2020 +0000
- Revision:
- 0:b4c1e32627f2
replaced mbed-os library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RyoheiHagimoto | 0:b4c1e32627f2 | 1 | /******************************************************************************* |
| RyoheiHagimoto | 0:b4c1e32627f2 | 2 | * DISCLAIMER |
| RyoheiHagimoto | 0:b4c1e32627f2 | 3 | * This software is supplied by Renesas Electronics Corporation and is only |
| RyoheiHagimoto | 0:b4c1e32627f2 | 4 | * intended for use with Renesas products. No other uses are authorized. This |
| RyoheiHagimoto | 0:b4c1e32627f2 | 5 | * software is owned by Renesas Electronics Corporation and is protected under |
| RyoheiHagimoto | 0:b4c1e32627f2 | 6 | * all applicable laws, including copyright laws. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 7 | * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING |
| RyoheiHagimoto | 0:b4c1e32627f2 | 8 | * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT |
| RyoheiHagimoto | 0:b4c1e32627f2 | 9 | * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 10 | * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 11 | * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS |
| RyoheiHagimoto | 0:b4c1e32627f2 | 12 | * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 13 | * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR |
| RyoheiHagimoto | 0:b4c1e32627f2 | 14 | * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 15 | * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 16 | * Renesas reserves the right, without notice, to make changes to this software |
| RyoheiHagimoto | 0:b4c1e32627f2 | 17 | * and to discontinue the availability of this software. By using this software, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 18 | * you agree to the additional terms and conditions found by accessing the |
| RyoheiHagimoto | 0:b4c1e32627f2 | 19 | * following link: |
| RyoheiHagimoto | 0:b4c1e32627f2 | 20 | * http://www.renesas.com/disclaimer |
| RyoheiHagimoto | 0:b4c1e32627f2 | 21 | * |
| RyoheiHagimoto | 0:b4c1e32627f2 | 22 | * Copyright (C) 2019 Renesas Electronics Corporation. All rights reserved. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 23 | *******************************************************************************/ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 24 | #include "sample_select.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 25 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 26 | #if (SAMPLE_PROGRAM_NO == 15) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 27 | // SAMPLE_PROGRAM_NO 15 : CEU, LCD and PWM sample |
| RyoheiHagimoto | 0:b4c1e32627f2 | 28 | // |
| RyoheiHagimoto | 0:b4c1e32627f2 | 29 | // Display camera image on LCD |
| RyoheiHagimoto | 0:b4c1e32627f2 | 30 | // Pressing SW3 changes the LCD backlight. (PWM) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 31 | // |
| RyoheiHagimoto | 0:b4c1e32627f2 | 32 | // Please set the value of "camera-type" in "mbed_app.json" to "CAMERA_MT9V111", "CAMERA_OV7725", "CAMERA_OV5642" or "CAMERA_WIRELESS_CAMERA". |
| RyoheiHagimoto | 0:b4c1e32627f2 | 33 | // |
| RyoheiHagimoto | 0:b4c1e32627f2 | 34 | // "camera-type":{ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 35 | // "help": "Please see EasyAttach_CameraAndLCD/README.md", |
| RyoheiHagimoto | 0:b4c1e32627f2 | 36 | // "value": "CAMERA_XXXXXXXX" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 37 | // }, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 38 | // |
| RyoheiHagimoto | 0:b4c1e32627f2 | 39 | // Please set the value of "lcd-type" in "mbed_app.json" to "TF043HV001A0", "ATM0430D25", "FG040346DSSWBG03" or "RSK_TFT". |
| RyoheiHagimoto | 0:b4c1e32627f2 | 40 | // |
| RyoheiHagimoto | 0:b4c1e32627f2 | 41 | // "lcd-type":{ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 42 | // "help": "Please see EasyAttach_CameraAndLCD/README.md", |
| RyoheiHagimoto | 0:b4c1e32627f2 | 43 | // "value": "RSK_TFT" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 44 | // }, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 45 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 46 | #if defined(TARGET_SEMB1402) || defined(TARGET_RZ_A2M_SBEV) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 47 | #error "LCD is not supported." |
| RyoheiHagimoto | 0:b4c1e32627f2 | 48 | #endif |
| RyoheiHagimoto | 0:b4c1e32627f2 | 49 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 50 | #include "mbed.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 51 | #include "EasyAttach_CameraAndLCD.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 52 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 53 | /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128 |
| RyoheiHagimoto | 0:b4c1e32627f2 | 54 | in accordance with the frame buffer burst transfer mode. */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 55 | #define VIDEO_PIXEL_HW (640) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 56 | #define VIDEO_PIXEL_VW (480) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 57 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 58 | #define DATA_SIZE_PER_PIC (2u) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 59 | #define FRAME_BUFFER_STRIDE (((VIDEO_PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 60 | #define FRAME_BUFFER_HEIGHT (VIDEO_PIXEL_VW) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 61 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 62 | DisplayBase Display; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 63 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 64 | static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(32))); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 65 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 66 | static void Start_Video_Camera(void) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 67 | // Video capture setting (progressive form fixed) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 68 | Display.Video_Write_Setting( |
| RyoheiHagimoto | 0:b4c1e32627f2 | 69 | DisplayBase::VIDEO_INPUT_CHANNEL_0, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 70 | DisplayBase::COL_SYS_NTSC_358, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 71 | (void *)user_frame_buffer0, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 72 | FRAME_BUFFER_STRIDE, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 73 | DisplayBase::VIDEO_FORMAT_YCBCR422, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 74 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 75 | VIDEO_PIXEL_VW, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 76 | VIDEO_PIXEL_HW |
| RyoheiHagimoto | 0:b4c1e32627f2 | 77 | ); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 78 | EasyAttach_CameraStart(Display, DisplayBase::VIDEO_INPUT_CHANNEL_0); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 79 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 80 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 81 | static void Start_LCD_Display(void) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 82 | DisplayBase::rect_t rect; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 83 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 84 | #if (LCD_PIXEL_HEIGHT > VIDEO_PIXEL_VW) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 85 | rect.vs = (LCD_PIXEL_HEIGHT - VIDEO_PIXEL_VW) / 2; // centering |
| RyoheiHagimoto | 0:b4c1e32627f2 | 86 | #else |
| RyoheiHagimoto | 0:b4c1e32627f2 | 87 | rect.vs = 0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 88 | #endif |
| RyoheiHagimoto | 0:b4c1e32627f2 | 89 | rect.vw = VIDEO_PIXEL_VW; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 90 | #if (LCD_PIXEL_WIDTH > VIDEO_PIXEL_HW) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 91 | rect.hs = (LCD_PIXEL_WIDTH - VIDEO_PIXEL_HW) / 2; // centering |
| RyoheiHagimoto | 0:b4c1e32627f2 | 92 | #else |
| RyoheiHagimoto | 0:b4c1e32627f2 | 93 | rect.hs = 0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 94 | #endif |
| RyoheiHagimoto | 0:b4c1e32627f2 | 95 | rect.hw = VIDEO_PIXEL_HW; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 96 | Display.Graphics_Read_Setting( |
| RyoheiHagimoto | 0:b4c1e32627f2 | 97 | DisplayBase::GRAPHICS_LAYER_0, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 98 | (void *)user_frame_buffer0, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 99 | FRAME_BUFFER_STRIDE, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 100 | DisplayBase::GRAPHICS_FORMAT_YCBCR422, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 101 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 102 | &rect |
| RyoheiHagimoto | 0:b4c1e32627f2 | 103 | ); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 104 | Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 105 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 106 | ThisThread::sleep_for(50); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 107 | EasyAttach_LcdBacklight(true); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 108 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 109 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 110 | static void button_fall(void) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 111 | static uint32_t backlight_val = 10; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 112 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 113 | if (backlight_val > 0) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 114 | backlight_val--; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 115 | } else { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 116 | backlight_val = 10; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 117 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 118 | EasyAttach_LcdBacklight((float)(0.1f * backlight_val)); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 119 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 120 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 121 | int main(void) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 122 | EasyAttach_Init(Display); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 123 | Start_LCD_Display(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 124 | Start_Video_Camera(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 125 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 126 | InterruptIn button(USER_BUTTON0); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 127 | button.fall(&button_fall); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 128 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 129 | ThisThread::sleep_for(osWaitForever); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 130 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 131 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 132 | #endif |