Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Wed Oct 10 00:33:53 2018 +0000
Revision:
0:8fdf9a60065b
how to make mbed librry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 #!/usr/bin/env python
kadonotakashi 0:8fdf9a60065b 2 """
kadonotakashi 0:8fdf9a60065b 3 mbed
kadonotakashi 0:8fdf9a60065b 4 Copyright (c) 2017-2017 ARM Limited
kadonotakashi 0:8fdf9a60065b 5
kadonotakashi 0:8fdf9a60065b 6 Licensed under the Apache License, Version 2.0 (the "License");
kadonotakashi 0:8fdf9a60065b 7 you may not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 8 You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 9
kadonotakashi 0:8fdf9a60065b 10 http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 11
kadonotakashi 0:8fdf9a60065b 12 Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 13 distributed under the License is distributed on an "AS IS" BASIS,
kadonotakashi 0:8fdf9a60065b 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 15 See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 16 limitations under the License.
kadonotakashi 0:8fdf9a60065b 17 """
kadonotakashi 0:8fdf9a60065b 18 import os
kadonotakashi 0:8fdf9a60065b 19 import sys
kadonotakashi 0:8fdf9a60065b 20 import shutil
kadonotakashi 0:8fdf9a60065b 21 import tempfile
kadonotakashi 0:8fdf9a60065b 22 from os.path import join, abspath, dirname
kadonotakashi 0:8fdf9a60065b 23 from contextlib import contextmanager
kadonotakashi 0:8fdf9a60065b 24 import pytest
kadonotakashi 0:8fdf9a60065b 25
kadonotakashi 0:8fdf9a60065b 26 from tools.targets import TARGETS, TARGET_MAP, Target, update_target_data
kadonotakashi 0:8fdf9a60065b 27 from tools.arm_pack_manager import Cache
kadonotakashi 0:8fdf9a60065b 28
kadonotakashi 0:8fdf9a60065b 29
kadonotakashi 0:8fdf9a60065b 30 def test_device_name():
kadonotakashi 0:8fdf9a60065b 31 """Assert device name is in a pack"""
kadonotakashi 0:8fdf9a60065b 32 cache = Cache(True, True)
kadonotakashi 0:8fdf9a60065b 33 named_targets = (target for target in TARGETS if
kadonotakashi 0:8fdf9a60065b 34 hasattr(target, "device_name"))
kadonotakashi 0:8fdf9a60065b 35 for target in named_targets:
kadonotakashi 0:8fdf9a60065b 36 assert target.device_name in cache.index,\
kadonotakashi 0:8fdf9a60065b 37 ("Target %s contains invalid device_name %s" %
kadonotakashi 0:8fdf9a60065b 38 (target.name, target.device_name))
kadonotakashi 0:8fdf9a60065b 39
kadonotakashi 0:8fdf9a60065b 40 @contextmanager
kadonotakashi 0:8fdf9a60065b 41 def temp_target_file(extra_target, json_filename='custom_targets.json'):
kadonotakashi 0:8fdf9a60065b 42 """Create an extra targets temp file in a context manager
kadonotakashi 0:8fdf9a60065b 43
kadonotakashi 0:8fdf9a60065b 44 :param extra_target: the contents of the extra targets temp file
kadonotakashi 0:8fdf9a60065b 45 """
kadonotakashi 0:8fdf9a60065b 46 tempdir = tempfile.mkdtemp()
kadonotakashi 0:8fdf9a60065b 47 try:
kadonotakashi 0:8fdf9a60065b 48 targetfile = os.path.join(tempdir, json_filename)
kadonotakashi 0:8fdf9a60065b 49 with open(targetfile, 'w') as f:
kadonotakashi 0:8fdf9a60065b 50 f.write(extra_target)
kadonotakashi 0:8fdf9a60065b 51 yield tempdir
kadonotakashi 0:8fdf9a60065b 52 finally:
kadonotakashi 0:8fdf9a60065b 53 # Reset extra targets
kadonotakashi 0:8fdf9a60065b 54 Target.set_targets_json_location()
kadonotakashi 0:8fdf9a60065b 55 # Delete temp files
kadonotakashi 0:8fdf9a60065b 56 shutil.rmtree(tempdir)
kadonotakashi 0:8fdf9a60065b 57
kadonotakashi 0:8fdf9a60065b 58 def test_add_extra_targets():
kadonotakashi 0:8fdf9a60065b 59 """Search for extra targets json in a source folder"""
kadonotakashi 0:8fdf9a60065b 60 test_target_json = """
kadonotakashi 0:8fdf9a60065b 61 {
kadonotakashi 0:8fdf9a60065b 62 "Test_Target": {
kadonotakashi 0:8fdf9a60065b 63 "inherits": ["Target"]
kadonotakashi 0:8fdf9a60065b 64 }
kadonotakashi 0:8fdf9a60065b 65 }
kadonotakashi 0:8fdf9a60065b 66 """
kadonotakashi 0:8fdf9a60065b 67 with temp_target_file(test_target_json) as source_dir:
kadonotakashi 0:8fdf9a60065b 68 Target.add_extra_targets(source_dir=source_dir)
kadonotakashi 0:8fdf9a60065b 69 update_target_data()
kadonotakashi 0:8fdf9a60065b 70
kadonotakashi 0:8fdf9a60065b 71 assert 'Test_Target' in TARGET_MAP
kadonotakashi 0:8fdf9a60065b 72 assert TARGET_MAP['Test_Target'].core is None, \
kadonotakashi 0:8fdf9a60065b 73 "attributes should be inherited from Target"
kadonotakashi 0:8fdf9a60065b 74
kadonotakashi 0:8fdf9a60065b 75 def test_modify_existing_target():
kadonotakashi 0:8fdf9a60065b 76 """Set default targets file, then override base Target definition"""
kadonotakashi 0:8fdf9a60065b 77 initial_target_json = """
kadonotakashi 0:8fdf9a60065b 78 {
kadonotakashi 0:8fdf9a60065b 79 "Target": {
kadonotakashi 0:8fdf9a60065b 80 "core": null,
kadonotakashi 0:8fdf9a60065b 81 "default_toolchain": "ARM",
kadonotakashi 0:8fdf9a60065b 82 "supported_toolchains": null,
kadonotakashi 0:8fdf9a60065b 83 "extra_labels": [],
kadonotakashi 0:8fdf9a60065b 84 "is_disk_virtual": false,
kadonotakashi 0:8fdf9a60065b 85 "macros": [],
kadonotakashi 0:8fdf9a60065b 86 "device_has": [],
kadonotakashi 0:8fdf9a60065b 87 "features": [],
kadonotakashi 0:8fdf9a60065b 88 "detect_code": [],
kadonotakashi 0:8fdf9a60065b 89 "public": false,
kadonotakashi 0:8fdf9a60065b 90 "default_lib": "std",
kadonotakashi 0:8fdf9a60065b 91 "bootloader_supported": false
kadonotakashi 0:8fdf9a60065b 92 },
kadonotakashi 0:8fdf9a60065b 93 "Test_Target": {
kadonotakashi 0:8fdf9a60065b 94 "inherits": ["Target"],
kadonotakashi 0:8fdf9a60065b 95 "core": "Cortex-M4",
kadonotakashi 0:8fdf9a60065b 96 "supported_toolchains": ["ARM"]
kadonotakashi 0:8fdf9a60065b 97 }
kadonotakashi 0:8fdf9a60065b 98 }"""
kadonotakashi 0:8fdf9a60065b 99
kadonotakashi 0:8fdf9a60065b 100 test_target_json = """
kadonotakashi 0:8fdf9a60065b 101 {
kadonotakashi 0:8fdf9a60065b 102 "Target": {
kadonotakashi 0:8fdf9a60065b 103 "core": "Cortex-M0",
kadonotakashi 0:8fdf9a60065b 104 "default_toolchain": "GCC_ARM",
kadonotakashi 0:8fdf9a60065b 105 "supported_toolchains": null,
kadonotakashi 0:8fdf9a60065b 106 "extra_labels": [],
kadonotakashi 0:8fdf9a60065b 107 "is_disk_virtual": false,
kadonotakashi 0:8fdf9a60065b 108 "macros": [],
kadonotakashi 0:8fdf9a60065b 109 "device_has": [],
kadonotakashi 0:8fdf9a60065b 110 "features": [],
kadonotakashi 0:8fdf9a60065b 111 "detect_code": [],
kadonotakashi 0:8fdf9a60065b 112 "public": false,
kadonotakashi 0:8fdf9a60065b 113 "default_lib": "std",
kadonotakashi 0:8fdf9a60065b 114 "bootloader_supported": true
kadonotakashi 0:8fdf9a60065b 115 }
kadonotakashi 0:8fdf9a60065b 116 }
kadonotakashi 0:8fdf9a60065b 117 """
kadonotakashi 0:8fdf9a60065b 118
kadonotakashi 0:8fdf9a60065b 119 with temp_target_file(initial_target_json, json_filename="targets.json") as targets_dir:
kadonotakashi 0:8fdf9a60065b 120 Target.set_targets_json_location(os.path.join(targets_dir, "targets.json"))
kadonotakashi 0:8fdf9a60065b 121 update_target_data()
kadonotakashi 0:8fdf9a60065b 122 assert TARGET_MAP["Test_Target"].core == "Cortex-M4"
kadonotakashi 0:8fdf9a60065b 123 assert TARGET_MAP["Test_Target"].default_toolchain == 'ARM'
kadonotakashi 0:8fdf9a60065b 124 assert TARGET_MAP["Test_Target"].bootloader_supported == False
kadonotakashi 0:8fdf9a60065b 125
kadonotakashi 0:8fdf9a60065b 126 with temp_target_file(test_target_json) as source_dir:
kadonotakashi 0:8fdf9a60065b 127 Target.add_extra_targets(source_dir=source_dir)
kadonotakashi 0:8fdf9a60065b 128 update_target_data()
kadonotakashi 0:8fdf9a60065b 129
kadonotakashi 0:8fdf9a60065b 130 assert TARGET_MAP["Test_Target"].core == "Cortex-M4"
kadonotakashi 0:8fdf9a60065b 131 # The existing target should not be modified by custom targets
kadonotakashi 0:8fdf9a60065b 132 assert TARGET_MAP["Test_Target"].default_toolchain != 'GCC_ARM'
kadonotakashi 0:8fdf9a60065b 133 assert TARGET_MAP["Test_Target"].bootloader_supported != True