-/*
- * File: akc6955.h
- * Author: whatisthis
+/*
+ * OpenI2CRADIO
+ * RADIO CHIP AKC6955 Handler(Header)
+ * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2+LE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ * This library / program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
*
- * Created on 2013/06/11, 10:24
+ * You should have received a copy of the GNU General Public License
+ * along with this library; see the file COPYING. If not, write to the
+ * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * As a special exception, if you link this(includeed from sdcc) library
+ * with other files, some of which are compiled with SDCC,
+ * to produce an executable, this library does not by itself cause
+ * the resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why
+ * the executable file might be covered by the GNU General Public License.
*/
#ifndef AKC6955_H
#define AKC6955_H
+#include "i2c_io.h"
+
#ifdef __cplusplus
extern "C" {
#endif
#define AKC6955_CH_HI 2
#define AKC6955_CH_LO 3
#define AKC6955_UCH_ST 4
-#define AKC6955_UCS_EN 5
+#define AKC6955_UCH_EN 5
#define AKC6955_VOLUME 6
#define AKC6955_STEREO 7
#define AKC6955_THRESH 8
#define AKC6955_ENABLE 9
-// 10 = RESERVE
+#define AKC6955_FM_SEEKSTEP 10
#define AKC6955_SPACE 11
-// 12 = RESERVE
+#define AKC6955_ADCEN 12
#define AKC6955_PRE 13
// 14-19 = RESERVE
#define AKC6955_RSSI 27
/*
- * Resister definitions
+ * BAND DEFINES
*/
- typedef union{
- unsigned char byte;
- struct {
- unsigned power_on :1;
- unsigned fm_en :1;
- unsigned tune :1;
- unsigned seek :1;
- unsigned seekdir :1;
- unsigned mute :1;
- unsigned reserve :2;
- };
- } AKC6955_Reg0;
+
+ enum {
+ AKC6955_BAND_LW = 0, // 150~285KHz, 3KHz order
+ AKC6955_BAND_MW1, // 520~1710KHz, 5KHz order
+ AKC6955_BAND_MW2, // 522~1620KHz, 9KHz order
+ AKC6955_BAND_MW3, // 520~1710KHz, 10KHz order
+
+ AKC6955_BAND_SW1, // 4700~10000KHz, 5KHz order
+ AKC6955_BAND_SW2, // 3200~4100KHz, 5KHz order
+ AKC6955_BAND_SW3, // 4700~5600KHz, 5KHz order
+ AKC6955_BAND_SW4, // 5700~6400KHz, 5KHz order
+
+ AKC6955_BAND_SW5, // 6800~7600KHz, 5KHz order
+ AKC6955_BAND_SW6, // 9200~10000KHz, 5KHz order
+ AKC6955_BAND_SW7, // 11400~12200KHz, 5KHz order
+ AKC6955_BAND_SW8, // 13500~14300KHz, 5KHz order
+
+ AKC6955_BAND_SW9, // 15000~15900KHz, 5KHz order
+ AKC6955_BAND_SW10, // 17400~17900KHz, 5KHz order
+ AKC6955_BAND_SW11, // 18900~19700KHz, 5KHz order
+ AKC6955_BAND_SW12, // 21400~21900KHz, 5KHz order
+
+ AKC6955_BAND_SW13, // 11400~17900KHz, 5KHz order
+ AKC6955_BAND_AMUSER, // User Setting
+ AKC6955_BAND_MW4, // 520~1730KHz, 5KHz order
+ AKC6955_BAND_AMEND
+ };
+
+
+ enum {
+ AKC6955_BAND_FM1 = 0, // 87.0~108.0MHz
+ AKC6955_BAND_FM2, // 76.0~108.0MHz
+ AKC6955_BAND_FM3, // 70.0~93.0MHz
+ AKC6955_BAND_FM4, // 76.0~90.0MHz
+ AKC6955_BAND_FM5, // 64.0~88.0MHz
+ AKC6955_BAND_TV1, // 56.25~91.75MHz
+ AKC6955_BAND_TV2, // 174.75~222.25MHz
+ AKC6955_BAND_FMUSER, // User Setting
+ AKC6955_BAND_FMEND
+ };
+/*
+ * Band defines
+ */
+typedef struct {
+ unsigned int start;
+ unsigned int end;
+} banddesc;
+// MCU Clock = 8MHz
+
+#define _AKC6955_WAIT_62_5MS() idle_time_62_5ms()
+// Wait 12.5ms
+#define _AKC6955_WAIT_12_5MS() idle_time_ms(13)
+// Wait 125.0ms
+#define _AKC6955_WAIT_125_0MS() idle_time_ms(125)
+
+
+#ifdef __SDCC
+ // Wait 62.5ms
+//#define _AKC6955_WAIT_62_5MS() delay1ktcy(500)
+// Wait 12.5ms
+//#define _AKC6955_WAIT_12_5MS() delay1ktcy(100)
+// Wait 125.0ms
+//#define _AKC6955_WAIT_125_0MS() delay10ktcy(100)
+// Wait 50us
+#define _AKC6955_WAIT_12_5uS() delay10tcy(40)
+#else
+#ifndef _XTAL_FREQ
+#define _XTAL_FREQ 8000000
+#endif
+
+//#define _AKC6955_WAIT_62_5MS() __delay_ms(63)
+// Wait 12.5ms
+//#define _AKC6955_WAIT_12_5MS() __delay_ms(13)
+// Wait 125.0ms
+//#define _AKC6955_WAIT_125_0MS() idle_time_ms(125)
+//#define _AKC6955_WAIT_125_0MS() {_delay_ms(63); _deyal_ms(62);}
+// Wait 50us
+#define _AKC6955_WAIT_12_5uS() __delay_us(13)
+#endif
+
+extern unsigned char akc6955_readcmd(unsigned char reg);
+extern void akc6955_writecmd(unsigned char reg,unsigned char data);
+extern unsigned char akc6955_getband(void);
+extern unsigned char akc6955_get_amband(void);
+extern unsigned char akc6955_get_fmband(void);
+extern void akc6955_chg_fm(unsigned char fm, unsigned int freq);
+extern unsigned char akc6955_get_fm(void);
+extern unsigned char akc6955_get_band(void);
+
+extern void akc6955_set_amband(unsigned char band);
+extern void akc6955_set_fmband(unsigned char band);
+
+
+extern void akc6955_set_power(unsigned char on);
+extern void akc6955_do_tune(void);
+extern unsigned char akc6955_tune(void);
+extern void akc6955_set_tune(unsigned char mode_3k, unsigned int ch);
+
+extern void akc6955_mode3k(unsigned char flag);
+extern unsigned char akc6955_get_mode3k(void);
+
+extern void akc6955_do_scan(unsigned char up);
+extern void akc6955_abort_scan(void);
+extern unsigned char akc6955_chk_donescan(void);
+
+extern unsigned int akc6955_get_channel(void);
+extern unsigned int akc6955_get_freq(void);
+extern void akc6955_set_freq(unsigned int freq);
+extern unsigned char akc6955_get_cnr(void);
+extern void akc6955_set_userband(unsigned char start, unsigned char stop, unsigned int ch, unsigned char mode3k);
+
+extern int akc6955_read_level(void);
+extern void akc6955_up_freq(unsigned int step);
+extern void akc6955_down_freq(unsigned int step);
+extern int akc6955_get_diff(void);
+
+extern void akc6955_setvolume(unsigned char level);
+extern void akc6955_setvolumemode(unsigned char flag);
+extern unsigned char akc6955_getvolumemode(void);
+extern unsigned char akc6955_getvolume(void);
+extern unsigned char akc6955_get_prevolume(void);
+extern void akc6955_set_prevolume(unsigned char level);
+
+extern void akc6955_setphase(unsigned char flag);
+extern void akc6955_setline(unsigned char flag);
+extern void akc6955_set_stereomode(unsigned char mode);
+extern unsigned char akc6955_get_stereo(void);
+extern void akc6955_set_scanrate_fm(unsigned char rate);
+extern unsigned char akc6955_get_scanrate_fm(void);
+extern unsigned int akc6955_get_battery(void);
+extern void akc6955_set_lowboost(unsigned char flag);
+extern void akc6955_set_thresh_fmstereo(unsigned char a);
+extern void akc6955_set_thresh_fmcnr(unsigned char a);
+extern void akc6955_set_thresh_amcnr(unsigned char a);
+extern void akc6955_set_thresh_width(unsigned char a);
+extern void akc6955_set_fmbandwidth(unsigned char bw);
+extern unsigned char akc6955_get_fmbandwidth(void);
+
+
+
#ifdef __cplusplus