5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
jacobjohnson
Date:
Mon Feb 27 17:45:05 2017 +0000
Revision:
1:f30bdcd2b33b
Parent:
0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c.  This will need to be changed later, and accessed from the main level, but for now this allows the  adc to read a value from 0 to 3.7V, instead of just up to 1V.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-onsemi 0:098463de4c5d 1 """
group-onsemi 0:098463de4c5d 2 mbed SDK
group-onsemi 0:098463de4c5d 3 Copyright (c) 2011-2014 ARM Limited
group-onsemi 0:098463de4c5d 4
group-onsemi 0:098463de4c5d 5 Licensed under the Apache License, Version 2.0 (the "License");
group-onsemi 0:098463de4c5d 6 you may not use this file except in compliance with the License.
group-onsemi 0:098463de4c5d 7 You may obtain a copy of the License at
group-onsemi 0:098463de4c5d 8
group-onsemi 0:098463de4c5d 9 http://www.apache.org/licenses/LICENSE-2.0
group-onsemi 0:098463de4c5d 10
group-onsemi 0:098463de4c5d 11 Unless required by applicable law or agreed to in writing, software
group-onsemi 0:098463de4c5d 12 distributed under the License is distributed on an "AS IS" BASIS,
group-onsemi 0:098463de4c5d 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-onsemi 0:098463de4c5d 14 See the License for the specific language governing permissions and
group-onsemi 0:098463de4c5d 15 limitations under the License.
group-onsemi 0:098463de4c5d 16
group-onsemi 0:098463de4c5d 17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
group-onsemi 0:098463de4c5d 18 """
group-onsemi 0:098463de4c5d 19
group-onsemi 0:098463de4c5d 20 import re
group-onsemi 0:098463de4c5d 21 import json
group-onsemi 0:098463de4c5d 22
group-onsemi 0:098463de4c5d 23
group-onsemi 0:098463de4c5d 24 class BaseDBAccess():
group-onsemi 0:098463de4c5d 25 """ Class used to connect with test database and store test results
group-onsemi 0:098463de4c5d 26 """
group-onsemi 0:098463de4c5d 27 def __init__(self):
group-onsemi 0:098463de4c5d 28 self.db_object = None
group-onsemi 0:098463de4c5d 29 self.db_type = None
group-onsemi 0:098463de4c5d 30 # Connection credentials
group-onsemi 0:098463de4c5d 31 self.host = None
group-onsemi 0:098463de4c5d 32 self.user = None
group-onsemi 0:098463de4c5d 33 self.passwd = None
group-onsemi 0:098463de4c5d 34 self.db = None
group-onsemi 0:098463de4c5d 35
group-onsemi 0:098463de4c5d 36 # Test Suite DB scheme (table names)
group-onsemi 0:098463de4c5d 37 self.TABLE_BUILD_ID = 'mtest_build_id'
group-onsemi 0:098463de4c5d 38 self.TABLE_BUILD_ID_STATUS = 'mtest_build_id_status'
group-onsemi 0:098463de4c5d 39 self.TABLE_BUILD_ID_TYPE = 'mtest_build_id_type'
group-onsemi 0:098463de4c5d 40 self.TABLE_TARGET = 'mtest_target'
group-onsemi 0:098463de4c5d 41 self.TABLE_TEST_ENTRY = 'mtest_test_entry'
group-onsemi 0:098463de4c5d 42 self.TABLE_TEST_ID = 'mtest_test_id'
group-onsemi 0:098463de4c5d 43 self.TABLE_TEST_RESULT = 'mtest_test_result'
group-onsemi 0:098463de4c5d 44 self.TABLE_TEST_TYPE = 'mtest_test_type'
group-onsemi 0:098463de4c5d 45 self.TABLE_TOOLCHAIN = 'mtest_toolchain'
group-onsemi 0:098463de4c5d 46 # Build ID status PKs
group-onsemi 0:098463de4c5d 47 self.BUILD_ID_STATUS_STARTED = 1 # Started
group-onsemi 0:098463de4c5d 48 self.BUILD_ID_STATUS_IN_PROGRESS = 2 # In Progress
group-onsemi 0:098463de4c5d 49 self.BUILD_ID_STATUS_COMPLETED = 3 #Completed
group-onsemi 0:098463de4c5d 50 self.BUILD_ID_STATUS_FAILED = 4 # Failed
group-onsemi 0:098463de4c5d 51 # Build ID type PKs
group-onsemi 0:098463de4c5d 52 self.BUILD_ID_TYPE_TEST = 1 # Test
group-onsemi 0:098463de4c5d 53 self.BUILD_ID_TYPE_BUILD_ONLY = 2 # Build Only
group-onsemi 0:098463de4c5d 54
group-onsemi 0:098463de4c5d 55 def get_hostname(self):
group-onsemi 0:098463de4c5d 56 """ Useful when creating build_id in database
group-onsemi 0:098463de4c5d 57 Function returns (hostname, uname) which can be used as (build_id_name, build_id_desc)
group-onsemi 0:098463de4c5d 58 """
group-onsemi 0:098463de4c5d 59 # Get hostname from socket
group-onsemi 0:098463de4c5d 60 import socket
group-onsemi 0:098463de4c5d 61 hostname = socket.gethostbyaddr(socket.gethostname())[0]
group-onsemi 0:098463de4c5d 62 # Get uname from platform resources
group-onsemi 0:098463de4c5d 63 import platform
group-onsemi 0:098463de4c5d 64 uname = json.dumps(platform.uname())
group-onsemi 0:098463de4c5d 65 return (hostname, uname)
group-onsemi 0:098463de4c5d 66
group-onsemi 0:098463de4c5d 67 def get_db_type(self):
group-onsemi 0:098463de4c5d 68 """ Returns database type. E.g. 'mysql', 'sqlLite' etc.
group-onsemi 0:098463de4c5d 69 """
group-onsemi 0:098463de4c5d 70 return self.db_type
group-onsemi 0:098463de4c5d 71
group-onsemi 0:098463de4c5d 72 def detect_database(self, verbose=False):
group-onsemi 0:098463de4c5d 73 """ detect database and return VERION data structure or string (verbose=True)
group-onsemi 0:098463de4c5d 74 """
group-onsemi 0:098463de4c5d 75 return None
group-onsemi 0:098463de4c5d 76
group-onsemi 0:098463de4c5d 77 def parse_db_connection_string(self, str):
group-onsemi 0:098463de4c5d 78 """ Parsing SQL DB connection string. String should contain:
group-onsemi 0:098463de4c5d 79 - DB Name, user name, password, URL (DB host), name
group-onsemi 0:098463de4c5d 80 Function should return tuple with parsed (db_type, username, password, host, db_name) or None if error
group-onsemi 0:098463de4c5d 81
group-onsemi 0:098463de4c5d 82 (db_type, username, password, host, db_name) = self.parse_db_connection_string(db_url)
group-onsemi 0:098463de4c5d 83
group-onsemi 0:098463de4c5d 84 E.g. connection string: 'mysql://username:password@127.0.0.1/db_name'
group-onsemi 0:098463de4c5d 85 """
group-onsemi 0:098463de4c5d 86 result = None
group-onsemi 0:098463de4c5d 87 if type(str) == type(''):
group-onsemi 0:098463de4c5d 88 PATTERN = '^([\w]+)://([\w]+):([\w]*)@(.*)/([\w]+)'
group-onsemi 0:098463de4c5d 89 result = re.match(PATTERN, str)
group-onsemi 0:098463de4c5d 90 if result is not None:
group-onsemi 0:098463de4c5d 91 result = result.groups() # Tuple (db_name, host, user, passwd, db)
group-onsemi 0:098463de4c5d 92 return result # (db_type, username, password, host, db_name)
group-onsemi 0:098463de4c5d 93
group-onsemi 0:098463de4c5d 94 def is_connected(self):
group-onsemi 0:098463de4c5d 95 """ Returns True if we are connected to database
group-onsemi 0:098463de4c5d 96 """
group-onsemi 0:098463de4c5d 97 pass
group-onsemi 0:098463de4c5d 98
group-onsemi 0:098463de4c5d 99 def connect(self, host, user, passwd, db):
group-onsemi 0:098463de4c5d 100 """ Connects to DB and returns DB object
group-onsemi 0:098463de4c5d 101 """
group-onsemi 0:098463de4c5d 102 pass
group-onsemi 0:098463de4c5d 103
group-onsemi 0:098463de4c5d 104 def connect_url(self, db_url):
group-onsemi 0:098463de4c5d 105 """ Connects to database using db_url (database url parsing),
group-onsemi 0:098463de4c5d 106 store host, username, password, db_name
group-onsemi 0:098463de4c5d 107 """
group-onsemi 0:098463de4c5d 108 pass
group-onsemi 0:098463de4c5d 109
group-onsemi 0:098463de4c5d 110 def reconnect(self):
group-onsemi 0:098463de4c5d 111 """ Reconnects to DB and returns DB object using stored host name,
group-onsemi 0:098463de4c5d 112 database name and credentials (user name and password)
group-onsemi 0:098463de4c5d 113 """
group-onsemi 0:098463de4c5d 114 pass
group-onsemi 0:098463de4c5d 115
group-onsemi 0:098463de4c5d 116 def disconnect(self):
group-onsemi 0:098463de4c5d 117 """ Close DB connection
group-onsemi 0:098463de4c5d 118 """
group-onsemi 0:098463de4c5d 119 pass
group-onsemi 0:098463de4c5d 120
group-onsemi 0:098463de4c5d 121 def escape_string(self, str):
group-onsemi 0:098463de4c5d 122 """ Escapes string so it can be put in SQL query between quotes
group-onsemi 0:098463de4c5d 123 """
group-onsemi 0:098463de4c5d 124 pass
group-onsemi 0:098463de4c5d 125
group-onsemi 0:098463de4c5d 126 def select_all(self, query):
group-onsemi 0:098463de4c5d 127 """ Execute SELECT query and get all results
group-onsemi 0:098463de4c5d 128 """
group-onsemi 0:098463de4c5d 129 pass
group-onsemi 0:098463de4c5d 130
group-onsemi 0:098463de4c5d 131 def insert(self, query, commit=True):
group-onsemi 0:098463de4c5d 132 """ Execute INSERT query, define if you want to commit
group-onsemi 0:098463de4c5d 133 """
group-onsemi 0:098463de4c5d 134 pass
group-onsemi 0:098463de4c5d 135
group-onsemi 0:098463de4c5d 136 def get_next_build_id(self, name, desc='', location='', type=None, status=None):
group-onsemi 0:098463de4c5d 137 """ Insert new build_id (DB unique build like ID number to send all test results)
group-onsemi 0:098463de4c5d 138 """
group-onsemi 0:098463de4c5d 139 pass
group-onsemi 0:098463de4c5d 140
group-onsemi 0:098463de4c5d 141 def get_table_entry_pk(self, table, column, value, update_db=True):
group-onsemi 0:098463de4c5d 142 """ Checks for entries in tables with two columns (<TABLE_NAME>_pk, <column>)
group-onsemi 0:098463de4c5d 143 If update_db is True updates table entry if value in specified column doesn't exist
group-onsemi 0:098463de4c5d 144 """
group-onsemi 0:098463de4c5d 145 pass
group-onsemi 0:098463de4c5d 146
group-onsemi 0:098463de4c5d 147 def update_table_entry(self, table, column, value):
group-onsemi 0:098463de4c5d 148 """ Updates table entry if value in specified column doesn't exist
group-onsemi 0:098463de4c5d 149 Locks table to perform atomic read + update
group-onsemi 0:098463de4c5d 150 """
group-onsemi 0:098463de4c5d 151 pass
group-onsemi 0:098463de4c5d 152
group-onsemi 0:098463de4c5d 153 def update_build_id_info(self, build_id, **kw):
group-onsemi 0:098463de4c5d 154 """ Update additional data inside build_id table
group-onsemi 0:098463de4c5d 155 Examples:
group-onsemi 0:098463de4c5d 156 db.update_build_is(build_id, _status_fk=self.BUILD_ID_STATUS_COMPLETED, _shuffle_seed=0.0123456789):
group-onsemi 0:098463de4c5d 157 """
group-onsemi 0:098463de4c5d 158 pass
group-onsemi 0:098463de4c5d 159
group-onsemi 0:098463de4c5d 160 def insert_test_entry(self, build_id, target, toolchain, test_type, test_id, test_result, test_time, test_timeout, test_loop, test_extra=''):
group-onsemi 0:098463de4c5d 161 """ Inserts test result entry to database. All checks regarding existing
group-onsemi 0:098463de4c5d 162 toolchain names in DB are performed.
group-onsemi 0:098463de4c5d 163 If some data is missing DB will be updated
group-onsemi 0:098463de4c5d 164 """
group-onsemi 0:098463de4c5d 165 pass