Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Thu Oct 11 02:27:46 2018 +0000
Revision:
3:f3764f852aa8
Parent:
0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 /*
kadonotakashi 0:8fdf9a60065b 2 * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
kadonotakashi 0:8fdf9a60065b 3 * SPDX-License-Identifier: Apache-2.0
kadonotakashi 0:8fdf9a60065b 4 *
kadonotakashi 0:8fdf9a60065b 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
kadonotakashi 0:8fdf9a60065b 6 * not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 7 * You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 8 *
kadonotakashi 0:8fdf9a60065b 9 * http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 10 *
kadonotakashi 0:8fdf9a60065b 11 * Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
kadonotakashi 0:8fdf9a60065b 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 14 * See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 15 * limitations under the License.
kadonotakashi 0:8fdf9a60065b 16 */
kadonotakashi 0:8fdf9a60065b 17 #include <stdio.h>
kadonotakashi 0:8fdf9a60065b 18 #include <string.h>
kadonotakashi 0:8fdf9a60065b 19 #include "mbed.h"
kadonotakashi 0:8fdf9a60065b 20 #include "greentea-client/test_env.h"
kadonotakashi 0:8fdf9a60065b 21 #include "unity/unity.h"
kadonotakashi 0:8fdf9a60065b 22 #include "utest/utest.h"
kadonotakashi 0:8fdf9a60065b 23
kadonotakashi 0:8fdf9a60065b 24 #define PAYLOAD_LENGTH 36
kadonotakashi 0:8fdf9a60065b 25
kadonotakashi 0:8fdf9a60065b 26 using namespace utest::v1;
kadonotakashi 0:8fdf9a60065b 27
kadonotakashi 0:8fdf9a60065b 28 // Fill a buffer with a slice of the ASCII alphabet.
kadonotakashi 0:8fdf9a60065b 29 void fill_buffer(char *buffer, unsigned int length, unsigned int index)
kadonotakashi 0:8fdf9a60065b 30 {
kadonotakashi 0:8fdf9a60065b 31 unsigned int start = length * index;
kadonotakashi 0:8fdf9a60065b 32 for (int i = 0; i < length - 1; i++) {
kadonotakashi 0:8fdf9a60065b 33 buffer[i] = 'a' + ((start + i) % 26);
kadonotakashi 0:8fdf9a60065b 34 }
kadonotakashi 0:8fdf9a60065b 35 buffer[length - 1] = '\0';
kadonotakashi 0:8fdf9a60065b 36 }
kadonotakashi 0:8fdf9a60065b 37
kadonotakashi 0:8fdf9a60065b 38 // Echo server (echo payload to host)
kadonotakashi 0:8fdf9a60065b 39 template<int N>
kadonotakashi 0:8fdf9a60065b 40 void test_case_echo_server_x()
kadonotakashi 0:8fdf9a60065b 41 {
kadonotakashi 0:8fdf9a60065b 42 char _key[11] = {};
kadonotakashi 0:8fdf9a60065b 43 char _tx_value[PAYLOAD_LENGTH + 1] = {};
kadonotakashi 0:8fdf9a60065b 44 char _rx_value[PAYLOAD_LENGTH + 1] = {};
kadonotakashi 0:8fdf9a60065b 45 const int echo_count = N;
kadonotakashi 0:8fdf9a60065b 46 const char _echo_count_key_const[] = "echo_count";
kadonotakashi 0:8fdf9a60065b 47 const char _echo_key_const[] = "echo";
kadonotakashi 0:8fdf9a60065b 48 int expected_key = 1;
kadonotakashi 0:8fdf9a60065b 49
kadonotakashi 0:8fdf9a60065b 50 // Send up the echo count
kadonotakashi 0:8fdf9a60065b 51 greentea_send_kv(_echo_count_key_const, echo_count);
kadonotakashi 0:8fdf9a60065b 52 // Handshake with host
kadonotakashi 0:8fdf9a60065b 53 do {
kadonotakashi 0:8fdf9a60065b 54 greentea_parse_kv(_key, _rx_value, sizeof(_key), sizeof(_rx_value));
kadonotakashi 0:8fdf9a60065b 55 // Ensure the key received is "echo_count" and not some old data
kadonotakashi 0:8fdf9a60065b 56 expected_key = strcmp(_echo_count_key_const, _key);
kadonotakashi 0:8fdf9a60065b 57 } while (expected_key);
kadonotakashi 0:8fdf9a60065b 58 TEST_ASSERT_EQUAL_INT(echo_count, atoi(_rx_value));
kadonotakashi 0:8fdf9a60065b 59
kadonotakashi 0:8fdf9a60065b 60 for (int i = 0; i < echo_count; ++i) {
kadonotakashi 0:8fdf9a60065b 61 fill_buffer(_tx_value, PAYLOAD_LENGTH, i);
kadonotakashi 0:8fdf9a60065b 62 greentea_send_kv(_echo_key_const, _tx_value);
kadonotakashi 0:8fdf9a60065b 63 do {
kadonotakashi 0:8fdf9a60065b 64 greentea_parse_kv(_key, _rx_value, sizeof(_key), sizeof(_rx_value));
kadonotakashi 0:8fdf9a60065b 65 // Ensure the key received is "echo" and not some old data
kadonotakashi 0:8fdf9a60065b 66 expected_key = strcmp(_echo_key_const, _key);
kadonotakashi 0:8fdf9a60065b 67 } while (expected_key);
kadonotakashi 0:8fdf9a60065b 68 TEST_ASSERT(strncmp(_tx_value, _rx_value, PAYLOAD_LENGTH) == 0);
kadonotakashi 0:8fdf9a60065b 69 }
kadonotakashi 0:8fdf9a60065b 70 }
kadonotakashi 0:8fdf9a60065b 71
kadonotakashi 0:8fdf9a60065b 72 utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
kadonotakashi 0:8fdf9a60065b 73 {
kadonotakashi 0:8fdf9a60065b 74 greentea_case_failure_abort_handler(source, reason);
kadonotakashi 0:8fdf9a60065b 75 return STATUS_CONTINUE;
kadonotakashi 0:8fdf9a60065b 76 }
kadonotakashi 0:8fdf9a60065b 77
kadonotakashi 0:8fdf9a60065b 78 Case cases[] = {
kadonotakashi 0:8fdf9a60065b 79 Case("Echo server: x16", test_case_echo_server_x<16>, greentea_failure_handler),
kadonotakashi 0:8fdf9a60065b 80 };
kadonotakashi 0:8fdf9a60065b 81
kadonotakashi 0:8fdf9a60065b 82 utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
kadonotakashi 0:8fdf9a60065b 83 {
kadonotakashi 0:8fdf9a60065b 84 GREENTEA_SETUP(30, "device_echo");
kadonotakashi 0:8fdf9a60065b 85 return greentea_test_setup_handler(number_of_cases);
kadonotakashi 0:8fdf9a60065b 86 }
kadonotakashi 0:8fdf9a60065b 87
kadonotakashi 0:8fdf9a60065b 88 Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
kadonotakashi 0:8fdf9a60065b 89
kadonotakashi 0:8fdf9a60065b 90 int main()
kadonotakashi 0:8fdf9a60065b 91 {
kadonotakashi 0:8fdf9a60065b 92 Harness::run(specification);
kadonotakashi 0:8fdf9a60065b 93 }