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 /*
kadonotakashi 0:8fdf9a60065b 2 * Copyright (c) , Arm Limited and affiliates.
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");
kadonotakashi 0:8fdf9a60065b 6 * you may 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,
kadonotakashi 0:8fdf9a60065b 13 * WITHOUT 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
kadonotakashi 0:8fdf9a60065b 18 #include <ctype.h>
kadonotakashi 0:8fdf9a60065b 19 #include "nsapi_types.h"
kadonotakashi 0:8fdf9a60065b 20 #include "ATHandler.h"
kadonotakashi 0:8fdf9a60065b 21 #include "EventQueue.h"
kadonotakashi 0:8fdf9a60065b 22 #include "ATHandler_stub.h"
kadonotakashi 0:8fdf9a60065b 23
kadonotakashi 0:8fdf9a60065b 24 using namespace mbed;
kadonotakashi 0:8fdf9a60065b 25 using namespace events;
kadonotakashi 0:8fdf9a60065b 26
kadonotakashi 0:8fdf9a60065b 27 #include "CellularLog.h"
kadonotakashi 0:8fdf9a60065b 28
kadonotakashi 0:8fdf9a60065b 29 const int DEFAULT_AT_TIMEOUT = 1000; // at default timeout in milliseconds
kadonotakashi 0:8fdf9a60065b 30
kadonotakashi 0:8fdf9a60065b 31 nsapi_error_t ATHandler_stub::nsapi_error_value = 0;
kadonotakashi 0:8fdf9a60065b 32 uint8_t ATHandler_stub::nsapi_error_ok_counter = 0;
kadonotakashi 0:8fdf9a60065b 33 int ATHandler_stub::int_value = -1;
kadonotakashi 0:8fdf9a60065b 34 int ATHandler_stub::ref_count = 0;
kadonotakashi 0:8fdf9a60065b 35 int ATHandler_stub::timeout = 0;
kadonotakashi 0:8fdf9a60065b 36 bool ATHandler_stub::default_timeout = 0;
kadonotakashi 0:8fdf9a60065b 37 bool ATHandler_stub::debug_on = 0;
kadonotakashi 0:8fdf9a60065b 38 ssize_t ATHandler_stub::ssize_value = 0;
kadonotakashi 0:8fdf9a60065b 39 const char *ATHandler_stub::read_string_value = NULL;
kadonotakashi 0:8fdf9a60065b 40 size_t ATHandler_stub::size_value = 0;
kadonotakashi 0:8fdf9a60065b 41 size_t ATHandler_stub::return_given_size = false;
kadonotakashi 0:8fdf9a60065b 42 bool ATHandler_stub::bool_value = false;
kadonotakashi 0:8fdf9a60065b 43 uint8_t ATHandler_stub::uint8_value = 0;
kadonotakashi 0:8fdf9a60065b 44 FileHandle_stub *ATHandler_stub::fh_value = NULL;
kadonotakashi 0:8fdf9a60065b 45 device_err_t ATHandler_stub::device_err_value;
kadonotakashi 0:8fdf9a60065b 46 Callback<void()> ATHandler_stub::callback = NULL;
kadonotakashi 0:8fdf9a60065b 47 bool ATHandler_stub::call_immediately = false;
kadonotakashi 0:8fdf9a60065b 48 uint8_t ATHandler_stub::resp_info_true_counter = false;
kadonotakashi 0:8fdf9a60065b 49 uint8_t ATHandler_stub::info_elem_true_counter = false;
kadonotakashi 0:8fdf9a60065b 50 int ATHandler_stub::int_valid_count_table[kRead_int_table_size];
kadonotakashi 0:8fdf9a60065b 51 int ATHandler_stub::int_count = kRead_int_table_size;
kadonotakashi 0:8fdf9a60065b 52
kadonotakashi 0:8fdf9a60065b 53 int ATHandler_stub::read_string_index = kRead_string_table_size;
kadonotakashi 0:8fdf9a60065b 54 const char *ATHandler_stub::read_string_table[kRead_string_table_size];
kadonotakashi 0:8fdf9a60065b 55 int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
kadonotakashi 0:8fdf9a60065b 56
kadonotakashi 0:8fdf9a60065b 57 ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) :
kadonotakashi 0:8fdf9a60065b 58 _nextATHandler(0),
kadonotakashi 0:8fdf9a60065b 59 _fileHandle(fh),
kadonotakashi 0:8fdf9a60065b 60 _queue(queue)
kadonotakashi 0:8fdf9a60065b 61 {
kadonotakashi 0:8fdf9a60065b 62 ATHandler_stub::ref_count = 1;
kadonotakashi 0:8fdf9a60065b 63 }
kadonotakashi 0:8fdf9a60065b 64
kadonotakashi 0:8fdf9a60065b 65 void ATHandler::set_debug(bool debug_on)
kadonotakashi 0:8fdf9a60065b 66 {
kadonotakashi 0:8fdf9a60065b 67 ATHandler_stub::debug_on = debug_on;
kadonotakashi 0:8fdf9a60065b 68 }
kadonotakashi 0:8fdf9a60065b 69
kadonotakashi 0:8fdf9a60065b 70 ATHandler::~ATHandler()
kadonotakashi 0:8fdf9a60065b 71 {
kadonotakashi 0:8fdf9a60065b 72 ATHandler_stub::ref_count = kATHandler_destructor_ref_ount;
kadonotakashi 0:8fdf9a60065b 73 }
kadonotakashi 0:8fdf9a60065b 74
kadonotakashi 0:8fdf9a60065b 75 void ATHandler::inc_ref_count()
kadonotakashi 0:8fdf9a60065b 76 {
kadonotakashi 0:8fdf9a60065b 77 ATHandler_stub::ref_count++;
kadonotakashi 0:8fdf9a60065b 78 }
kadonotakashi 0:8fdf9a60065b 79
kadonotakashi 0:8fdf9a60065b 80 void ATHandler::dec_ref_count()
kadonotakashi 0:8fdf9a60065b 81 {
kadonotakashi 0:8fdf9a60065b 82 ATHandler_stub::ref_count--;
kadonotakashi 0:8fdf9a60065b 83 }
kadonotakashi 0:8fdf9a60065b 84
kadonotakashi 0:8fdf9a60065b 85 int ATHandler::get_ref_count()
kadonotakashi 0:8fdf9a60065b 86 {
kadonotakashi 0:8fdf9a60065b 87 return ATHandler_stub::ref_count;
kadonotakashi 0:8fdf9a60065b 88 }
kadonotakashi 0:8fdf9a60065b 89
kadonotakashi 0:8fdf9a60065b 90 FileHandle *ATHandler::get_file_handle()
kadonotakashi 0:8fdf9a60065b 91 {
kadonotakashi 0:8fdf9a60065b 92 return ATHandler_stub::fh_value;
kadonotakashi 0:8fdf9a60065b 93 }
kadonotakashi 0:8fdf9a60065b 94
kadonotakashi 0:8fdf9a60065b 95 void ATHandler::set_file_handle(FileHandle *fh)
kadonotakashi 0:8fdf9a60065b 96 {
kadonotakashi 0:8fdf9a60065b 97 }
kadonotakashi 0:8fdf9a60065b 98
kadonotakashi 0:8fdf9a60065b 99 nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
kadonotakashi 0:8fdf9a60065b 100 {
kadonotakashi 0:8fdf9a60065b 101 ATHandler_stub::callback = cb;
kadonotakashi 0:8fdf9a60065b 102 if (ATHandler_stub::call_immediately) {
kadonotakashi 0:8fdf9a60065b 103 cb();
kadonotakashi 0:8fdf9a60065b 104 }
kadonotakashi 0:8fdf9a60065b 105 return ATHandler_stub::nsapi_error_value;
kadonotakashi 0:8fdf9a60065b 106 }
kadonotakashi 0:8fdf9a60065b 107
kadonotakashi 0:8fdf9a60065b 108 void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> callback)
kadonotakashi 0:8fdf9a60065b 109 {
kadonotakashi 0:8fdf9a60065b 110 }
kadonotakashi 0:8fdf9a60065b 111
kadonotakashi 0:8fdf9a60065b 112 nsapi_error_t ATHandler::get_last_error() const
kadonotakashi 0:8fdf9a60065b 113 {
kadonotakashi 0:8fdf9a60065b 114 if (ATHandler_stub::nsapi_error_ok_counter) {
kadonotakashi 0:8fdf9a60065b 115 ATHandler_stub::nsapi_error_ok_counter--;
kadonotakashi 0:8fdf9a60065b 116 return NSAPI_ERROR_OK;
kadonotakashi 0:8fdf9a60065b 117 }
kadonotakashi 0:8fdf9a60065b 118 return ATHandler_stub::nsapi_error_value;
kadonotakashi 0:8fdf9a60065b 119 }
kadonotakashi 0:8fdf9a60065b 120
kadonotakashi 0:8fdf9a60065b 121 void ATHandler::lock()
kadonotakashi 0:8fdf9a60065b 122 {
kadonotakashi 0:8fdf9a60065b 123 }
kadonotakashi 0:8fdf9a60065b 124
kadonotakashi 0:8fdf9a60065b 125 void ATHandler::unlock()
kadonotakashi 0:8fdf9a60065b 126 {
kadonotakashi 0:8fdf9a60065b 127 }
kadonotakashi 0:8fdf9a60065b 128
kadonotakashi 0:8fdf9a60065b 129 nsapi_error_t ATHandler::unlock_return_error()
kadonotakashi 0:8fdf9a60065b 130 {
kadonotakashi 0:8fdf9a60065b 131 return ATHandler_stub::nsapi_error_value;
kadonotakashi 0:8fdf9a60065b 132 }
kadonotakashi 0:8fdf9a60065b 133
kadonotakashi 0:8fdf9a60065b 134 void ATHandler::set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout)
kadonotakashi 0:8fdf9a60065b 135 {
kadonotakashi 0:8fdf9a60065b 136 ATHandler_stub::timeout = timeout_milliseconds;
kadonotakashi 0:8fdf9a60065b 137 ATHandler_stub::default_timeout = default_timeout;
kadonotakashi 0:8fdf9a60065b 138 }
kadonotakashi 0:8fdf9a60065b 139
kadonotakashi 0:8fdf9a60065b 140 void ATHandler::restore_at_timeout()
kadonotakashi 0:8fdf9a60065b 141 {
kadonotakashi 0:8fdf9a60065b 142 }
kadonotakashi 0:8fdf9a60065b 143
kadonotakashi 0:8fdf9a60065b 144 void ATHandler::process_oob()
kadonotakashi 0:8fdf9a60065b 145 {
kadonotakashi 0:8fdf9a60065b 146 }
kadonotakashi 0:8fdf9a60065b 147
kadonotakashi 0:8fdf9a60065b 148 void ATHandler::clear_error()
kadonotakashi 0:8fdf9a60065b 149 {
kadonotakashi 0:8fdf9a60065b 150 ATHandler_stub::nsapi_error_ok_counter++;
kadonotakashi 0:8fdf9a60065b 151 }
kadonotakashi 0:8fdf9a60065b 152
kadonotakashi 0:8fdf9a60065b 153 void ATHandler::skip_param(uint32_t count)
kadonotakashi 0:8fdf9a60065b 154 {
kadonotakashi 0:8fdf9a60065b 155
kadonotakashi 0:8fdf9a60065b 156 }
kadonotakashi 0:8fdf9a60065b 157
kadonotakashi 0:8fdf9a60065b 158 void ATHandler::skip_param(ssize_t len, uint32_t count)
kadonotakashi 0:8fdf9a60065b 159 {
kadonotakashi 0:8fdf9a60065b 160 }
kadonotakashi 0:8fdf9a60065b 161
kadonotakashi 0:8fdf9a60065b 162 ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
kadonotakashi 0:8fdf9a60065b 163 {
kadonotakashi 0:8fdf9a60065b 164 return ATHandler_stub::ssize_value;
kadonotakashi 0:8fdf9a60065b 165 }
kadonotakashi 0:8fdf9a60065b 166
kadonotakashi 0:8fdf9a60065b 167 ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
kadonotakashi 0:8fdf9a60065b 168 {
kadonotakashi 0:8fdf9a60065b 169
kadonotakashi 0:8fdf9a60065b 170 if (ATHandler_stub::read_string_index == kRead_string_table_size) {
kadonotakashi 0:8fdf9a60065b 171 if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) {
kadonotakashi 0:8fdf9a60065b 172 memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value + 1);
kadonotakashi 0:8fdf9a60065b 173 }
kadonotakashi 0:8fdf9a60065b 174 return ATHandler_stub::ssize_value;
kadonotakashi 0:8fdf9a60065b 175 }
kadonotakashi 0:8fdf9a60065b 176
kadonotakashi 0:8fdf9a60065b 177 ATHandler_stub::read_string_index--;
kadonotakashi 0:8fdf9a60065b 178 if (ATHandler_stub::read_string_index >= 0) {
kadonotakashi 0:8fdf9a60065b 179 const char *tmp = ATHandler_stub::read_string_table[ATHandler_stub::read_string_index];
kadonotakashi 0:8fdf9a60065b 180 ssize_t len = strlen(tmp);
kadonotakashi 0:8fdf9a60065b 181 memcpy(buf, tmp, len + 1);
kadonotakashi 0:8fdf9a60065b 182 return len;
kadonotakashi 0:8fdf9a60065b 183 }
kadonotakashi 0:8fdf9a60065b 184
kadonotakashi 0:8fdf9a60065b 185 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
kadonotakashi 0:8fdf9a60065b 186 return -1;
kadonotakashi 0:8fdf9a60065b 187 }
kadonotakashi 0:8fdf9a60065b 188
kadonotakashi 0:8fdf9a60065b 189 int32_t ATHandler::read_int()
kadonotakashi 0:8fdf9a60065b 190 {
kadonotakashi 0:8fdf9a60065b 191 if (ATHandler_stub::nsapi_error_value != NSAPI_ERROR_OK) {
kadonotakashi 0:8fdf9a60065b 192 return -1;
kadonotakashi 0:8fdf9a60065b 193 }
kadonotakashi 0:8fdf9a60065b 194
kadonotakashi 0:8fdf9a60065b 195 if (ATHandler_stub::int_count == kRead_int_table_size) {
kadonotakashi 0:8fdf9a60065b 196 return ATHandler_stub::int_value;
kadonotakashi 0:8fdf9a60065b 197 }
kadonotakashi 0:8fdf9a60065b 198
kadonotakashi 0:8fdf9a60065b 199 //printf("ATHandler_stub::int_count: %d", ATHandler_stub::int_count);
kadonotakashi 0:8fdf9a60065b 200 ATHandler_stub::int_count--;
kadonotakashi 0:8fdf9a60065b 201 if (ATHandler_stub::int_count < kRead_int_table_size && ATHandler_stub::int_count >= 0) {
kadonotakashi 0:8fdf9a60065b 202 return ATHandler_stub::int_valid_count_table[ATHandler_stub::int_count];
kadonotakashi 0:8fdf9a60065b 203 }
kadonotakashi 0:8fdf9a60065b 204
kadonotakashi 0:8fdf9a60065b 205 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
kadonotakashi 0:8fdf9a60065b 206 return -1;
kadonotakashi 0:8fdf9a60065b 207 }
kadonotakashi 0:8fdf9a60065b 208
kadonotakashi 0:8fdf9a60065b 209 void ATHandler::set_delimiter(char delimiter)
kadonotakashi 0:8fdf9a60065b 210 {
kadonotakashi 0:8fdf9a60065b 211 }
kadonotakashi 0:8fdf9a60065b 212
kadonotakashi 0:8fdf9a60065b 213 void ATHandler::set_default_delimiter()
kadonotakashi 0:8fdf9a60065b 214 {
kadonotakashi 0:8fdf9a60065b 215 }
kadonotakashi 0:8fdf9a60065b 216
kadonotakashi 0:8fdf9a60065b 217 void ATHandler::set_stop_tag(const char *stop_tag_seq)
kadonotakashi 0:8fdf9a60065b 218 {
kadonotakashi 0:8fdf9a60065b 219 }
kadonotakashi 0:8fdf9a60065b 220
kadonotakashi 0:8fdf9a60065b 221 int ATHandler::get_3gpp_error()
kadonotakashi 0:8fdf9a60065b 222 {
kadonotakashi 0:8fdf9a60065b 223 return ATHandler_stub::int_value;
kadonotakashi 0:8fdf9a60065b 224 }
kadonotakashi 0:8fdf9a60065b 225
kadonotakashi 0:8fdf9a60065b 226 void ATHandler::resp_start(const char *prefix, bool stop)
kadonotakashi 0:8fdf9a60065b 227 {
kadonotakashi 0:8fdf9a60065b 228 }
kadonotakashi 0:8fdf9a60065b 229
kadonotakashi 0:8fdf9a60065b 230 bool ATHandler::info_resp()
kadonotakashi 0:8fdf9a60065b 231 {
kadonotakashi 0:8fdf9a60065b 232 if (ATHandler_stub::resp_info_true_counter) {
kadonotakashi 0:8fdf9a60065b 233 ATHandler_stub::resp_info_true_counter--;
kadonotakashi 0:8fdf9a60065b 234 return true;
kadonotakashi 0:8fdf9a60065b 235 }
kadonotakashi 0:8fdf9a60065b 236 return ATHandler_stub::bool_value;
kadonotakashi 0:8fdf9a60065b 237 }
kadonotakashi 0:8fdf9a60065b 238
kadonotakashi 0:8fdf9a60065b 239 bool ATHandler::info_elem(char start_tag)
kadonotakashi 0:8fdf9a60065b 240 {
kadonotakashi 0:8fdf9a60065b 241 if (ATHandler_stub::info_elem_true_counter) {
kadonotakashi 0:8fdf9a60065b 242 ATHandler_stub::info_elem_true_counter--;
kadonotakashi 0:8fdf9a60065b 243 return true;
kadonotakashi 0:8fdf9a60065b 244 }
kadonotakashi 0:8fdf9a60065b 245 return ATHandler_stub::bool_value;
kadonotakashi 0:8fdf9a60065b 246 }
kadonotakashi 0:8fdf9a60065b 247
kadonotakashi 0:8fdf9a60065b 248 bool ATHandler::consume_to_stop_tag()
kadonotakashi 0:8fdf9a60065b 249 {
kadonotakashi 0:8fdf9a60065b 250 return ATHandler_stub::bool_value;
kadonotakashi 0:8fdf9a60065b 251 }
kadonotakashi 0:8fdf9a60065b 252
kadonotakashi 0:8fdf9a60065b 253 void ATHandler::resp_stop()
kadonotakashi 0:8fdf9a60065b 254 {
kadonotakashi 0:8fdf9a60065b 255 if (ATHandler_stub::resp_stop_success_count > 0) {
kadonotakashi 0:8fdf9a60065b 256 ATHandler_stub::resp_stop_success_count--;
kadonotakashi 0:8fdf9a60065b 257 return;
kadonotakashi 0:8fdf9a60065b 258 }
kadonotakashi 0:8fdf9a60065b 259 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
kadonotakashi 0:8fdf9a60065b 260 }
kadonotakashi 0:8fdf9a60065b 261
kadonotakashi 0:8fdf9a60065b 262 void ATHandler::cmd_start(const char *cmd)
kadonotakashi 0:8fdf9a60065b 263 {
kadonotakashi 0:8fdf9a60065b 264 }
kadonotakashi 0:8fdf9a60065b 265
kadonotakashi 0:8fdf9a60065b 266 void ATHandler::write_int(int32_t param)
kadonotakashi 0:8fdf9a60065b 267 {
kadonotakashi 0:8fdf9a60065b 268 }
kadonotakashi 0:8fdf9a60065b 269
kadonotakashi 0:8fdf9a60065b 270 void ATHandler::write_string(const char *param, bool useQuotations)
kadonotakashi 0:8fdf9a60065b 271 {
kadonotakashi 0:8fdf9a60065b 272 }
kadonotakashi 0:8fdf9a60065b 273
kadonotakashi 0:8fdf9a60065b 274 size_t ATHandler::write_bytes(const uint8_t *param, size_t len)
kadonotakashi 0:8fdf9a60065b 275 {
kadonotakashi 0:8fdf9a60065b 276 if (ATHandler_stub::return_given_size) {
kadonotakashi 0:8fdf9a60065b 277 return len;
kadonotakashi 0:8fdf9a60065b 278 }
kadonotakashi 0:8fdf9a60065b 279 return ATHandler_stub::size_value;
kadonotakashi 0:8fdf9a60065b 280 }
kadonotakashi 0:8fdf9a60065b 281
kadonotakashi 0:8fdf9a60065b 282 void ATHandler::cmd_stop()
kadonotakashi 0:8fdf9a60065b 283 {
kadonotakashi 0:8fdf9a60065b 284 }
kadonotakashi 0:8fdf9a60065b 285
kadonotakashi 0:8fdf9a60065b 286 device_err_t ATHandler::get_last_device_error() const
kadonotakashi 0:8fdf9a60065b 287 {
kadonotakashi 0:8fdf9a60065b 288 return ATHandler_stub::device_err_value;
kadonotakashi 0:8fdf9a60065b 289 }
kadonotakashi 0:8fdf9a60065b 290
kadonotakashi 0:8fdf9a60065b 291 void ATHandler::flush()
kadonotakashi 0:8fdf9a60065b 292 {
kadonotakashi 0:8fdf9a60065b 293
kadonotakashi 0:8fdf9a60065b 294 }