본문 바로가기

IT/Tizen

타이젠 + 제어컨트롤러

G Camp 홍보 이미지

 

 

* 1일차 동영상

 

 

* 기존의 '플랫폼 + 제어컨트롤러' 예시

- 자율주행 자동차 : https://comma.ai, 안드로이드 + MCU with 블루투스

사이트 설명 중

 

- 케이블 테스트 머신 : 코드주 제품, 제어부, 통신부 분리

- 초고온 측정 시스템 : 코드주 제품, 안드로이드 + MCU with BUS(?), https://youtu.be/ZlssLOXRJXM

- 스마트 에어모니터 : 코드주 제품, 안드로이드 + MCU with USB

 

 

* Mbed OS(= Arduino) 

- https://mbed.com 

 

Home | Mbed

The Arm® Mbed™ IoT Device Platform provides the operating system, cloud services, tools and developer ecosystem to make the creation and deployment of commercial, standards-based IoT solutions possible at scale.

www.mbed.com

- RTOS 지원

- OS 수준으로 File System 등 지원

- Mbed TLS로 보안 지원

 

* Mbed Web Compiler

https://os.mbed.com/ 가입

 

 

* Mbed CLI : https://os.mbed.com/docs/mbed-os/v5.13/tools/installation-and-setup.html

- 파이썬 버전 충돌로 인해 환경설정이 중첩되는 문제 발생

- 기본 소스

 

 

* NUCLEO-F429ZI

 

 

* Mbed OS Architecture

 

 

* API :  https://os.mbed.com/docs/mbed-os/v5.13/apis/index.html

 

Full API list - APIs | Mbed OS 5 Documentation

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling coo

os.mbed.com

 

 

* YouTube : Mbed Office Hour

 

 

* L9110s : 바퀴 2개 자동차

 

* 2일차 동영상

 

 

* 첫번째 연습 : Mbed <-> Tizen I2C로 연동하기

- Mbed I2C Slave 소스

mbed.c
0.00MB

#include <mbed.h>

#if !DEVICE_I2CSLAVE
  #error [NOT_SUPPORTED] I2C Slave is not supported
#endif

I2CSlave slave(PB_9, PB_8);

int main() {
   char buf[10] = {0,};
   char rbuf[2] = {0,};
   char msg[] = "Slave!";
   char k = 0;
   
   //wait_us(50); // to mbed devices
   wait_us(500); // to RPI3

   printf("mbed-os-example\n\r");

   slave.frequency(100000);//100Khz
   slave.address(0xA0);

   while (1) {
       int i = slave.receive(); // blocking
       switch (i) {
           case I2CSlave::ReadAddressed:
               slave.write(buf, 2); // Includes null char
               buf[0] = k++;
               buf[1] = k++;
               
               if (buf[0] == 0xFF)
                    buf[0] = 0x0;
               if (buf[1] == 0xFF)
                    buf[1] = 0x0;

               break;
           case I2CSlave::WriteGeneral:
               //slave.read(buf, 10);
               //printf("Read G: %s\n", buf);
               break;
           case I2CSlave::WriteAddressed:
               slave.read(rbuf, 1);
               //printf("Read A: %s\n", buf);
               break;
       }
   }
}

 

 

- Tizen I2C Master 소스

  소스 다운로드 : git clone https://git.tizen.org/cgit/apps/native/rcc illuminance -b illuminance 

  위의 소스에서 'resource_illuminance_sensor.c'만 바꿔주세요.

tizen.c
0.00MB

/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
 *
 * Contact: Jin Yoon <jinny.yoon@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdlib.h>
#include <unistd.h>
#include <peripheral_io.h>
#include <sys/time.h>

#include "log.h"
#include "resource_internal.h"

#define I2C_PIN_MAX 28
/* I2C */
#define GY30_ADDR (0xA0>>1) /* MBED Addr */

#define GY30_CONT_HIGH_RES_MODE 0x10 /* Start measurement at 11x resolution. Measurement time is approx 120mx */
#define GY30_CONSTANT_NUM (1.2)

static struct {
	int opened;
	peripheral_i2c_h sensor_h;
} resource_sensor_s;

void resource_close_illuminance_sensor(void)
{
	if (!resource_sensor_s.opened)
		return;

	_I("Illuminance Sensor is finishing...");
	peripheral_i2c_close(resource_sensor_s.sensor_h);
	resource_sensor_s.opened = 0;
}

int resource_read_illuminance_sensor(int i2c_bus, uint32_t *out_value)
{
	int ret = PERIPHERAL_ERROR_NONE;
	static int write = 0;
	static int count = 0;
	unsigned char buf[10] = { 0, };
	unsigned char cbuf[10] = { 0, };

	if (!resource_sensor_s.opened) {
		ret = peripheral_i2c_open(i2c_bus, GY30_ADDR, &resource_sensor_s.sensor_h);
		if (ret != PERIPHERAL_ERROR_NONE) {
			_E("i2c open error : %s", get_error_message(ret));
			return -1;
		}
		resource_sensor_s.opened = 1;
		write = 0;
	}

	cbuf[0] = 0x10;

	if (!write) {
		ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 1);
		if (ret != PERIPHERAL_ERROR_NONE) {
			_E("i2c write error : %s", get_error_message(ret));
			return -1;
		}
		write = 1;
	}

	ret = peripheral_i2c_read(resource_sensor_s.sensor_h, buf, 2);
	if (ret != PERIPHERAL_ERROR_NONE) {
		_E("i2c read error : %s", get_error_message(ret));
		return -1;
	}

	_D("READ : 0x%2X 0x%2X, count : %d", buf[0], buf[1], count++);

	*out_value = (buf[0] << 8 | buf[1]) / GY30_CONSTANT_NUM; // Just Sum High 8bit and Low 8bit

	return 0;
}

 

 

 

* 두번째 연습 : Mbed <-> Tizen I2C + GPIO로 연동하기

- Mbed 소스

mbed.c
0.00MB

#include "mbed.h"

#if !DEVICE_I2CSLAVE
  #error [NOT_SUPPORTED] I2C Slave is not supported
#endif

I2CSlave slave(PB_9, PB_8);
DigitalOut led1(LED1);
InterruptIn mybutton(USER_BUTTON);
DigitalOut _check(PC_6);

void pressed()
{
//    printf("button pressed event!!\r\n");
    _check = 0;
    led1 = !led1;
}


int main() {
   char buf[3];
   char msg[] = "Slave!";

   buf[0] = 0x1A;
   buf[1] = 0xFF;
   
   //wait_us(50);  //to mbed devices
   wait_us(500);   //to RaspberryPi
   
//   printf("hello world\r\n");
   
   slave.frequency(400000);
   slave.address(0xA0);
   _check = 1;
   
   mybutton.fall(&pressed);
   
   while (1) {
//       wait(1.0f);            
              
       int i = slave.receive();
       switch (i) {
           case I2CSlave::ReadAddressed:
               _check = 1; 
//               slave.write(msg, strlen(msg) + 1); // Includes null char
               slave.write(buf, 2);
 //              printf("Write A: %s\r\n",msg);
               _check = 1;
               break;
           case I2CSlave::WriteGeneral:
               slave.read(buf, 10);
//               printf("Read G: %s\n", buf);
               break;
           case I2CSlave::WriteAddressed:
               slave.read(buf, 2);
//               printf("Read A: %s\n", buf);
               _check = 1;
               break;
       }
//       for(int i = 0; i < 10; i++) buf[i] = 0;    // Clear buffer

   }
}

 

- 타이젠 소스

  git clone https://git.tizen.org/cgit/apps/native/st-things-light -b basic-interrupted st-things-light-basic-interrupted

tizen-mbed-final.zip
0.75MB