Skip to content
Snippets Groups Projects
Commit e5f9af23 authored by Michael DM Dryden's avatar Michael DM Dryden
Browse files

Move TWI init into separate function.

parent fe46342e
Branches
Tags
No related merge requests found
//
// dstat_config.h
// dstat-firmware
//
// Created by Michael Dryden on 2017-02-19.
// Copyright © 2017 Michael Dryden. All rights reserved.
//
#ifndef dstat_config_h
#define dstat_config_h
#include <ioport.h>
#define EXT_TWI0 TWIC
#define EXT_TWI0_SDA IOPORT_CREATE_PIN(PORTC,0)
#define EXT_TWI0_SCL IOPORT_CREATE_PIN(PORTC,1)
#define EXT_TWI0_MASTER_ADDR 0x42
#define EXT_TWI0_SPEED 100000
#endif /* dstat_config_h */
//
// ext_twi.c
// dstat-firmware
//
// Created by Michael Dryden on 2017-02-19.
// Copyright © 2017 Michael Dryden. All rights reserved.
//
#include "ext_twi.h"
#include "config/dstat_config.h"
#include <ioport.h>
#include <sysclk.h>
#include <twi_common.h>
#include <twi_master.h>
void ext_twi_init(void){
ioport_set_pin_mode(EXT_TWI0_SDA, IOPORT_MODE_WIREDANDPULL);
ioport_set_pin_mode(EXT_TWI0_SCL, IOPORT_MODE_WIREDANDPULL);
sysclk_enable_peripheral_clock(&EXT_TWI0);
twi_master_enable(&EXT_TWI0);
twi_master_options_t opt = {
.speed = EXT_TWI0_SPEED,
.chip = EXT_TWI0_MASTER_ADDR
};
twi_master_setup(&EXT_TWI0, &opt);
printf("#INFO: TWI master enabled\n\r");
}
//
// ext_twi.h
// dstat-firmware
//
// Created by Michael Dryden on 2017-02-19.
// Copyright © 2017 Michael Dryden. All rights reserved.
//
#ifndef ext_twi_h
#define ext_twi_h
#include <stdio.h>
#include "config/dstat_config.h"
void ext_twi_init(void);
#endif /* ext_twi_h */
......@@ -14,6 +14,7 @@
#include <math.h>
#include <stdint.h>
#include "conf_board.h"
#include "ext_twi.h"
//Internal function declarations
int8_t command_handler(char command);
......@@ -109,6 +110,7 @@ int main(void){
settings_read_eeprom();
ext_twi_init();
tcs_init();
shutter_init();
......
......@@ -11,6 +11,9 @@
#include <twi_common.h>
#include <ioport.h>
#include <sysclk.h>
#include "dstat_config.h"
#define TCS_TWI EXT_TWI0
#define SLAVE_ADDR 0x29
#define TCS_EN 0x00
......@@ -19,28 +22,7 @@
#define TCS_INTERRUPT 0b10000010
#define TCS_CTRL 0x0F
static void tcs_on(void);
static uint8_t _tcs_active = 0;
void tcs_init(void){
ioport_set_port_mode(IOPORT_PORTC, PIN0_bm|PIN1_bm, IOPORT_MODE_WIREDANDPULL);
twi_master_options_t opt = {
.speed = 50000,
.chip = 0x42,
};
sysclk_enable_peripheral_clock(&TCS_TWI);
twi_master_setup(&TCS_TWI, &opt);
twi_master_enable(&TCS_TWI);
printf("#INFO: TWI master enabled\n\r");
tcs_on();
}
static void tcs_on(void){
twi_package_t twi_pack;
uint8_t data_buffer = 0b00000011;
......@@ -86,4 +68,4 @@ void tcs_readvalues(uint16_t data[4]){
data[3] = data_buffer.uint16[3];
return;
}
\ No newline at end of file
}
......@@ -10,9 +10,6 @@
#define tcs_h
#include <stdio.h>
//#include <stdbool.h>
#define TCS_TWI TWIC
void tcs_init(void);
void tcs_readvalues(uint16_t data[4]);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment