OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [drivers/] [src/] [dis7seg/] [dis7seg.c] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jlechner
#include "dis7seg.h"
2
 
3
#define CMD_SETVALUE 0x40
4
#define CMD_SETDOT 0x80
5
#define CMD_GETVALUE 0xC0
6
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
7
 
8
void dis7seg_initHandle(dis7seg_handle_t *h, scarts_addr_t baseAddress, uint8_t segmentCount) {
9
  h->baseAddress = baseAddress;
10
  h->segmentCount = segmentCount;
11
}
12
 
13
void dis7seg_releaseHandle(dis7seg_handle_t *h) {
14
}
15
 
16
void dis7seg_setPrescaler(dis7seg_handle_t *h, uint16_t value) {
17
  volatile uint16_t *reg = (uint16_t *)(h->baseAddress+DISP7SEG_PRESC_L_BOFF);
18
  *reg = value;
19
}
20
 
21
void dis7seg_setDigitValue(dis7seg_handle_t *h, uint8_t index, uint8_t value) {
22
  volatile uint8_t *reg;
23
  reg = (uint8_t *)(h->baseAddress+DISP7SEG_DISPLAY_CMD);
24
  *reg = CMD_SETVALUE | (index & 0x3F);
25
  reg = (uint8_t *)(h->baseAddress+DISP7SEG_DISPLAY_VALUE);
26
  *reg = value;
27
}
28
 
29
 
30
void dis7seg_displayUInt8(dis7seg_handle_t *h, uint8_t index, uint8_t value) {
31
  int i=0;
32
  for (i=0; i<MIN(3, h->segmentCount); i++) {
33
    dis7seg_setDigitValue(h, index+i, (value % 10));
34
    value /= 10;
35
  }
36
}
37
 
38
void dis7seg_displayUInt16(dis7seg_handle_t *h, uint8_t index, uint16_t value) {
39
  int i=0;
40
  for (i=0; i<MIN(5, h->segmentCount); i++) {
41
    dis7seg_setDigitValue(h, index+i, (value % 10));
42
    value /= 10;
43
  }
44
}
45
 
46
void dis7seg_displayUInt32(dis7seg_handle_t *h, uint8_t index, uint32_t value) {
47
  int i=0;
48
  for (i=0; i<MIN(10, h->segmentCount); i++) {
49
    dis7seg_setDigitValue(h, index+i, (value % 10));
50
    value /= 10;
51
  }
52
}
53
 
54
void dis7seg_displayHexUInt8(dis7seg_handle_t *h, uint8_t index, uint8_t value) {
55
  dis7seg_setDigitValue(h, index, value & 0x0F);
56
  dis7seg_setDigitValue(h, index+1, value >> 4);
57
}
58
 
59
void dis7seg_displayHexUInt16(dis7seg_handle_t *h, uint8_t index, uint16_t value) {
60
  int i=0;
61
  for (i=0; i<4; i++) {
62
    dis7seg_setDigitValue(h, index+i, value >> (i*4) & 0x000F);
63
  }
64
}
65
 
66
void dis7seg_displayHexUInt32(dis7seg_handle_t *h, uint8_t index, uint32_t value) {
67
  int i=0;
68
  for (i=0; i<8; i++) {
69
    dis7seg_setDigitValue(h, index+i, value >> (i*4) & 0x000F);
70
  }
71
}
72
 
73
uint8_t dis7seg_getDigitValue(dis7seg_handle_t *h, uint8_t index) {
74
  volatile uint8_t *reg;
75
  // set display index
76
  reg = (uint8_t *)(h->baseAddress+DISP7SEG_DISPLAY_CMD);
77
  *reg = CMD_GETVALUE | (index & 0x3F);
78
  // get value
79
  reg = (uint8_t *)(h->baseAddress+DISP7SEG_DISPLAY_VALUE);
80
  return *reg;
81
}
82
 
83
void dis7seg_setDigitDot(dis7seg_handle_t *h, uint8_t index, uint8_t enabled) {
84
  // not implemented
85
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.