Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
#include <FastSerial.h>
2
 
3
#undef PROGMEM 
4
#define PROGMEM __attribute__(( section(".progmem.data") )) 
5
 
6
#undef PSTR 
7
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
8
 
9
#include "ArduCam_Max7456.h"
10
#include "WProgram.h"
11
#include "Spi.h"
12
 
13
volatile int x;
14
 
15
OSD::OSD()
16
{
17
}
18
 
19
//------------------ init ---------------------------------------------------
20
 
21
void OSD::init()
22
{
23
  pinMode(MAX7456_SELECT,OUTPUT);
24
  digitalWrite(MAX7456_SELECT,HIGH); //disable device
25
  pinMode(MAX7456_VSYNC, INPUT);
26
  //digitalWrite(MAX7456_VSYNC,HIGH); //enabling pull-up resistor
27
  // force soft reset on Max7456
28
  digitalWrite(MAX7456_SELECT,LOW);
29
  Spi.transfer(MAX7456_VM0_reg);
30
  Spi.transfer(MAX7456_RESET);
31
  digitalWrite(MAX7456_SELECT,HIGH);
32
  delay(50);
33
 
34
  // set all rows to same charactor white level, 90%
35
  digitalWrite(MAX7456_SELECT,LOW);
36
  for (x = 0; x < MAX7456_screen_rows; x++)
37
  {
38
    Spi.transfer(x + 0x10);
39
    Spi.transfer(MAX7456_WHITE_level_120);
40
  }
41
  // define sync (auto,int,ext) and
42
  // making sure the Max7456 is enabled
43
  control(1);
44
  //digitalWrite(MAX7456_SELECT,HIGH);
45
 
46
  //Serial.println("Initialized!");
47
}
48
 
49
//------------------ plug ---------------------------------------------------
50
 
51
void OSD::plug()
52
{
53
  digitalWrite(MAX7456_SELECT,LOW);
54
}
55
 
56
//------------------ clear ---------------------------------------------------
57
 
58
void OSD::clear()
59
{
60
  // clear the screen
61
  digitalWrite(MAX7456_SELECT,LOW);
62
  Spi.transfer(MAX7456_DMM_reg);
63
  Spi.transfer(MAX7456_CLEAR_display);
64
  digitalWrite(MAX7456_SELECT,HIGH);
65
}
66
 
67
//------------------ set panel -----------------------------------------------
68
 
69
void
70
OSD::setPanel(uint8_t st_col, uint8_t st_row){
71
  start_col = st_col;
72
  start_row = st_row;
73
  col = st_col;
74
  row = st_row;
75
  //Serial.printf("setPanel -> %d %d %d %d\n", start_col, start_row, max_col, max_row);
76
}
77
 
78
//------------------ open panel ----------------------------------------------
79
 
80
void
81
OSD::openPanel(void){
82
  unsigned int linepos;
83
  byte settings, char_address_hi, char_address_lo;
84
 
85
  //find [start address] position
86
  linepos = row*30+col;
87
 
88
  // divide 16 bits into hi & lo byte
89
  char_address_hi = linepos >> 8;
90
  char_address_lo = linepos;
91
 
92
  //Auto increment turn writing fast (less SPI commands).
93
  //No need to set next char address. Just send them
94
  settings = MAX7456_INCREMENT_auto; //To Enable DMM Auto Increment
95
  digitalWrite(MAX7456_SELECT,LOW);
96
  Spi.transfer(MAX7456_DMM_reg); //dmm
97
  Spi.transfer(settings);
98
 
99
  Spi.transfer(MAX7456_DMAH_reg); // set start address high
100
  Spi.transfer(char_address_hi);
101
 
102
  Spi.transfer(MAX7456_DMAL_reg); // set start address low
103
  Spi.transfer(char_address_lo);
104
  //Serial.printf("setPos -> %d %d\n", col, row);
105
}
106
 
107
//------------------ close panel ---------------------------------------------
108
 
109
void
110
OSD::closePanel(void){  
111
  Spi.transfer(MAX7456_DMDI_reg);
112
  Spi.transfer(MAX7456_END_string); //This is needed "trick" to finish auto increment
113
  digitalWrite(MAX7456_SELECT,HIGH);
114
  //Serial.println("close");
115
  row++; //only after finish the auto increment the new row will really act as desired
116
}
117
 
118
//------------------ write ---------------------------------------------------
119
 
120
void
121
OSD::write(uint8_t c){
122
  if(c == '|'){
123
    closePanel(); //It does all needed to finish auto increment and change current row
124
    openPanel(); //It does all needed to re-enable auto increment
125
  }
126
  else{
127
    Spi.transfer(MAX7456_DMDI_reg);
128
    Spi.transfer(c);
129
  }
130
}
131
 
132
//------------------
133
 
134
void
135
OSD::control(uint8_t ctrl){
136
  digitalWrite(MAX7456_SELECT,LOW);
137
  Spi.transfer(MAX7456_VM0_reg);
138
  switch(ctrl){
139
    case 0:
140
      Spi.transfer(MAX7456_DISABLE_display);
141
      break;
142
    case 1:
143
      //Spi.transfer(MAX7456_ENABLE_display_vert | MAX7456_SYNC_internal);
144
      //Spi.transfer(MAX7456_ENABLE_display_vert | MAX7456_SYNC_external);
145
      Spi.transfer(MAX7456_ENABLE_display_vert | MAX7456_SYNC_autosync);
146
      break;
147
  }
148
  digitalWrite(MAX7456_SELECT,HIGH);
149
}
150
 
151
//------------------ pure virtual ones (just overriding) ---------------------
152
 
153
int  OSD::available(void){
154
}
155
int  OSD::read(void){
156
}
157
int  OSD::peek(void){
158
}
159
void OSD::flush(void){
160
}